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

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
var Functions = require(pathThumbnails + "/handlers/functions.js"); var Functions = require(pathThumbnails + "/handlers/functions.js");
var db = require(pathThumbnails + "/handlers/db.js"); var db = require(pathThumbnails + "/handlers/db.js");
function frontpage_lists(msg, socket) { function frontpage_lists(msg, socket) {
if ( if (
msg == undefined || msg == undefined ||
@@ -17,11 +18,15 @@ function frontpage_lists(msg, socket) {
return; return;
} }
db.collection("frontpage_lists").find({ frontpage: true }, function( db.collection("frontpage_lists").find({
frontpage: true
}, function (
err, err,
docs docs
) { ) {
db.collection("connected_users").find({ _id: "total_users" }, function( db.collection("connected_users").find({
_id: "total_users"
}, function (
err, err,
tot tot
) { ) {
@@ -44,16 +49,22 @@ function get_frontpage_lists(callback) {
title: 1, title: 1,
viewers: 1, viewers: 1,
accessed: 1, accessed: 1,
pinned: { $ifNull: ["$pinned", 0] }, pinned: {
$ifNull: ["$pinned", 0]
},
description: { description: {
$ifNull: [ $ifNull: [{
{
$cond: { $cond: {
if: { if: {
$or: [ $or: [{
{ $eq: ["$description", ""] }, $eq: ["$description", ""]
{ $eq: ["$description", null] }, },
{ $eq: ["$description", undefined] } {
$eq: ["$description", null]
},
{
$eq: ["$description", undefined]
}
] ]
}, },
then: "This list has no description", then: "This list has no description",
@@ -64,14 +75,18 @@ function get_frontpage_lists(callback) {
] ]
}, },
thumbnail: { thumbnail: {
$ifNull: [ $ifNull: [{
{
$cond: { $cond: {
if: { if: {
$or: [ $or: [{
{ $eq: ["$thumbnail", ""] }, $eq: ["$thumbnail", ""]
{ $eq: ["$thumbnail", null] }, },
{ $eq: ["$thumbnail", undefined] } {
$eq: ["$thumbnail", null]
},
{
$eq: ["$thumbnail", undefined]
}
] ]
}, },
then: { then: {
@@ -80,16 +95,19 @@ function get_frontpage_lists(callback) {
else: "$thumbnail" 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( db.collection("frontpage_lists").aggregate(
[ [{
{
$match: { $match: {
frontpage: true, 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) { function update_frontpage(coll, id, title, thumbnail, source, callback) {
//coll = coll.replace(/ /g,''); //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 = { var updateObject = {
id: id, id: id,
title: title, title: title,
@@ -129,10 +149,13 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
updateObject.thumbnail = thumbnail; updateObject.thumbnail = thumbnail;
if (thumbnail == undefined) updateObject.thumbnail = ""; if (thumbnail == undefined) updateObject.thumbnail = "";
} }
db.collection("frontpage_lists").update( db.collection("frontpage_lists").update({
{ _id: coll }, _id: coll
{ $set: updateObject }, }, {
{ upsert: true }, $set: updateObject
}, {
upsert: true
},
function (err, returnDocs) { function (err, returnDocs) {
if (typeof callback == "function") callback(); if (typeof callback == "function") callback();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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