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

@@ -10,12 +10,24 @@ var toShowConfig = {
startTime: 1,
userpass: 1,
vote: 1,
toggleChat: { $ifNull: ["$toggleChat", true] },
strictSkip: { $ifNull: ["$strictSkip", false] },
strictSkipNumber: { $ifNull: ["$strictSkipNumber", 10] },
description: { $ifNull: ["$description", ""] },
thumbnail: { $ifNull: ["$thumbnail", ""] },
rules: { $ifNull: ["$rules", ""] },
toggleChat: {
$ifNull: ["$toggleChat", true]
},
strictSkip: {
$ifNull: ["$strictSkip", false]
},
strictSkipNumber: {
$ifNull: ["$strictSkipNumber", 10]
},
description: {
$ifNull: ["$description", ""]
},
thumbnail: {
$ifNull: ["$thumbnail", ""]
},
rules: {
$ifNull: ["$rules", ""]
},
_id: 0
};
@@ -30,8 +42,12 @@ var project_object = {
duration: 1,
end: 1,
type: 1,
added_by: { $ifNull: ["$added_by", "Anonymous"] },
source: { $ifNull: ["$source", "youtube"] },
added_by: {
$ifNull: ["$added_by", "Anonymous"]
},
source: {
$ifNull: ["$source", "youtube"]
},
thumbnail: {
$ifNull: [
"$thumbnail",
@@ -40,7 +56,9 @@ var project_object = {
}
]
},
tags: { $ifNull: ["$tags", []] }
tags: {
$ifNull: ["$tags", []]
}
};
var toShowChannel = {

View File

@@ -1,12 +1,5 @@
var Functions = require(pathThumbnails + "/handlers/functions.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
/*var filter = {
clean: function(str) {
return str;
}
}*/
var db = require(pathThumbnails + "/handlers/db.js");
function get_history(channel, all, socket) {
@@ -36,7 +29,9 @@ function get_history(channel, all, socket) {
.update(Functions.decrypt_string(pass))
.digest("base64");
}
db.collection(channel + "_settings").find({ id: "config" }, function(
db.collection(channel + "_settings").find({
id: "config"
}, function (
err,
conf
) {
@@ -65,14 +60,21 @@ function getAndSendLogs(channel, all, socket, pass, query) {
icon: 1,
_id: 0
})
.sort({ createdAt: 1 })
.sort({
createdAt: 1
})
.limit(20, function (err, docs) {
socket.emit("chat_history", { all: all, data: docs });
socket.emit("chat_history", {
all: all,
data: docs
});
});
}
function getUserNameByGuid(guid, callback) {
db.collection("user_names").find({ guid: guid }, function(err, usernames) {
db.collection("user_names").find({
guid: guid
}, function (err, usernames) {
if (usernames.length == 1) {
callback(usernames[0].name);
return;
@@ -150,15 +152,15 @@ function chat(msg, guid, offline, socket) {
function () {
if (data == "/who") {
db.collection("user_names").distinct(
"name",
{ channels: coll },
"name", {
channels: coll
},
function (err, docs) {
var userAdd = "s";
if (docs.length == 1) userAdd = "";
socket.emit("chat", {
from: "System",
msg:
": User" +
msg: ": User" +
userAdd +
" in channel are: " +
docs.join(", "),
@@ -173,7 +175,9 @@ function chat(msg, guid, offline, socket) {
data.length < 151 &&
data.replace(/\s/g, "").length
) {
db.collection("user_names").find({ guid: guid }, function(
db.collection("user_names").find({
guid: guid
}, function (
err,
docs
) {
@@ -186,8 +190,9 @@ function chat(msg, guid, offline, socket) {
if (splitData[1].length > 0) {
var passToCompare = Functions.hash_pass(adminpass);
if (passToCompare == conf[0].adminpass) {
db.collection("user_names").find(
{ name: splitData[1] },
db.collection("user_names").find({
name: splitData[1]
},
function (err, name) {
if (name.length == 1) {
if (
@@ -206,30 +211,25 @@ function chat(msg, guid, offline, socket) {
]
);
if (connection_id != yourSelf) {
db.collection(coll + "_banned_chat").update(
{
db.collection(coll + "_banned_chat").update({
connection_id: connection_id
},
{
}, {
connection_id: connection_id,
by: docs[0].name,
reason: reason
},
{
}, {
upsert: true
},
function (err, results) {
io.to(coll).emit("chat", {
from: "System",
msg:
": " +
msg: ": " +
docs[0].name +
" has banned " +
splitData[1] +
" for: " +
reason,
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
@@ -237,16 +237,15 @@ function chat(msg, guid, offline, socket) {
} else {
socket.emit("chat", {
from: "System",
msg:
": I'm sorry but you can't ban yourself..",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
msg: ": I'm sorry but you can't ban yourself..",
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
} else if (data.startsWith("/unban")) {
db.collection(coll + "_banned_chat").remove(
{ connection_id: name[0].connection_id },
db.collection(coll + "_banned_chat").remove({
connection_id: name[0].connection_id
},
function (err, results) {
if (
results.hasOwnProperty("n") &&
@@ -258,22 +257,18 @@ function chat(msg, guid, offline, socket) {
) {
io.to(coll).emit("chat", {
from: "System",
msg:
": " +
msg: ": " +
docs[0].name +
" has unbanned " +
splitData[1],
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
} else {
socket.emit("chat", {
from: "System",
msg:
": Cannot find anyone with that username in this chat.",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
msg: ": Cannot find anyone with that username in this chat.",
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
@@ -285,10 +280,8 @@ function chat(msg, guid, offline, socket) {
) {
socket.emit("chat", {
from: "System",
msg:
": You are doing that command wrong. its /ban USERNAME",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
msg: ": You are doing that command wrong. its /ban USERNAME",
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
@@ -296,8 +289,7 @@ function chat(msg, guid, offline, socket) {
socket.emit("chat", {
from: "System",
msg: ": No user by that name.",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
@@ -306,26 +298,23 @@ function chat(msg, guid, offline, socket) {
} else {
socket.emit("chat", {
from: "System",
msg:
": You are not logged in as an admin to the channel, don't try any funnybusiness.",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
msg: ": You are not logged in as an admin to the channel, don't try any funnybusiness.",
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
} else {
socket.emit("chat", {
from: "System",
msg:
": You are doing that command wrong. its /ban USERNAME REASON or /unban USERNAME",
icon:
"https://zoff.me/assets/images/favicon-32x32.png"
msg: ": You are doing that command wrong. its /ban USERNAME REASON or /unban USERNAME",
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
return;
}
} else {
db.collection("registered_users").find(
{ _id: docs[0].name },
db.collection("registered_users").find({
_id: docs[0].name
},
function (err, n) {
var icon = false;
if (n.length > 0 && n[0].icon) {
@@ -407,17 +396,19 @@ function all_chat(msg, guid, offline, socket) {
data.length < 151 &&
data.replace(/\s/g, "").length
) {
db.collection("user_names").find({ guid: guid }, function(err, docs) {
db.collection("user_names").find({
guid: guid
}, function (err, docs) {
if (docs.length == 1) {
db.collection("registered_users").find(
{ _id: docs[0].name },
db.collection("registered_users").find({
_id: docs[0].name
},
function (err, n) {
var icon = false;
if (n.length > 0 && n[0].icon) {
icon = n[0].icon;
}
db.collection("chat_logs").insert(
{
db.collection("chat_logs").insert({
createdAt: new Date(),
all: true,
channel: coll,
@@ -478,21 +469,31 @@ function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) {
socket.handshake.address +
socket.handshake.headers["accept-language"]
);
db.collection(channel + "_banned_chat").find(
{ $or: [{ connection_id: connection_id }, { connection_id: guid }] },
db.collection(channel + "_banned_chat").find({
$or: [{
connection_id: connection_id
}, {
connection_id: guid
}]
},
function (err, docs) {
if (docs.length == 0) callback();
else {
db.collection("user_names").findAndModify(
{
query: { guid, guid },
update: { $addToSet: { channels: channel } }
db.collection("user_names").findAndModify({
query: {
guid,
guid
},
update: {
$addToSet: {
channels: channel
}
}
},
function (e, d) {
socket.emit("chat", {
from: "System",
msg:
": You can't chat in this channel, you are banned. The reason is: " +
msg: ": You can't chat in this channel, you are banned. The reason is: " +
docs[0].reason,
icon: "https://zoff.me/assets/images/favicon-32x32.png"
});
@@ -561,8 +562,9 @@ function namechange(data, guid, socket, tried, callback) {
return;
}
db.collection("registered_users").find(
{ _id: name.toLowerCase() },
db.collection("registered_users").find({
_id: name.toLowerCase()
},
function (err, docs) {
var accepted_password = false;
var icon = false;
@@ -577,10 +579,15 @@ function namechange(data, guid, socket, tried, callback) {
name.toLowerCase(),
data.password,
function () {
db.collection("registered_users").update(
{ _id: name.toLowerCase() },
{ $set: { password: password } },
{ upsert: true },
db.collection("registered_users").update({
_id: name.toLowerCase()
}, {
$set: {
password: password
}
}, {
upsert: true
},
function () {}
);
}
@@ -596,10 +603,13 @@ function namechange(data, guid, socket, tried, callback) {
name.toLowerCase(),
data.new_password,
function () {
db.collection("registered_users").update(
{ _id: name.toLowerCase(), password: password },
{
$set: { password: Functions.hash_pass(new_password) }
db.collection("registered_users").update({
_id: name.toLowerCase(),
password: password
}, {
$set: {
password: Functions.hash_pass(new_password)
}
},
function () {}
);
@@ -609,9 +619,9 @@ function namechange(data, guid, socket, tried, callback) {
Functions.setSessionChatPass(
Functions.getSession(socket),
name.toLowerCase(),
fetched
? data.password
: Functions.hash_pass(
fetched ?
data.password :
Functions.hash_pass(
Functions.decrypt_string(data.password)
),
function () {}
@@ -619,7 +629,9 @@ function namechange(data, guid, socket, tried, callback) {
}
}
if (accepted_password) {
db.collection("user_names").find({ guid: guid }, function(
db.collection("user_names").find({
guid: guid
}, function (
err,
names
) {
@@ -631,9 +643,13 @@ function namechange(data, guid, socket, tried, callback) {
if (names.length == 0) no_name = true;
if (!no_name) {
var old_name = names[0].name;
db.collection("user_names").update(
{ _id: "all_names" },
{ $pull: { names: old_name } },
db.collection("user_names").update({
_id: "all_names"
}, {
$pull: {
names: old_name
}
},
function () {}
);
}
@@ -650,16 +666,24 @@ function namechange(data, guid, socket, tried, callback) {
}
};
if (data.hasOwnProperty("channel") && data.channel != "") {
updateElement["$addToSet"] = { channels: data.channel };
updateElement["$addToSet"] = {
channels: data.channel
};
}
db.collection("user_names").update(
{ guid: guid },
updateElement,
{ upsert: true },
db.collection("user_names").update({
guid: guid
},
updateElement, {
upsert: true
},
function (err, docs) {
db.collection("user_names").update(
{ _id: "all_names" },
{ $addToSet: { names: name } },
db.collection("user_names").update({
_id: "all_names"
}, {
$addToSet: {
names: name
}
},
function (err, docs) {
//socket.emit('name', {type: "name", accepted: true});
if (old_name != name && !first && !no_name) {
@@ -700,7 +724,10 @@ function namechange(data, guid, socket, tried, callback) {
Functions.removeSessionChatPass(
Functions.getSession(socket),
function () {
socket.emit("name", { type: "name", accepted: false });
socket.emit("name", {
type: "name",
accepted: false
});
}
);
}
@@ -717,17 +744,25 @@ function removename(guid, coll, socket) {
//coll = coll.replace(/ /g,'');
checkIfChatEnabled(coll, socket, function (enabled) {
if (!enabled) return;
db.collection("user_names").find({ guid: guid }, function(err, docs) {
db.collection("user_names").find({
guid: guid
}, function (err, docs) {
if (docs.length == 1) {
var old_name = docs[0].name;
Functions.removeSessionChatPass(
Functions.getSession(socket),
function () {
db.collection("user_names").update(
{ _id: "all_names" },
{ $pull: { names: old_name } },
db.collection("user_names").update({
_id: "all_names"
}, {
$pull: {
names: old_name
}
},
function (err, updated) {
db.collection("user_names").remove({ guid: guid }, function(
db.collection("user_names").remove({
guid: guid
}, function (
err,
removed
) {
@@ -753,15 +788,22 @@ function generate_name(guid, announce_payload, second, round, channel) {
second ? second : guid,
Math.floor(8 + round)
);
db.collection("registered_users").find({ _id: tmp_name }, function(
db.collection("registered_users").find({
_id: tmp_name
}, function (
err,
docs
) {
if (docs.length == 0) {
db.collection("user_names").update(
{ _id: "all_names" },
{ $addToSet: { names: tmp_name } },
{ upsert: true },
db.collection("user_names").update({
_id: "all_names"
}, {
$addToSet: {
names: tmp_name
}
}, {
upsert: true
},
function (err, updated) {
if (
updated.nModified == 1 ||
@@ -782,7 +824,9 @@ function generate_name(guid, announce_payload, second, round, channel) {
}
};
if (channel != undefined && channel != "") {
updateElement["$addToSet"] = { channels: channel };
updateElement["$addToSet"] = {
channels: channel
};
}
if (
announce_payload.hasOwnProperty("channel") &&
@@ -792,10 +836,12 @@ function generate_name(guid, announce_payload, second, round, channel) {
channels: announce_payload.channel
};
}
db.collection("user_names").update(
{ guid: guid },
updateElement,
{ upsert: true },
db.collection("user_names").update({
guid: guid
},
updateElement, {
upsert: true
},
function (err, update) {
name = tmp_name;
if (announce_payload.announce) {
@@ -853,8 +899,9 @@ function get_name(guid, announce_payload, first) {
);
return;
}
db.collection("registered_users").find(
{ _id: name.toLowerCase() },
db.collection("registered_users").find({
_id: name.toLowerCase()
},
function (err, docs) {
if (
docs[0].password ==
@@ -876,7 +923,11 @@ function get_name(guid, announce_payload, first) {
announce_payload.socket.handshake.headers["accept-language"]
);
var updateElement = {
$set: { name: name, icon: icon, connection_id: connection_id }
$set: {
name: name,
icon: icon,
connection_id: connection_id
}
};
if (
announce_payload.hasOwnProperty("channel") &&
@@ -885,14 +936,20 @@ function get_name(guid, announce_payload, first) {
updateElement["$addToSet"] = {
channel: announce_payload.channel
};
db.collection("user_names").update(
{ guid: guid },
updateElement,
{ upsert: true },
db.collection("user_names").update({
guid: guid
},
updateElement, {
upsert: true
},
function (err, docs) {
db.collection("user_names").update(
{ _id: "all_names" },
{ $addToSet: { names: name } },
db.collection("user_names").update({
_id: "all_names"
}, {
$addToSet: {
names: name
}
},
function (err, docs) {
name = name;
}
@@ -910,7 +967,9 @@ function get_name(guid, announce_payload, first) {
}
function get_name_generate(guid, announce_payload, first, channel) {
db.collection("user_names").find({ guid: guid }, function(err, docs) {
db.collection("user_names").find({
guid: guid
}, function (err, docs) {
if (docs.length == 0) {
generate_name(guid, announce_payload, undefined);
} else {

View File

@@ -17,19 +17,25 @@ var connected_db = mongojs(
);
var ObjectId = mongojs.ObjectId;
db.collection("chat_logs").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 600 },
db.collection("chat_logs").createIndex({
createdAt: 1
}, {
expireAfterSeconds: 600
},
function () {}
);
db.collection("timeout_api").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 120 },
db.collection("timeout_api").createIndex({
createdAt: 1
}, {
expireAfterSeconds: 120
},
function () {}
);
db.collection("api_links").createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 86400 },
db.collection("api_links").createIndex({
createdAt: 1
}, {
expireAfterSeconds: 86400
},
function () {}
);
db.on("connected", function (err) {
@@ -45,39 +51,78 @@ db.on("error", function(err) {
});
/* Resetting usernames, and connected users */
db.collection("unique_ids").update(
{ _id: "unique_ids" },
{ $set: { unique_ids: [] } },
{ multi: true, upsert: true },
db.collection("unique_ids").update({
_id: "unique_ids"
}, {
$set: {
unique_ids: []
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);
db.collection("user_names").remove(
{ guid: { $exists: true } },
{ multi: true, upsert: true },
db.collection("user_names").remove({
guid: {
$exists: true
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);
db.collection("user_names").update(
{ _id: "all_names" },
{ $set: { names: [] } },
{ multi: true, upsert: true },
db.collection("user_names").update({
_id: "all_names"
}, {
$set: {
names: []
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);
db.collection("connected_users").update(
{ users: { $exists: true } },
{ $set: { users: [] } },
{ multi: true, upsert: true },
db.collection("connected_users").update({
users: {
$exists: true
}
}, {
$set: {
users: []
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);
db.collection("connected_users").update(
{ _id: "total_users" },
{ $set: { total_users: [] } },
{ multi: true, upsert: true },
db.collection("connected_users").update({
_id: "total_users"
}, {
$set: {
total_users: []
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);
db.collection("frontpage_lists").update(
{ viewers: { $ne: 0 } },
{ $set: { viewers: 0 } },
{ multi: true, upsert: true },
db.collection("frontpage_lists").update({
viewers: {
$ne: 0
}
}, {
$set: {
viewers: 0
}
}, {
multi: true,
upsert: true
},
function (err, docs) {}
);

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,
@@ -129,10 +149,13 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
updateObject.thumbnail = thumbnail;
if (thumbnail == undefined) updateObject.thumbnail = "";
}
db.collection("frontpage_lists").update(
{ _id: coll },
{ $set: updateObject },
{ upsert: true },
db.collection("frontpage_lists").update({
_id: coll
}, {
$set: updateObject
}, {
upsert: true
},
function (err, returnDocs) {
if (typeof callback == "function") callback();
}

View File

@@ -18,7 +18,9 @@ var crypto = require("crypto");
var db = require(pathThumbnails + "/handlers/db.js");
var uniqid = require("uniqid");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
var filter = new Filter({
placeHolder: "x"
});
var Chat = require(pathThumbnails + "/handlers/chat.js");
@@ -42,9 +44,13 @@ function decodeChannelName(str) {
}
function remove_unique_id(short_id) {
db.collection("unique_ids").update(
{ _id: "unique_ids" },
{ $pull: { unique_ids: short_id } },
db.collection("unique_ids").update({
_id: "unique_ids"
}, {
$pull: {
unique_ids: short_id
}
},
function (err, docs) {}
);
}
@@ -53,7 +59,9 @@ function remove_name_from_db(guid, channel) {
// Use temporary, with caution. Can bottleneck in large quantity of users.
//
// Find a way of indexing users in lists in a clever way, to avoid the search here
db.collection("connected_users").find({ _id: "total_users" }, function(
db.collection("connected_users").find({
_id: "total_users"
}, function (
err,
all_users
) {
@@ -61,13 +69,21 @@ function remove_name_from_db(guid, channel) {
return v.indexOf(guid) >= 0;
});
if (!hasOne) {
db.collection("user_names").find({ guid: guid }, function(err, user) {
db.collection("user_names").find({
guid: guid
}, function (err, user) {
if (user.length == 1) {
db.collection("user_names").update(
{ _id: "all_names" },
{ $pull: { names: user[0].name } },
db.collection("user_names").update({
_id: "all_names"
}, {
$pull: {
names: user[0].name
}
},
function (err, updated) {
db.collection("user_names").remove({ guid: guid }, function(
db.collection("user_names").remove({
guid: guid
}, function (
err,
removed
) {});
@@ -77,9 +93,13 @@ function remove_name_from_db(guid, channel) {
});
} else {
if (channel == undefined || channel == "") return;
db.collection("user_names").update(
{ guid: guid },
{ $pull: { channels: channel } },
db.collection("user_names").update({
guid: guid
}, {
$pull: {
channels: channel
}
},
function (err, docs) {
//console.log("Pulled user from current channel");
}
@@ -136,9 +156,14 @@ function remove_from_array(array, element) {
function generate_channel_name(res) {
var trying_id = uniqid.time().toLowerCase();
db.collection("frontpage_lists").find(
{ frontpage: { $exists: true }, _id: trying_id },
{ _id: 1 },
db.collection("frontpage_lists").find({
frontpage: {
$exists: true
},
_id: trying_id
}, {
_id: 1
},
function (err, docs) {
if (docs.length == 0) {
res.send(trying_id);
@@ -163,19 +188,30 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
}
//coll = coll.replace(/ /g,'');
if (!offline && coll != undefined) {
db.collection("connected_users").update(
{ _id: coll },
{ $addToSet: { users: guid } },
{ upsert: true },
db.collection("connected_users").update({
_id: coll
}, {
$addToSet: {
users: guid
}
}, {
upsert: true
},
function (err, updated) {
if (updated.nModified > 0 || updated.upserted != undefined) {
db.collection("connected_users").find({ _id: coll }, function(
db.collection("connected_users").find({
_id: coll
}, function (
err,
new_doc
) {
db.collection("frontpage_lists").update(
{ _id: coll },
{ $set: { viewers: new_doc[0].users.length } },
db.collection("frontpage_lists").update({
_id: coll
}, {
$set: {
viewers: new_doc[0].users.length
}
},
function () {
if (
new_doc[0].users == undefined ||
@@ -185,22 +221,31 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
} else {
io.to(coll).emit("viewers", new_doc[0].users.length);
}
Chat.namechange(
{ initial: true, first: true, channel: coll },
Chat.namechange({
initial: true,
first: true,
channel: coll
},
guid,
socket,
false,
function (enabled) {
db.collection("user_names").find({ guid: guid }, function(
db.collection("user_names").find({
guid: guid
}, function (
err,
docs
) {
if (docs.length == 1) {
var icon = "";
if (docs[0].icon != undefined) icon = docs[0].icon;
db.collection("user_names").update(
{ guid: guid },
{ $addToSet: { channels: coll } },
db.collection("user_names").update({
guid: guid
}, {
$addToSet: {
channels: coll
}
},
function (err, doc) {}
);
if (enabled) {
@@ -222,9 +267,13 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
});
}
});
db.collection("connected_users").update(
{ _id: "total_users" },
{ $addToSet: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$addToSet: {
total_users: guid + coll
}
},
function (err, docs) {
if (
callback != undefined &&
@@ -239,7 +288,9 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
);
});
} else {
db.collection("connected_users").find({ _id: coll }, function(
db.collection("connected_users").find({
_id: coll
}, function (
err,
new_doc
) {
@@ -252,23 +303,35 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
);
} else {
if (offline) {
db.collection("connected_users").update(
{ _id: "offline_users" },
{ $addToSet: { users: guid } },
db.collection("connected_users").update({
_id: "offline_users"
}, {
$addToSet: {
users: guid
}
},
function (err, docs) {}
);
} else {
db.collection("connected_users").update(
{ _id: coll },
{ $addToSet: { users: guid } },
db.collection("connected_users").update({
_id: coll
}, {
$addToSet: {
users: guid
}
},
function (err, docs) {}
);
}
//
if (coll != undefined && coll != "") {
db.collection("connected_users").update(
{ _id: "total_users" },
{ $addToSet: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$addToSet: {
total_users: guid + coll
}
},
function (err, docs) {}
);
}
@@ -372,10 +435,15 @@ function setSessionAdminPass(id, adminpass, list, callback) {
connected_db
.collection(id)
.update(
{ _id: list },
{ $set: { adminpass: hash_pass(decrypt_string(adminpass), true) } },
{ upsert: true },
.update({
_id: list
}, {
$set: {
adminpass: hash_pass(decrypt_string(adminpass), true)
}
}, {
upsert: true
},
function (e, d) {
callback();
return;
@@ -392,10 +460,16 @@ function setSessionChatPass(id, name, pass, callback) {
}
connected_db
.collection(id)
.update(
{ _id: "_chat_" },
{ $set: { password: pass, name: name } },
{ upsert: true },
.update({
_id: "_chat_"
}, {
$set: {
password: pass,
name: name
}
}, {
upsert: true
},
function (e) {
callback();
return;
@@ -414,7 +488,9 @@ function getSessionChatPass(id, callback) {
return;
}
connected_db.collection(id).find({ _id: "_chat_" }, function(e, d) {
connected_db.collection(id).find({
_id: "_chat_"
}, function (e, d) {
if (d.length > 0) {
var name = "";
var pass = "";
@@ -446,10 +522,14 @@ function setChromecastHost(id, other_id, list, callback) {
}
connected_db
.collection(id)
.update(
{ _id: list },
{ chromecast: true, id: other_id },
{ upsert: true },
.update({
_id: list
}, {
chromecast: true,
id: other_id
}, {
upsert: true
},
function (e, docs) {
callback(true);
return;
@@ -469,10 +549,15 @@ function setSessionUserPass(id, userpass, list, callback) {
connected_db
.collection(id)
.update(
{ _id: list },
{ $set: { userpass: userpass } },
{ upsert: true },
.update({
_id: list
}, {
$set: {
userpass: userpass
}
}, {
upsert: true
},
function (e, d) {
callback();
return;
@@ -489,7 +574,9 @@ function getSessionAdminUser(id, list, callback) {
callback("", "", false);
return;
}
connected_db.collection(id).find({ _id: list }, function(e, d) {
connected_db.collection(id).find({
_id: list
}, function (e, d) {
var userpass = "";
var adminpass = "";
if (d.length > 0) {
@@ -514,7 +601,9 @@ function removeSessionChatPass(id, callback) {
callback();
return;
}
connected_db.collection(id).remove({ _id: "_chat_" }, function() {
connected_db.collection(id).remove({
_id: "_chat_"
}, function () {
callback();
return;
});
@@ -527,16 +616,26 @@ function removeSessionAdminPass(id, channel, callback) {
}
connected_db
.collection(id)
.update({ _id: channel }, { $set: { adminpass: "" } }, function() {
.update({
_id: channel
}, {
$set: {
adminpass: ""
}
}, function () {
callback();
return;
});
}
function remove_from_chat_channel(coll, guid) {
db.collection("user_names").update(
{ guid: guid },
{ $pull: { channels: coll } },
db.collection("user_names").update({
guid: guid
}, {
$pull: {
channels: coll
}
},
function (err, docs) {}
);
}
@@ -551,25 +650,44 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
return;
}
//coll = coll.replace(/ /g,'');
db.collection("connected_users").update(
{ _id: coll },
{ $pull: { users: guid } },
db.collection("connected_users").update({
_id: coll
}, {
$pull: {
users: guid
}
},
function (err, updated) {
if (updated.nModified > 0) {
db.collection("connected_users").update(
{ _id: "total_users" },
{ $pull: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$pull: {
total_users: guid + coll
}
},
function (err, updated) {}
);
db.collection("connected_users").find({ _id: coll }, function(
db.collection("connected_users").find({
_id: coll
}, function (
err,
new_doc
) {
db.collection("frontpage_lists").update(
{ _id: coll, viewers: { $gt: 0 } },
{ $inc: { viewers: -1 } },
db.collection("frontpage_lists").update({
_id: coll,
viewers: {
$gt: 0
}
}, {
$inc: {
viewers: -1
}
},
function (err, doc) {
db.collection("user_names").find({ guid: guid }, function(
db.collection("user_names").find({
guid: guid
}, function (
err,
docs
) {
@@ -594,14 +712,22 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
);
});
} else {
db.collection("connected_users").update(
{ _id: "offline_users" },
{ $pull: { users: guid } },
db.collection("connected_users").update({
_id: "offline_users"
}, {
$pull: {
users: guid
}
},
function (err, updated) {
//if(updated.nModified > 0) {
db.collection("connected_users").update(
{ _id: "total_users" },
{ $pull: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$pull: {
total_users: guid + coll
}
},
function (err, updated) {}
);
if (!change) {
@@ -634,8 +760,7 @@ function checkTimeout(
callback();
return;
}
db.collection("timeout_api").find(
{
db.collection("timeout_api").find({
type: type,
guid: guid
},
@@ -663,16 +788,18 @@ function checkTimeout(
}
}
var now_date = new Date();
db.collection("timeout_api").update(
{ type: type, guid: guid },
{
db.collection("timeout_api").update({
type: type,
guid: guid
}, {
$set: {
createdAt: now_date,
type: type,
guid: guid
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {
callback();
return;

View File

@@ -11,7 +11,9 @@ var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
var Search = require(pathThumbnails + "/handlers/search.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
var filter = new Filter({
placeHolder: "x"
});
/*var filter = {
clean: function(str) {
return str;
@@ -51,7 +53,10 @@ module.exports = function() {
var in_list = false;
var name = "";
var short_id;
Chat.get_name(guid, { announce: false, socket: socket });
Chat.get_name(guid, {
announce: false,
socket: socket
});
var offline = false;
var chromecast_object = false;
@@ -67,32 +72,52 @@ module.exports = function() {
}
//channel = channel.replace(/ /g,'');
if (offline) {
db.collection("connected_users").update(
{ _id: "offline_users" },
{ $addToSet: { users: guid } },
{ upsert: true },
db.collection("connected_users").update({
_id: "offline_users"
}, {
$addToSet: {
users: guid
}
}, {
upsert: true
},
function (err, docs) {}
);
} else {
db.collection("connected_users").update(
{ _id: channel },
{ $addToSet: { users: guid } },
{ upsert: true },
db.collection("connected_users").update({
_id: channel
}, {
$addToSet: {
users: guid
}
}, {
upsert: true
},
function (err, docs) {
db.collection("frontpage_lists").update(
{ _id: channel },
{ $inc: { viewers: 1 } },
{ upsert: true },
db.collection("frontpage_lists").update({
_id: channel
}, {
$inc: {
viewers: 1
}
}, {
upsert: true
},
function () {}
);
}
);
}
if (channel != "" && channel != undefined) {
db.collection("connected_users").update(
{ _id: "total_users" },
{ $addToSet: { total_users: guid + channel } },
{ upsert: true },
db.collection("connected_users").update({
_id: "total_users"
}, {
$addToSet: {
total_users: guid + channel
}
}, {
upsert: true
},
function (err, docs) {}
);
}
@@ -143,7 +168,9 @@ module.exports = function() {
if (msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
db.collection("connected_users").find({ _id: msg.channel }, function(
db.collection("connected_users").find({
_id: msg.channel
}, function (
err,
connected_users_channel
) {
@@ -209,15 +236,24 @@ module.exports = function() {
});
socket.on("get_spread", function () {
db.collection("connected_users").find({ _id: "total_users" }, function(
db.collection("connected_users").find({
_id: "total_users"
}, function (
err,
tot
) {
db.collection("connected_users").find(
{ _id: "offline_users" },
db.collection("connected_users").find({
_id: "offline_users"
},
function (err, off) {
db.collection("connected_users").find(
{ _id: { $ne: "total_users" }, _id: { $ne: "offline_users" } },
db.collection("connected_users").find({
_id: {
$ne: "total_users"
},
_id: {
$ne: "offline_users"
}
},
function (err, users_list) {
if (tot.length > 0 && off.length == 0) {
socket.emit("spread_listeners", {
@@ -340,10 +376,15 @@ module.exports = function() {
if (coll !== undefined) {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = filter.clean(coll);
db.collection("connected_users").findAndModify(
{
query: { _id: coll },
update: { $pull: { users: guid } },
db.collection("connected_users").findAndModify({
query: {
_id: coll
},
update: {
$pull: {
users: guid
}
},
upsert: true
},
function (err, updated, d) {
@@ -353,27 +394,47 @@ module.exports = function() {
num = updated.users.length;
}
io.to(coll).emit("viewers", num);
db.collection("frontpage_lists").update(
{ _id: coll, viewers: { $gt: 0 } },
{ $inc: { viewers: -1 } },
db.collection("frontpage_lists").update({
_id: coll,
viewers: {
$gt: 0
}
}, {
$inc: {
viewers: -1
}
},
function (err, docs) {}
);
db.collection("connected_users").update(
{ _id: "total_users" },
{ $pull: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$pull: {
total_users: guid + coll
}
},
function (err, docs) {
db.collection("connected_users").update(
{ _id: "offline_users" },
{ $addToSet: { users: guid } },
{ upsert: true },
db.collection("connected_users").update({
_id: "offline_users"
}, {
$addToSet: {
users: guid
}
}, {
upsert: true
},
function (err, docs) {
if (
docs.nModified == 1 &&
(coll != undefined && coll != "")
) {
db.collection("connected_users").update(
{ _id: "total_users" },
{ $addToSet: { total_users: guid + coll } },
db.collection("connected_users").update({
_id: "total_users"
}, {
$addToSet: {
total_users: guid + coll
}
},
function (err, docs) {}
);
}
@@ -390,9 +451,13 @@ module.exports = function() {
Functions.remove_unique_id(short_id);
} else {
offline = false;
db.collection("connected_users").update(
{ _id: "offline_users" },
{ $pull: { users: guid } },
db.collection("connected_users").update({
_id: "offline_users"
}, {
$pull: {
users: guid
}
},
function (err, docs) {
Functions.check_inlist(
coll,

View File

@@ -4,15 +4,7 @@ var Functions = require(pathThumbnails + "/handlers/functions.js");
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
var projects = require(pathThumbnails + "/handlers/aggregates.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var Search = require(pathThumbnails + "/handlers/search.js");
var filter = new Filter({ placeHolder: "x" });
/*var filter = {
clean: function(str) {
return str;
}
}*/
var request = require("request");
var db = require(pathThumbnails + "/handlers/db.js");
function now_playing(list, fn, socket) {
@@ -20,7 +12,9 @@ function now_playing(list, fn, socket) {
socket.emit("update_required");
return;
}
db.collection(list).find({ now_playing: true }, function(err, docs) {
db.collection(list).find({
now_playing: true
}, function (err, docs) {
if (docs.length === 0) {
fn("No song currently playing");
return;
@@ -52,7 +46,7 @@ function join_silent(msg, socket) {
socket.emit("join_silent_declined", "");
return;
}
if(docs[0].userpass == "" || docs[0].userpass == undefined || docs[0].userpass == password) {
if (docs[0].userpass == "" || docs[0].userpass == undefined || docs[0].userpass == password) {
socket.join(channelName);
socket.emit("join_silent_accepted", "");
@@ -111,7 +105,9 @@ function list(msg, guid, coll, offline, socket) {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = filter.clean(coll);
var pass = msg.pass;
db.collection("frontpage_lists").find({ _id: coll }, function(
db.collection("frontpage_lists").find({
_id: coll
}, function (
err,
frontpage_lists
) {
@@ -136,7 +132,9 @@ function list(msg, guid, coll, offline, socket) {
coll,
function () {}
);
socket.emit("auth_accepted", { value: true });
socket.emit("auth_accepted", {
value: true
});
}
if (docs.length > 0 && docs[0].userpass != pass) {
Functions.setSessionUserPass(
@@ -178,9 +176,11 @@ function list(msg, guid, coll, offline, socket) {
});
} else {
db.createCollection(coll, function (err, docs) {
db.collection(coll).createIndex(
{ id: 1 },
{ unique: true },
db.collection(coll).createIndex({
id: 1
}, {
unique: true
},
function (e, d) {
var configs = {
addsongs: false,
@@ -208,8 +208,7 @@ function list(msg, guid, coll, offline, socket) {
) {
socket.join(coll);
send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert(
{
db.collection("frontpage_lists").insert({
_id: coll,
count: 0,
frontpage: true,
@@ -283,9 +282,8 @@ function skip(list, guid, coll, offline, socket, callback) {
},
userpass: {
expected: "string",
got: list.hasOwnProperty("userpass")
? typeof list.userpass
: undefined
got: list.hasOwnProperty("userpass") ?
typeof list.userpass : undefined
},
id: {
expected: "string",
@@ -370,7 +368,9 @@ function skip(list, guid, coll, offline, socket, callback) {
(docs[0].adminpass == hash && docs[0].adminpass !== "") ||
error
) {
db.collection("frontpage_lists").find({ _id: coll }, function(
db.collection("frontpage_lists").find({
_id: coll
}, function (
err,
frontpage_viewers
) {
@@ -403,12 +403,14 @@ function skip(list, guid, coll, offline, socket, callback) {
function () {
change_song(coll, error, video_id, docs);
socket.emit("toast", "skip");
db.collection("user_names").find(
{ guid: guid },
db.collection("user_names").find({
guid: guid
},
function (err, docs) {
if (docs.length == 1) {
db.collection("registered_users").find(
{ _id: docs[0].name },
db.collection("registered_users").find({
_id: docs[0].name
},
function (err, n) {
var icon = false;
if (n.length > 0 && n[0].icon) {
@@ -428,9 +430,13 @@ function skip(list, guid, coll, offline, socket, callback) {
"The channel is skipping too often, please wait "
);
} else if (!Functions.contains(docs[0].skips, guid)) {
db.collection(coll + "_settings").update(
{ id: "config" },
{ $push: { skips: guid } },
db.collection(coll + "_settings").update({
id: "config"
}, {
$push: {
skips: guid
}
},
function (err, d) {
if (
frontpage_viewers[0].viewers == 2 &&
@@ -450,12 +456,14 @@ function skip(list, guid, coll, offline, socket, callback) {
"toast",
to_skip + " more are needed to skip!"
);
db.collection("user_names").find(
{ guid: guid },
db.collection("user_names").find({
guid: guid
},
function (err, docs) {
if (docs.length == 1) {
db.collection("registered_users").find(
{ _id: docs[0].name },
db.collection("registered_users").find({
_id: docs[0].name
},
function (err, n) {
var icon = false;
if (n.length > 0 && n[0].icon) {
@@ -503,8 +511,7 @@ function change_song(coll, error, id, conf, callback, socket) {
var startTime = conf[0].startTime;
if (conf !== null && conf.length !== 0) {
db.collection(coll).aggregate(
[
{
[{
$match: {
views: {
$exists: false
@@ -535,7 +542,10 @@ function change_song(coll, error, id, conf, callback, socket) {
((id && id == now_playing_doc[0].id) || !id)
) {
if (error) {
db.collection(coll).remove({ now_playing: true, id: id }, function(
db.collection(coll).remove({
now_playing: true,
id: id
}, function (
err,
docs
) {
@@ -551,19 +561,30 @@ function change_song(coll, error, id, conf, callback, socket) {
});
}
if (docs.deletedCount == 1) {
db.collection("frontpage_lists").update(
{ _id: coll, count: { $gt: 0 } },
{
$inc: { count: -1 },
$set: { accessed: Functions.get_time() }
db.collection("frontpage_lists").update({
_id: coll,
count: {
$gt: 0
}
}, {
$inc: {
count: -1
},
$set: {
accessed: Functions.get_time()
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {}
);
}
});
} else if (conf[0].removeplay === true) {
db.collection(coll).remove({ now_playing: true, id: id }, function(
db.collection(coll).remove({
now_playing: true,
id: id
}, function (
err,
docs
) {
@@ -579,13 +600,21 @@ function change_song(coll, error, id, conf, callback, socket) {
});
}
if (docs.deletedCount == 1) {
db.collection("frontpage_lists").update(
{ _id: coll, count: { $gt: 0 } },
{
$inc: { count: -1 },
$set: { accessed: Functions.get_time() }
db.collection("frontpage_lists").update({
_id: coll,
count: {
$gt: 0
}
}, {
$inc: {
count: -1
},
$set: {
accessed: Functions.get_time()
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {}
);
}
@@ -596,16 +625,18 @@ function change_song(coll, error, id, conf, callback, socket) {
conf[0].skipped_time != Functions.get_time()) ||
conf[0].skipped_time == undefined
) {
db.collection(coll).update(
{ now_playing: true, id: id },
{
db.collection(coll).update({
now_playing: true,
id: id
}, {
$set: {
now_playing: false,
votes: 0,
guids: []
}
}, {
multi: true
},
{ multi: true },
function (err, docs) {
var next_song;
if (now_playing_doc.length == 2)
@@ -629,9 +660,13 @@ function change_song(coll, error, id, conf, callback, socket) {
now_playing_doc.length > 1 &&
now_playing_doc[1].id == id
) {
db.collection(coll).update(
{ id: now_playing_doc[0].id },
{ $set: { now_playing: false } },
db.collection(coll).update({
id: now_playing_doc[0].id
}, {
$set: {
now_playing: false
}
},
function (e, d) {
change_song(coll, error, id, conf, callback, socket, error);
}
@@ -649,8 +684,7 @@ function change_song(coll, error, id, conf, callback, socket) {
function change_song_post(coll, next_song, conf, callback, socket, removed) {
//coll = coll.replace(/ /g,'');
db.collection(coll).aggregate(
[
{
[{
$match: {
now_playing: false,
type: {
@@ -679,9 +713,10 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) {
return;
}
}
db.collection(coll).update(
{ id: id, now_playing: false },
{
db.collection(coll).update({
id: id,
now_playing: false
}, {
$set: {
now_playing: true,
votes: 0,
@@ -699,9 +734,9 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) {
callback();
return;
}
db.collection(coll + "_settings").update(
{ id: "config" },
{
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: {
startTime: Functions.get_time(),
skips: []
@@ -756,8 +791,7 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) {
function send_list(coll, socket, send, list_send, configs, shuffled) {
//coll = coll.replace(/ /g,'');
db.collection(coll + "_settings").aggregate(
[
{
[{
$match: {
id: "config"
}
@@ -789,38 +823,50 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
toggleChat: true,
userpass: ""
};
db.collection(coll + "_settings").update(
{ id: "config" },
conf,
{ upsert: true },
db.collection(coll + "_settings").update({
id: "config"
},
conf, {
upsert: true
},
function (err, docs) {
send_list(coll, socket, send, list_send, configs, shuffled);
}
);
} else {
db.collection(coll).aggregate(
[
{
$match: { type: { $ne: "suggested" } }
[{
$match: {
type: {
$ne: "suggested"
}
}
},
{
$project: projects.project_object
},
{ $sort: { now_playing: -1, votes: -1, added: 1 } }
{
$sort: {
now_playing: -1,
votes: -1,
added: 1
}
}
],
function (
err,
docs //db.collection(coll).find({type: {$ne: "suggested"}}, function(err, docs)
) {
if (docs.length > 0) {
db.collection(coll).find({ now_playing: true }, function(
db.collection(coll).find({
now_playing: true
}, function (
err,
np_docs
) {
if (np_docs.length == 0) {
db.collection(coll).aggregate(
[
{
[{
$match: {
views: {
$exists: false
@@ -844,9 +890,10 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
],
function (err, now_playing_doc) {
if (now_playing_doc[0].now_playing == false) {
db.collection(coll).update(
{ id: now_playing_doc[0].id, now_playing: false },
{
db.collection(coll).update({
id: now_playing_doc[0].id,
now_playing: false
}, {
$set: {
now_playing: true,
votes: 0,
@@ -855,9 +902,9 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
}
},
function (err, returnDocs) {
db.collection(coll + "_settings").update(
{ id: "config" },
{
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: {
startTime: Functions.get_time(),
skips: []
@@ -888,8 +935,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
);
} else if (np_docs.length > 1) {
db.collection(coll).aggregate(
[
{
[{
$match: {
now_playing: true
}
@@ -905,10 +951,18 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
],
function (e, docs) {
var real_now_playing = docs[docs.length - 1];
db.collection(coll).update(
{ now_playing: true, id: { $ne: real_now_playing.id } },
{ $set: { now_playing: false } },
{ multi: true },
db.collection(coll).update({
now_playing: true,
id: {
$ne: real_now_playing.id
}
}, {
$set: {
now_playing: false
}
}, {
multi: true
},
function (e, d) {
send_list(
coll,
@@ -1013,10 +1067,12 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
desc: "",
userpass: ""
};
db.collection(coll + "_settings").update(
{ id: "config" },
conf,
{ upsert: true },
db.collection(coll + "_settings").update({
id: "config"
},
conf, {
upsert: true
},
function (err, docs) {
io.to(coll).emit("conf", conf);
}
@@ -1028,8 +1084,12 @@ function send_list(coll, socket, send, list_send, configs, shuffled) {
);
if (socket) {
db.collection(coll)
.find({ type: "suggested" })
.sort({ added: 1 }, function(err, sugg) {
.find({
type: "suggested"
})
.sort({
added: 1
}, function (err, sugg) {
socket.emit("suggested", sugg);
});
}
@@ -1107,7 +1167,9 @@ function end(obj, coll, guid, offline, socket) {
undefined,
"place 13"
);
db.collection(coll).find({ now_playing: true }, function(err, np) {
db.collection(coll).find({
now_playing: true
}, function (err, np) {
if (err !== null) console.log(err);
if (
np !== null &&
@@ -1142,7 +1204,9 @@ function end(obj, coll, guid, offline, socket) {
function send_play(coll, socket, broadcast) {
//coll = coll.replace(/ /g,'');
db.collection(coll).find({ now_playing: true }, function(err, np) {
db.collection(coll).find({
now_playing: true
}, function (err, np) {
db.collection(coll + "_settings").find(function (err, conf) {
if (err !== null) console.log(err);
try {
@@ -1155,7 +1219,11 @@ function send_play(coll, socket, broadcast) {
else conf[0].userpass = false;
if (!np.hasOwnProperty("start")) np.start = 0;
if (!np.hasOwnProperty("end")) np.end = np.duration;
toSend = { np: np, conf: conf, time: Functions.get_time() };
toSend = {
np: np,
conf: conf,
time: Functions.get_time()
};
if (socket === undefined) {
io.to(coll).emit("np", toSend);
//
@@ -1203,14 +1271,22 @@ function sendColor(coll, socket, url, ajax, res) {
.then(function (image) {
var c = ColorThief.getColor(image);
if (ajax) {
res.header({ "Content-Type": "application/json" });
res.header({
"Content-Type": "application/json"
});
res.status(200).send(c);
return;
} else {
if (socket) {
socket.emit("color", { color: c, only: true });
socket.emit("color", {
color: c,
only: true
});
} else {
io.to(coll).emit("color", { color: c, only: false });
io.to(coll).emit("color", {
color: c,
only: false
});
}
}
})
@@ -1218,7 +1294,9 @@ function sendColor(coll, socket, url, ajax, res) {
console.log("Crashed on fetching image, url is " + url);
console.log("Is ajax: " + ajax);
if (ajax) {
res.header({ "Content-Type": "application/json" });
res.header({
"Content-Type": "application/json"
});
res.status(404);
return;
}
@@ -1228,8 +1306,7 @@ function sendColor(coll, socket, url, ajax, res) {
function getNextSong(coll, socket, callback) {
//coll = coll.replace(/ /g,'');
db.collection(coll).aggregate(
[
{
[{
$match: {
views: {
$exists: false

View File

@@ -4,13 +4,6 @@ var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
var Search = require(pathThumbnails + "/handlers/search.js");
var Chat = require(pathThumbnails + "/handlers/chat.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
/*var filter = {
clean: function(str) {
return str;
}
}*/
var db = require(pathThumbnails + "/handlers/db.js");
function addFromOtherList(arr, guid, offline, socket) {
@@ -29,9 +22,8 @@ function addFromOtherList(arr, guid, offline, socket) {
},
new_channel: {
expected: "string",
got: arr.hasOwnProperty("new_channel")
? typeof arr.new_channel
: undefined
got: arr.hasOwnProperty("new_channel") ?
typeof arr.new_channel : undefined
}
};
socket.emit("update_required", result);
@@ -39,7 +31,9 @@ function addFromOtherList(arr, guid, offline, socket) {
}
var channel = arr.channel; //.replace(/ /g,'').toLowerCase();
var new_channel = Functions.encodeChannelName(arr.new_channel); //.replace(/ /g, '').toLowerCase();
db.collection("frontpage_lists").find({ _id: new_channel }, function(
db.collection("frontpage_lists").find({
_id: new_channel
}, function (
err,
fp
) {
@@ -80,17 +74,23 @@ function addFromOtherList(arr, guid, offline, socket) {
.digest("base64");
}
db.collection(channel).find({ now_playing: true }, function(
db.collection(channel).find({
now_playing: true
}, function (
e,
np
) {
var project_object = {
id: 1,
added: 1,
guids: { $literal: [] },
guids: {
$literal: []
},
now_playing: 1,
title: 1,
votes: { $literal: 0 },
votes: {
$literal: 0
},
start: 1,
duration: 1,
end: 1,
@@ -101,11 +101,14 @@ function addFromOtherList(arr, guid, offline, socket) {
};
var to_set_np = true;
if (np.length > 0) {
project_object.now_playing = { $literal: false };
project_object.now_playing = {
$literal: false
};
to_set_np = false;
}
db.collection(new_channel + "_settings").find(
{ id: "config" },
db.collection(new_channel + "_settings").find({
id: "config"
},
function (e, this_conf) {
if (
this_conf.length > 0 &&
@@ -113,8 +116,9 @@ function addFromOtherList(arr, guid, offline, socket) {
!this_conf[0].userpass ||
this_conf[0].userpass == otheruser)
) {
db.collection(channel + "_settings").find(
{ id: "config" },
db.collection(channel + "_settings").find({
id: "config"
},
function (e, this_conf) {
var hash = arr.adminpass;
if (this_conf.length == 0) {
@@ -147,9 +151,10 @@ function addFromOtherList(arr, guid, offline, socket) {
this_conf[0].addsongs === false
) {
db.collection(new_channel).aggregate(
[
{
$match: { type: "video" }
[{
$match: {
type: "video"
}
},
{
$project: project_object
@@ -176,19 +181,21 @@ function addFromOtherList(arr, guid, offline, socket) {
dbo
.collection(channel)
.insertMany(
docs,
{ ordered: false },
docs, {
ordered: false
},
function (err, res) {
db.collection(channel).count(
{
type: { $ne: "suggested" }
db.collection(channel).count({
type: {
$ne: "suggested"
}
},
function (err, count) {
db.collection(
channel + "_settings"
).update(
{ id: "config" },
{
).update({
id: "config"
}, {
$set: {
startTime: Functions.get_time()
}
@@ -203,8 +210,7 @@ function addFromOtherList(arr, guid, offline, socket) {
};
db.collection(
new_channel
).find(
{
).find({
now_playing: true
},
function (
@@ -217,8 +223,7 @@ function addFromOtherList(arr, guid, offline, socket) {
np_docs[0].title;
db.collection(
"frontpage_lists"
).find(
{
).find({
_id: new_channel
},
function (
@@ -254,11 +259,9 @@ function addFromOtherList(arr, guid, offline, socket) {
db.collection(
"frontpage_lists"
).update(
{
).update({
_id: channel
},
{
}, {
$set: to_change
},
function (
@@ -290,9 +293,9 @@ function addFromOtherList(arr, guid, offline, socket) {
} else {
db.collection(
"frontpage_lists"
).update(
{ _id: channel },
{
).update({
_id: channel
}, {
$set: {
count: count
}
@@ -382,7 +385,9 @@ function addPlaylist(arr, guid, offline, socket) {
socket.emit("toast", "Empty list..");
return;
}
db.collection("frontpage_lists").find({ _id: channel }, function(err, fp) {
db.collection("frontpage_lists").find({
_id: channel
}, function (err, fp) {
if (fp.length == 0) {
socket.emit("toast", "nolist");
return;
@@ -407,11 +412,14 @@ function addPlaylist(arr, guid, offline, socket) {
Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true)
);
}
db.collection(channel).find({ now_playing: true }, function(e, np) {
db.collection(channel).find({
now_playing: true
}, function (e, np) {
var now_playing = false;
if (np.length == 0) now_playing = true;
db.collection(channel + "_settings").find(
{ id: "config" },
db.collection(channel + "_settings").find({
id: "config"
},
function (e, conf) {
if (arr.length == 0 || arr.songs.length == 0) {
socket.emit("toast", "Empty list..");
@@ -525,12 +533,15 @@ function addPlaylist(arr, guid, offline, socket) {
bulk.insert(this_element);
}
bulk.execute(function (err, results) {
db.collection(channel).count(
{ type: { $ne: "suggested" } },
db.collection(channel).count({
type: {
$ne: "suggested"
}
},
function (err, count) {
db.collection(channel + "_settings").update(
{ id: "config" },
{
db.collection(channel + "_settings").update({
id: "config"
}, {
$set: {
startTime: Functions.get_time()
}
@@ -543,15 +554,18 @@ function addPlaylist(arr, guid, offline, socket) {
frontpage: true,
accessed: Functions.get_time()
};
db.collection(channel).find(
{ now_playing: true },
db.collection(channel).find({
now_playing: true
},
function (e, np_docs) {
to_change.id = np_docs[0].id;
to_change.title =
np_docs[0].title;
db.collection(
"frontpage_lists"
).find({ _id: channel }, function(
).find({
_id: channel
}, function (
e,
doc
) {
@@ -576,9 +590,11 @@ function addPlaylist(arr, guid, offline, socket) {
db.collection(
"frontpage_lists"
).update(
{ _id: channel },
{ $set: to_change },
).update({
_id: channel
}, {
$set: to_change
},
function (e, d) {
List.send_list(
channel,
@@ -604,9 +620,13 @@ function addPlaylist(arr, guid, offline, socket) {
} else {
db.collection(
"frontpage_lists"
).update(
{ _id: channel },
{ $set: { count: count } },
).update({
_id: channel
}, {
$set: {
count: count
}
},
function (e, d) {
List.send_list(
channel,
@@ -753,9 +773,8 @@ function add_function(arr, coll, guid, offline, socket) {
},
adminpass: {
expected: "string",
got: arr.hasOwnProperty("adminpass")
? typeof arr.adminpass
: undefined
got: arr.hasOwnProperty("adminpass") ?
typeof arr.adminpass : undefined
},
source: {
expected: "string (youtube or soundcloud)",
@@ -763,9 +782,8 @@ function add_function(arr, coll, guid, offline, socket) {
},
thumbnail: {
expected: "url if source == soundcloud",
got: arr.hasOwnProperty("thumbnail")
? typeof arr.thumbnail
: undefined
got: arr.hasOwnProperty("thumbnail") ?
typeof arr.thumbnail : undefined
}
};
socket.emit("update_required", result);
@@ -828,14 +846,20 @@ function add_function(arr, coll, guid, offline, socket) {
(hash == docs[0].adminpass || docs[0].adminpass === "")) ||
docs[0].addsongs === false)
) {
db.collection(coll).find(
{ id: id, type: { $ne: "suggested" } },
db.collection(coll).find({
id: id,
type: {
$ne: "suggested"
}
},
function (err, docs) {
if (docs !== null && docs.length === 0) {
var guids = [guid];
var added = Functions.get_time();
var votes = 1;
db.collection(coll).find({ now_playing: true }, function(
db.collection(coll).find({
now_playing: true
}, function (
err,
docs
) {
@@ -874,23 +898,28 @@ function add_function(arr, coll, guid, offline, socket) {
"https://img.youtube.com/vi/" +
new_song.id +
"/mqdefault.jpg";
db.collection(coll).update(
{ id: id },
new_song,
{ upsert: true },
db.collection(coll).update({
id: id
},
new_song, {
upsert: true
},
function (err, docs) {
new_song._id = "asd";
if (np) {
List.send_list(coll, undefined, false, true, false);
db.collection(coll + "_settings").update(
{ id: "config" },
{ $set: { startTime: Functions.get_time() } }
);
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: {
startTime: Functions.get_time()
}
});
List.send_play(coll, undefined);
var thumbnail =
arr.thumbnail != undefined
? arr.thumbnail
: undefined;
arr.thumbnail != undefined ?
arr.thumbnail :
undefined;
Frontpage.update_frontpage(
coll,
id,
@@ -912,13 +941,18 @@ function add_function(arr, coll, guid, offline, socket) {
else if (source == "soundcloud")
Search.get_genres_soundcloud(new_song, coll);
}
db.collection("frontpage_lists").update(
{ _id: coll },
{
$inc: { count: 1 },
$set: { accessed: Functions.get_time() }
db.collection("frontpage_lists").update({
_id: coll
}, {
$inc: {
count: 1
},
$set: {
accessed: Functions.get_time()
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {}
);
List.getNextSong(coll, undefined);
@@ -932,7 +966,9 @@ function add_function(arr, coll, guid, offline, socket) {
}
);
} else {
db.collection(coll).find({ id: id }, function(err, docs) {
db.collection(coll).find({
id: id
}, function (err, docs) {
if (docs.length === 0) {
var suggestedAdd = {
added: Functions.get_time(),
@@ -955,10 +991,13 @@ function add_function(arr, coll, guid, offline, socket) {
} else {
suggestedAdd.source = "youtube";
}
db.collection(coll).update(
{ id: id },
{ $set: suggestedAdd },
{ upsert: true },
db.collection(coll).update({
id: id
}, {
$set: suggestedAdd
}, {
upsert: true
},
function (err, docs) {
socket.emit("toast", "suggested");
var toSend = suggestedAdd;
@@ -1035,9 +1074,8 @@ function voteUndecided(msg, coll, guid, offline, socket) {
},
adminpass: {
expected: "adminpass",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
got: msg.hasOwnProperty("adminpass") ?
typeof msg.adminpass : undefined
},
pass: {
expected: "string",
@@ -1070,7 +1108,9 @@ function voteUndecided(msg, coll, guid, offline, socket) {
.digest("base64");
}
db.collection(coll + "_settings").find({ id: "config" }, function(
db.collection(coll + "_settings").find({
id: "config"
}, function (
err,
docs
) {
@@ -1198,7 +1238,9 @@ function shuffle(msg, coll, guid, offline, socket) {
docs[0].shuffle === false)
) {
db.collection(coll)
.find({ now_playing: false })
.find({
now_playing: false
})
.forEach(function (err, docs) {
if (!docs) {
List.send_list(coll, undefined, false, true, false, true);
@@ -1207,10 +1249,13 @@ function shuffle(msg, coll, guid, offline, socket) {
return;
} else {
num = Math.floor(Math.random() * 1000000);
db.collection(coll).update(
{ id: docs.id },
{ $set: { added: num } }
);
db.collection(coll).update({
id: docs.id
}, {
$set: {
added: num
}
});
}
});
} else socket.emit("toast", "wrongpass");
@@ -1242,26 +1287,38 @@ function del(params, socket, socketid) {
docs.length !== 0 &&
docs[0].adminpass == params.adminpass
) {
db.collection(coll).find({ id: params.id }, function(err, docs) {
db.collection(coll).find({
id: params.id
}, function (err, docs) {
var dont_increment = false;
if (docs[0]) {
if (docs[0].type == "suggested") {
dont_increment = true;
}
db.collection(coll).remove({ id: params.id }, function(err, docs) {
db.collection(coll).remove({
id: params.id
}, function (err, docs) {
socket.emit("toast", "deletesong");
io.to(coll).emit("channel", {
type: "deleted",
value: params.id
});
if (!dont_increment)
db.collection("frontpage_lists").update(
{ _id: coll, count: { $gt: 0 } },
{
$inc: { count: -1 },
$set: { accessed: Functions.get_time() }
db.collection("frontpage_lists").update({
_id: coll,
count: {
$gt: 0
}
}, {
$inc: {
count: -1
},
$set: {
accessed: Functions.get_time()
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {}
);
});
@@ -1283,9 +1340,8 @@ function delete_all(msg, coll, guid, offline, socket) {
},
adminpass: {
expected: "adminpass",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
got: msg.hasOwnProperty("adminpass") ?
typeof msg.adminpass : undefined
},
pass: {
expected: "string",
@@ -1335,15 +1391,26 @@ function delete_all(msg, coll, guid, offline, socket) {
conf.userpass != undefined &&
conf.pass == hash_userpass))
) {
db.collection(coll).remove(
{ views: { $exists: false }, type: "video" },
{ multi: true },
db.collection(coll).remove({
views: {
$exists: false
},
type: "video"
}, {
multi: true
},
function (err, succ) {
List.send_list(coll, false, true, true, true);
db.collection("frontpage_lists").update(
{ _id: coll },
{ $set: { count: 0, accessed: Functions.get_time() } },
{ upsert: true },
db.collection("frontpage_lists").update({
_id: coll
}, {
$set: {
count: 0,
accessed: Functions.get_time()
}
}, {
upsert: true
},
function (err, docs) {}
);
socket.emit("toast", "deleted_songs");
@@ -1369,20 +1436,29 @@ function delete_all(msg, coll, guid, offline, socket) {
function vote(coll, id, guid, socket) {
//coll = coll.replace(/ /g,'');
db.collection(coll).find(
{ id: id, now_playing: false, type: "video" },
db.collection(coll).find({
id: id,
now_playing: false,
type: "video"
},
function (err, docs) {
if (
docs !== null &&
docs.length > 0 &&
!Functions.contains(docs[0].guids, guid)
) {
db.collection(coll).update(
{ id: id },
{
$inc: { votes: 1 },
$set: { added: Functions.get_time() },
$push: { guids: guid }
db.collection(coll).update({
id: id
}, {
$inc: {
votes: 1
},
$set: {
added: Functions.get_time()
},
$push: {
guids: guid
}
},
function (err, docs) {
socket.emit("toast", "voted");

View File

@@ -1,12 +1,5 @@
var Functions = require(pathThumbnails + "/handlers/functions.js");
var crypto = require("crypto");
var Filter = require("bad-words");
var filter = new Filter({ placeHolder: "x" });
/*var filter = {
clean: function(str) {
return str;
}
}*/
var projects = require(pathThumbnails + "/handlers/aggregates.js");
var db = require(pathThumbnails + "/handlers/db.js");
@@ -64,9 +57,13 @@ function password(inp, coll, guid, offline, socket) {
inp.password,
coll,
function () {
db.collection(coll + "_settings").update(
{ id: "config" },
{ $set: { adminpass: Functions.hash_pass(pw) } },
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: {
adminpass: Functions.hash_pass(pw)
}
},
function (err, docs) {
if (adminpass != pw && adminpass != "") {
socket.emit("toast", "changedpass");
@@ -87,9 +84,13 @@ function password(inp, coll, guid, offline, socket) {
inp.password,
coll,
function () {
db.collection(coll + "_settings").update(
{ id: "config" },
{ $set: { adminpass: Functions.hash_pass(pw) } },
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: {
adminpass: Functions.hash_pass(pw)
}
},
function (err, docs) {
if (adminpass != pw) {
socket.emit("toast", "changedpass");
@@ -181,15 +182,13 @@ function conf_function(params, coll, guid, offline, socket) {
var result = {
adminpass: {
expected: "string",
got: params.hasOwnProperty("adminpass")
? typeof params.adminpass
: undefined
got: params.hasOwnProperty("adminpass") ?
typeof params.adminpass : undefined
},
userpass: {
expected: "string",
got: params.hasOwnProperty("userpass")
? typeof params.userpass
: undefined
got: params.hasOwnProperty("userpass") ?
typeof params.userpass : undefined
},
vote: {
expected: "boolean",
@@ -197,39 +196,33 @@ function conf_function(params, coll, guid, offline, socket) {
},
addsongs: {
expected: "boolean",
got: params.hasOwnProperty("addsongs")
? typeof params.addsongs
: undefined
got: params.hasOwnProperty("addsongs") ?
typeof params.addsongs : undefined
},
longsongs: {
expected: "boolean",
got: params.hasOwnProperty("longsongs")
? typeof params.longsongs
: undefined
got: params.hasOwnProperty("longsongs") ?
typeof params.longsongs : undefined
},
frontpage: {
expected: "boolean",
got: params.hasOwnProperty("frontpage")
? typeof params.frontpage
: undefined
got: params.hasOwnProperty("frontpage") ?
typeof params.frontpage : undefined
},
skipping: {
expected: "boolean",
got: params.hasOwnProperty("skipping")
? typeof params.skipping
: undefined
got: params.hasOwnProperty("skipping") ?
typeof params.skipping : undefined
},
shuffling: {
expected: "boolean",
got: params.hasOwnProperty("shuffling")
? typeof params.shuffling
: undefined
got: params.hasOwnProperty("shuffling") ?
typeof params.shuffling : undefined
},
userpass_changed: {
expected: "boolean",
got: params.hasOwnProperty("userpass_changed")
? typeof params.userpass_changed
: undefined
got: params.hasOwnProperty("userpass_changed") ?
typeof params.userpass_changed : undefined
}
};
socket.emit("update_required", result);
@@ -266,15 +259,16 @@ function conf_function(params, coll, guid, offline, socket) {
hash = adminpass;
}
if (userpass != "") {
if (!params.userpass_changed && gotten) {
} else {
if (!params.userpass_changed && gotten) {} else {
userpass = crypto
.createHash("sha256")
.update(userpass)
.digest("base64");
}
}
db.collection(coll + "_settings").find({ id: "config" }, function(
db.collection(coll + "_settings").find({
id: "config"
}, function (
err,
docs
) {
@@ -326,9 +320,9 @@ function conf_function(params, coll, guid, offline, socket) {
} else if (frontpage) {
obj["userpass"] = "";
}
db.collection(coll + "_settings").update(
{ id: "config" },
{
db.collection(coll + "_settings").update({
id: "config"
}, {
$set: obj
},
function (err, docs) {
@@ -338,8 +332,7 @@ function conf_function(params, coll, guid, offline, socket) {
coll,
function () {
db.collection(coll + "_settings").aggregate(
[
{
[{
$match: {
id: "config"
}
@@ -359,15 +352,16 @@ function conf_function(params, coll, guid, offline, socket) {
io.to(coll).emit("conf", docs);
socket.emit("toast", "savedsettings");
db.collection("frontpage_lists").update(
{ _id: coll },
{
db.collection("frontpage_lists").update({
_id: coll
}, {
$set: {
frontpage: frontpage,
accessed: Functions.get_time()
}
}, {
upsert: true
},
{ upsert: true },
function (err, docs) {}
);
}

View File

@@ -19,7 +19,10 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
callback(false);
return;
}
db.collection(channel).find({ id: id, now_playing: true }, function(
db.collection(channel).find({
id: id,
now_playing: true
}, function (
err,
song
) {
@@ -29,11 +32,9 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
}
var song_info = song[0];
if (song_info.source != "soundcloud") {
request(
{
request({
type: "GET",
url:
"https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key=" +
url: "https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key=" +
key +
"&id=" +
song_info.id
@@ -81,11 +82,9 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
}
);
} else {
request(
{
request({
type: "GET",
url:
"http://api.soundcloud.com/tracks/" +
url: "http://api.soundcloud.com/tracks/" +
song_info.id +
"?client_id=" +
soundcloudKey
@@ -138,9 +137,9 @@ function get_genres_soundcloud(song, channel) {
.concat(object.tag_list.toLowerCase().split('"'));
genre = genre.filter(filterFunction);
db.collection(channel).update(
{ id: song.id },
{
db.collection(channel).update({
id: song.id
}, {
$set: {
tags: genre
}
@@ -228,9 +227,9 @@ function get_genres_soundcloud_recursive(arr, channel, i, callback) {
.concat(object.tag_list.toLowerCase().split('"'));
genre = genre.filter(filterFunction);
db.collection(channel).update(
{ id: song.id },
{
db.collection(channel).update({
id: song.id
}, {
$set: {
tags: genre
}
@@ -281,11 +280,9 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
}
ids.push(arr[y].id);
}
request(
{
request({
type: "GET",
url:
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
key +
"&id=" +
ids.join(",")
@@ -315,9 +312,9 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
.split(",");
genre = genre.filter(filterFunction);
//console.log(resp.items[i].id + " - ", genre);
db.collection(channel).update(
{ id: resp.items[z].id },
{
db.collection(channel).update({
id: resp.items[z].id
}, {
$set: {
tags: genre
}
@@ -334,11 +331,9 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
}
function get_genres_youtube(ids, channel) {
request(
{
request({
type: "GET",
url:
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
key +
"&id=" +
ids
@@ -366,9 +361,9 @@ function get_genres_youtube(ids, channel) {
.split(",");
genre = genre.filter(filterFunction);
//console.log(resp.items[i].id + " - ", genre);
db.collection(channel).update(
{ id: resp.items[i].id },
{
db.collection(channel).update({
id: resp.items[i].id
}, {
$set: {
tags: genre
}
@@ -383,11 +378,9 @@ function get_genres_youtube(ids, channel) {
function get_correct_info(song_generated, channel, broadcast, callback) {
//channel = channel.replace(/ /g,'');
request(
{
request({
type: "GET",
url:
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
key +
"&id=" +
song_generated.id
@@ -424,9 +417,9 @@ function get_correct_info(song_generated, channel, broadcast, callback) {
song_generated.start = 0;
song_generated.end = duration;
}
db.collection(channel).update(
{ id: song_generated.id },
{
db.collection(channel).update({
id: song_generated.id
}, {
$set: {
duration: song_generated.duration,
start: song_generated.start,
@@ -455,9 +448,9 @@ function get_correct_info(song_generated, channel, broadcast, callback) {
}
);
} else {
db.collection(channel).update(
{ id: song_generated.id },
{
db.collection(channel).update({
id: song_generated.id
}, {
$set: {
tags: genre
}
@@ -502,11 +495,9 @@ function check_error_video(msg, channel) {
}
if (msg.source == "soundcloud") return;
//channel = channel.replace(/ /g,'');
request(
{
request({
type: "GET",
url:
"https://www.googleapis.com/youtube/v3/videos?part=id&key=" +
url: "https://www.googleapis.com/youtube/v3/videos?part=id&key=" +
key +
"&id=" +
msg.id
@@ -531,8 +522,7 @@ function findSimilar(msg, channel, broadcast, callback) {
key +
"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" +
encodeURIComponent(msg.title);
request(
{
request({
method: "GET",
url: yt_url
},
@@ -546,8 +536,7 @@ function findSimilar(msg, channel, broadcast, callback) {
for (var i = 0; i < resp.items.length; i++) {
vid_url += resp.items[i].id.videoId + ",";
}
request(
{
request({
type: "GET",
url: vid_url
},
@@ -576,9 +565,9 @@ function findSimilar(msg, channel, broadcast, callback) {
}
}
if (found) {
db.collection(channel).update(
{ id: msg.id },
{
db.collection(channel).update({
id: msg.id
}, {
$set: element
},
function (err, docs) {

View File

@@ -22,15 +22,15 @@ function thumbnail(msg, coll, guid, offline, socket) {
},
thumbnail: {
expected: "string",
got: msg.hasOwnProperty("thumbnail")
? typeof msg.thumbnail
: undefined
got: msg.hasOwnProperty("thumbnail") ?
typeof msg.thumbnail :
undefined
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
got: msg.hasOwnProperty("adminpass") ?
typeof msg.adminpass :
undefined
}
};
socket.emit("update_required", result);
@@ -63,7 +63,9 @@ function thumbnail(msg, coll, guid, offline, socket) {
}
var channel = msg.channel.toLowerCase();
var hash = msg.adminpass;
db.collection(channel + "_settings").find({ id: "config" }, function(
db.collection(channel + "_settings").find({
id: "config"
}, function (
err,
docs
) {
@@ -79,10 +81,15 @@ function thumbnail(msg, coll, guid, offline, socket) {
docs[0].adminpass !== "" &&
docs[0].adminpass == hash
) {
db.collection("suggested_thumbnails").update(
{ channel: channel },
{ $set: { thumbnail: msg.thumbnail } },
{ upsert: true },
db.collection("suggested_thumbnails").update({
channel: channel
}, {
$set: {
thumbnail: msg.thumbnail
}
}, {
upsert: true
},
function (err, docs) {
Notifications.requested_change(
"thumbnail",
@@ -117,15 +124,15 @@ function description(msg, coll, guid, offline, socket) {
},
description: {
expected: "string",
got: msg.hasOwnProperty("description")
? typeof msg.description
: undefined
got: msg.hasOwnProperty("description") ?
typeof msg.description :
undefined
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
got: msg.hasOwnProperty("adminpass") ?
typeof msg.adminpass :
undefined
}
};
socket.emit("update_required", result);
@@ -154,7 +161,9 @@ function description(msg, coll, guid, offline, socket) {
}
var channel = msg.channel.toLowerCase();
var hash = msg.adminpass;
db.collection(channel + "_settings").find({ id: "config" }, function(
db.collection(channel + "_settings").find({
id: "config"
}, function (
err,
docs
) {
@@ -170,10 +179,15 @@ function description(msg, coll, guid, offline, socket) {
docs[0].adminpass !== "" &&
docs[0].adminpass == hash
) {
db.collection("suggested_descriptions").update(
{ channel: channel },
{ $set: { description: msg.description } },
{ upsert: true },
db.collection("suggested_descriptions").update({
channel: channel
}, {
$set: {
description: msg.description
}
}, {
upsert: true
},
function (err, docs) {
Notifications.requested_change(
"description",
@@ -212,9 +226,9 @@ function rules(msg, coll, guid, offline, socket) {
},
adminpass: {
expected: "string",
got: msg.hasOwnProperty("adminpass")
? typeof msg.adminpass
: undefined
got: msg.hasOwnProperty("adminpass") ?
typeof msg.adminpass :
undefined
}
};
socket.emit("update_required", result);
@@ -243,7 +257,9 @@ function rules(msg, coll, guid, offline, socket) {
}
var channel = msg.channel.toLowerCase();
var hash = msg.adminpass;
db.collection(channel + "_settings").find({ id: "config" }, function(
db.collection(channel + "_settings").find({
id: "config"
}, function (
err,
docs
) {
@@ -259,10 +275,15 @@ function rules(msg, coll, guid, offline, socket) {
docs[0].adminpass !== "" &&
docs[0].adminpass == hash
) {
db.collection("suggested_rules").update(
{ channel: channel },
{ $set: { rules: msg.rules } },
{ upsert: true },
db.collection("suggested_rules").update({
channel: channel
}, {
$set: {
rules: msg.rules
}
}, {
upsert: true
},
function (err, docs) {
Notifications.requested_change("rules", msg.rules, channel);
socket.emit("toast", "suggested_rules");