Add linting and unused cleanup

This commit is contained in:
Alf Hammerseth
2019-11-16 15:16:34 +01:00
parent ce7ac96a5d
commit 120553eac4
12 changed files with 1560 additions and 1066 deletions

View File

@@ -1,5 +1,6 @@
var Functions = require(pathThumbnails + "/handlers/functions.js");
var db = require(pathThumbnails + "/handlers/db.js");
function frontpage_lists(msg, socket) {
if (
msg == undefined ||
@@ -17,11 +18,15 @@ function frontpage_lists(msg, socket) {
return;
}
db.collection("frontpage_lists").find({ frontpage: true }, function(
db.collection("frontpage_lists").find({
frontpage: true
}, function (
err,
docs
) {
db.collection("connected_users").find({ _id: "total_users" }, function(
db.collection("connected_users").find({
_id: "total_users"
}, function (
err,
tot
) {
@@ -44,16 +49,22 @@ function get_frontpage_lists(callback) {
title: 1,
viewers: 1,
accessed: 1,
pinned: { $ifNull: ["$pinned", 0] },
pinned: {
$ifNull: ["$pinned", 0]
},
description: {
$ifNull: [
{
$ifNull: [{
$cond: {
if: {
$or: [
{ $eq: ["$description", ""] },
{ $eq: ["$description", null] },
{ $eq: ["$description", undefined] }
$or: [{
$eq: ["$description", ""]
},
{
$eq: ["$description", null]
},
{
$eq: ["$description", undefined]
}
]
},
then: "This list has no description",
@@ -64,14 +75,18 @@ function get_frontpage_lists(callback) {
]
},
thumbnail: {
$ifNull: [
{
$ifNull: [{
$cond: {
if: {
$or: [
{ $eq: ["$thumbnail", ""] },
{ $eq: ["$thumbnail", null] },
{ $eq: ["$thumbnail", undefined] }
$or: [{
$eq: ["$thumbnail", ""]
},
{
$eq: ["$thumbnail", null]
},
{
$eq: ["$thumbnail", undefined]
}
]
},
then: {
@@ -80,16 +95,19 @@ function get_frontpage_lists(callback) {
else: "$thumbnail"
}
},
{ $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] }
{
$concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
}
]
}
};
db.collection("frontpage_lists").aggregate(
[
{
[{
$match: {
frontpage: true,
count: { $gt: 3 }
count: {
$gt: 3
}
}
},
{
@@ -111,7 +129,9 @@ function get_frontpage_lists(callback) {
function update_frontpage(coll, id, title, thumbnail, source, callback) {
//coll = coll.replace(/ /g,'');
db.collection("frontpage_lists").find({ _id: coll }, function(e, doc) {
db.collection("frontpage_lists").find({
_id: coll
}, function (e, doc) {
var updateObject = {
id: id,
title: title,
@@ -120,20 +140,23 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
if (
doc.length > 0 &&
((doc[0].thumbnail != "" &&
doc[0].thumbnail != undefined &&
(doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) ||
doc[0].thumbnail != undefined &&
(doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 ||
doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) ||
(doc[0].thumbnail == "" || doc[0].thumbnail == undefined))
) {
updateObject.thumbnail = thumbnail;
if (thumbnail == undefined) updateObject.thumbnail = "";
}
db.collection("frontpage_lists").update(
{ _id: coll },
{ $set: updateObject },
{ upsert: true },
function(err, returnDocs) {
db.collection("frontpage_lists").update({
_id: coll
}, {
$set: updateObject
}, {
upsert: true
},
function (err, returnDocs) {
if (typeof callback == "function") callback();
}
);
@@ -142,4 +165,4 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
module.exports.get_frontpage_lists = get_frontpage_lists;
module.exports.frontpage_lists = frontpage_lists;
module.exports.update_frontpage = update_frontpage;
module.exports.update_frontpage = update_frontpage;