mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
More intermediary work
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
||||||
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
var remove = require(pathThumbnails + "/handlers/dbFunctions/remove.js");
|
var remove = require(pathThumbnails + "/handlers/dbFunctions/remove.js");
|
||||||
|
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
var frontpage = require(pathThumbnails +
|
var frontpage = require(pathThumbnails +
|
||||||
"/handlers/dbFunctions/frontpageUpdates.js");
|
"/handlers/dbFunctions/advancedFunctions/frontpageUpdates.js");
|
||||||
var findAggregate = [
|
var findAggregate = [
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
@@ -49,12 +52,14 @@ var verifyAggregate = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
async function changeSong(coll, error, id, conf, socket) {
|
async function changeSong(coll, error, id, conf, socket) {
|
||||||
|
console.log("hello");
|
||||||
return pre(coll, error, id, conf, socket);
|
return pre(coll, error, id, conf, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pre(coll, error, id, conf, socket) {
|
async function pre(coll, error, id, conf, socket) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
var startTime = conf[0].startTime;
|
var startTime = conf[0].startTime;
|
||||||
if (conf === null || conf.length == 0) {
|
if (conf === null || conf.length == 0) {
|
||||||
return;
|
return;
|
||||||
@@ -72,13 +77,12 @@ async function pre(coll, error, id, conf, socket) {
|
|||||||
next_song = now_playing_doc[1].id;
|
next_song = now_playing_doc[1].id;
|
||||||
}
|
}
|
||||||
await post(coll, next_song, conf, socket, error);
|
await post(coll, next_song, conf, socket, error);
|
||||||
/*if (!callback) {
|
|
||||||
io.to(coll).emit("channel", {
|
io.to(coll).emit("channel", {
|
||||||
type: "deleted",
|
type: "deleted",
|
||||||
value: now_playing_doc[0].id,
|
value: now_playing_doc[0].id,
|
||||||
removed: true
|
removed: true
|
||||||
});
|
});
|
||||||
}*/
|
|
||||||
if (docs.deletedCount == 1) {
|
if (docs.deletedCount == 1) {
|
||||||
frontpage.incrementList("frontpage_lists", -1);
|
frontpage.incrementList("frontpage_lists", -1);
|
||||||
}
|
}
|
||||||
@@ -95,9 +99,10 @@ async function pre(coll, error, id, conf, socket) {
|
|||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
console.log("here 2");
|
||||||
if (
|
if (
|
||||||
(conf[0].skipped_time != undefined &&
|
(conf[0].skipped_time != undefined &&
|
||||||
conf[0].skipped_time != Functions.get_time()) ||
|
conf[0].skipped_time != Helpers.get_time()) ||
|
||||||
conf[0].skipped_time == undefined
|
conf[0].skipped_time == undefined
|
||||||
) {
|
) {
|
||||||
var docs = await update(
|
var docs = await update(
|
||||||
@@ -112,6 +117,7 @@ async function pre(coll, error, id, conf, socket) {
|
|||||||
},
|
},
|
||||||
{ multi: true }
|
{ multi: true }
|
||||||
);
|
);
|
||||||
|
console.log("update", docs);
|
||||||
var next_song;
|
var next_song;
|
||||||
if (now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if (now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
await post(coll, next_song, conf, socket, error);
|
await post(coll, next_song, conf, socket, error);
|
||||||
@@ -140,7 +146,7 @@ async function pre(coll, error, id, conf, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function post(coll, next_song, conf, socket, removed) {
|
async function post(coll, next_song, conf, socket, removed) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
var docs = await aggregate(coll, verifyAggregate);
|
var docs = await aggregate(coll, verifyAggregate);
|
||||||
if (docs === null || docs.length == 0) {
|
if (docs === null || docs.length == 0) {
|
||||||
reject();
|
reject();
|
||||||
@@ -163,7 +169,7 @@ async function post(coll, next_song, conf, socket, removed) {
|
|||||||
now_playing: true,
|
now_playing: true,
|
||||||
votes: 0,
|
votes: 0,
|
||||||
guids: [],
|
guids: [],
|
||||||
added: Functions.get_time()
|
added: Helpers.get_time()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
@@ -175,12 +181,18 @@ async function post(coll, next_song, conf, socket, removed) {
|
|||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
io.to(coll).emit("channel", {
|
||||||
|
type: "song_change",
|
||||||
|
time: Helpers.get_time(),
|
||||||
|
remove: conf[0].removeplay || removed,
|
||||||
|
id: id
|
||||||
|
});
|
||||||
returnDocs = await update(
|
returnDocs = await update(
|
||||||
coll + "_settings",
|
coll + "_settings",
|
||||||
{ id: "config" },
|
{ id: "config" },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
startTime: Functions.get_time(),
|
startTime: Helpers.get_time(),
|
||||||
skips: []
|
skips: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -190,6 +202,6 @@ async function post(coll, next_song, conf, socket, removed) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.changeSong = changeSong;
|
module.exports = changeSong;
|
||||||
module.exports.pre = pre;
|
module.exports.pre = pre;
|
||||||
module.exports.post = post;
|
module.exports.post = post;
|
||||||
|
|||||||
402
server/handlers/dbFunctions/advancedFunctions/chat.js
Normal file
402
server/handlers/dbFunctions/advancedFunctions/chat.js
Normal file
@@ -0,0 +1,402 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var mongojs = require("mongojs");
|
||||||
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
var findAndModify = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/findAndModify.js");
|
||||||
|
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
var SessionHandler = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sessionHandler.js");
|
||||||
|
async function checkIfChatEnabled(channel, socket, callback) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
if (channel == "" || channel == undefined) resolve();
|
||||||
|
else {
|
||||||
|
var docs = await find(channel + "_settings");
|
||||||
|
if (
|
||||||
|
docs.length > 0 &&
|
||||||
|
(docs[0].hasOwnProperty("toggleChat") && !docs[0].toggleChat)
|
||||||
|
) {
|
||||||
|
socket.emit("chat", {
|
||||||
|
from: "System",
|
||||||
|
msg: ": Chat for this channel has been disabled.",
|
||||||
|
icon: "https://zoff.me/assets/images/favicon-32x32.png"
|
||||||
|
});
|
||||||
|
resolve(false);
|
||||||
|
} else {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkIfUserIsBanned(channel, socket, guid) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
var connection_id = Helpers.hash_pass(
|
||||||
|
socket.handshake.headers["user-agent"] +
|
||||||
|
socket.handshake.address +
|
||||||
|
socket.handshake.headers["accept-language"]
|
||||||
|
);
|
||||||
|
var docs = await find(channel + "_banned_chat", {
|
||||||
|
$or: [{ connection_id: connection_id }, { connection_id: guid }]
|
||||||
|
});
|
||||||
|
if (docs.length == 0) resolve();
|
||||||
|
else {
|
||||||
|
var d = await findAndModify("user_names", {
|
||||||
|
query: { guid, guid },
|
||||||
|
update: { $addToSet: { channels: channel } }
|
||||||
|
});
|
||||||
|
socket.emit("chat", {
|
||||||
|
from: "System",
|
||||||
|
msg:
|
||||||
|
": You can't chat in this channel, you are banned. The reason is: " +
|
||||||
|
docs[0].reason,
|
||||||
|
icon: "https://zoff.me/assets/images/favicon-32x32.png"
|
||||||
|
});
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function namechange(data, guid, socket, tried) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
var enabled = await checkIfChatEnabled(data.channel, socket);
|
||||||
|
if (!enabled) {
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await checkIfUserIsBanned(data.channel, socket, guid);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pw = "";
|
||||||
|
var new_password;
|
||||||
|
var first = false;
|
||||||
|
var sessionObject = await SessionHandler.getSessionChatPass(
|
||||||
|
Helpers.getSession(socket)
|
||||||
|
);
|
||||||
|
var name = sessionObject.name;
|
||||||
|
var pass = sessionObject.pass;
|
||||||
|
var fetched = false;
|
||||||
|
if (data.hasOwnProperty("first") && data.first) {
|
||||||
|
pw = pass;
|
||||||
|
name = name;
|
||||||
|
data.name = name;
|
||||||
|
data.password = pass;
|
||||||
|
new_password = false;
|
||||||
|
if (name == "" || pass == "") {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetched = true;
|
||||||
|
password = pw;
|
||||||
|
} else {
|
||||||
|
var name = data.name;
|
||||||
|
if (data.hasOwnProperty("first")) {
|
||||||
|
first = data.first;
|
||||||
|
}
|
||||||
|
if (data.hasOwnProperty("password")) {
|
||||||
|
pw = data.password;
|
||||||
|
new_password = false;
|
||||||
|
} else if (
|
||||||
|
data.hasOwnProperty("new_password") &&
|
||||||
|
data.hasOwnProperty("old_password")
|
||||||
|
) {
|
||||||
|
pw = data.old_password;
|
||||||
|
new_password = Helpers.decrypt_string(data.new_password);
|
||||||
|
}
|
||||||
|
password = Helpers.decrypt_string(pw);
|
||||||
|
password = Helpers.hash_pass(password);
|
||||||
|
doubled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == "") {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var docs = await find("registered_users", { _id: name.toLowerCase() });
|
||||||
|
var accepted_password = false;
|
||||||
|
var icon = false;
|
||||||
|
if (docs.length == 0) {
|
||||||
|
if (new_password) {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accepted_password = true;
|
||||||
|
await SessionHandler.setSessionChatPass(
|
||||||
|
Functions.getSession(socket),
|
||||||
|
name.toLowerCase(),
|
||||||
|
data.password
|
||||||
|
);
|
||||||
|
update(
|
||||||
|
"registered_users",
|
||||||
|
{ _id: name.toLowerCase() },
|
||||||
|
{ $set: { password: password } },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
} else if (docs[0].password == password) {
|
||||||
|
if (docs[0].icon) {
|
||||||
|
icon = docs[0].icon;
|
||||||
|
}
|
||||||
|
accepted_password = true;
|
||||||
|
if (new_password) {
|
||||||
|
await SessionHandler.setSessionChatPass(
|
||||||
|
Helpers.getSession(socket),
|
||||||
|
name.toLowerCase(),
|
||||||
|
data.new_password
|
||||||
|
);
|
||||||
|
update(
|
||||||
|
"registered_users",
|
||||||
|
{ _id: name.toLowerCase(), password: password },
|
||||||
|
{
|
||||||
|
$set: { password: Helpers.hash_pass(new_password) }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await SessionHandler.setSessionChatPass(
|
||||||
|
Helpers.getSession(socket),
|
||||||
|
name.toLowerCase(),
|
||||||
|
fetched
|
||||||
|
? data.password
|
||||||
|
: Helpers.hash_pass(Helpers.decrypt_string(data.password))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (accepted_password) {
|
||||||
|
var names = await find("user_names", { guid: guid });
|
||||||
|
if (
|
||||||
|
names.length > 0 ||
|
||||||
|
(docs.length != 0 && docs[0].password == password)
|
||||||
|
) {
|
||||||
|
var no_name = false;
|
||||||
|
if (names.length == 0) no_name = true;
|
||||||
|
if (!no_name) {
|
||||||
|
var old_name = names[0].name;
|
||||||
|
update(
|
||||||
|
"user_names",
|
||||||
|
{ _id: "all_names" },
|
||||||
|
{ $pull: { names: old_name } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
var connection_id = Helpers.hash_pass(
|
||||||
|
socket.handshake.headers["user-agent"] +
|
||||||
|
socket.handshake.address +
|
||||||
|
socket.handshake.headers["accept-language"]
|
||||||
|
);
|
||||||
|
var updateElement = {
|
||||||
|
$set: {
|
||||||
|
name: name,
|
||||||
|
icon: icon,
|
||||||
|
connection_id: connection_id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (data.hasOwnProperty("channel") && data.channel != "") {
|
||||||
|
updateElement["$addToSet"] = { channels: data.channel };
|
||||||
|
}
|
||||||
|
await update("user_names", { guid: guid }, updateElement, {
|
||||||
|
upsert: true
|
||||||
|
});
|
||||||
|
await update(
|
||||||
|
"user_names",
|
||||||
|
{ _id: "all_names" },
|
||||||
|
{ $addToSet: { names: name } }
|
||||||
|
);
|
||||||
|
//socket.emit('name', {type: "name", accepted: true});
|
||||||
|
if (old_name != name && !first && !no_name) {
|
||||||
|
if (
|
||||||
|
data.hasOwnProperty("channel") &&
|
||||||
|
typeof data.channel == "string"
|
||||||
|
) {
|
||||||
|
io.to(data.channel).emit("chat", {
|
||||||
|
from: old_name,
|
||||||
|
msg: " changed name to " + name
|
||||||
|
});
|
||||||
|
io.sockets.emit("chat.all", {
|
||||||
|
from: old_name,
|
||||||
|
msg: " changed name to " + name,
|
||||||
|
channel: data.channel
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
if (tried < 3 || tried == undefined) {
|
||||||
|
if (tried == undefined) {
|
||||||
|
tried = 1;
|
||||||
|
}
|
||||||
|
namechange(data, guid, socket, tried + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await SessionHandler.removeSessionChatPass(Functions.Helpers(socket));
|
||||||
|
socket.emit("name", { type: "name", accepted: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function get_name(guid, announce_payload, first) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
if (
|
||||||
|
!announce_payload.announce &&
|
||||||
|
announce_payload.hasOwnProperty("socket")
|
||||||
|
) {
|
||||||
|
var sessionObject = await SessionHandler.getSessionChatPass(
|
||||||
|
Helpers.getSession(announce_payload.socket)
|
||||||
|
);
|
||||||
|
var name = sessionObject.name;
|
||||||
|
var pass = sessionObject.pass;
|
||||||
|
if (name == "" || pass == "") {
|
||||||
|
get_name_generate(
|
||||||
|
guid,
|
||||||
|
announce_payload,
|
||||||
|
first,
|
||||||
|
announce_payload.channel
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var docs = find("registered_users", { _id: name.toLowerCase() });
|
||||||
|
if (docs[0].password == Helpers.hash_pass(Helpers.decrypt_string(pass))) {
|
||||||
|
var icon = false;
|
||||||
|
if (docs[0].icon) {
|
||||||
|
icon = docs[0].icon;
|
||||||
|
}
|
||||||
|
SessionHandler.setSessionChatPass(
|
||||||
|
Functions.getSession(announce_payload.socket),
|
||||||
|
name.toLowerCase(),
|
||||||
|
pass
|
||||||
|
);
|
||||||
|
var connection_id = Helpers.hash_pass(
|
||||||
|
announce_payload.socket.handshake.headers["user-agent"] +
|
||||||
|
announce_payload.socket.handshake.address +
|
||||||
|
announce_payload.socket.handshake.headers["accept-language"]
|
||||||
|
);
|
||||||
|
var updateElement = {
|
||||||
|
$set: { name: name, icon: icon, connection_id: connection_id }
|
||||||
|
};
|
||||||
|
if (
|
||||||
|
announce_payload.hasOwnProperty("channel") &&
|
||||||
|
announce_payload.channel != ""
|
||||||
|
)
|
||||||
|
updateElement["$addToSet"] = {
|
||||||
|
channel: announce_payload.channel
|
||||||
|
};
|
||||||
|
await update("user_names", { guid: guid }, updateElement, {
|
||||||
|
upsert: true
|
||||||
|
});
|
||||||
|
await update(
|
||||||
|
"user_names",
|
||||||
|
{ _id: "all_names" },
|
||||||
|
{ $addToSet: { names: name } }
|
||||||
|
);
|
||||||
|
name = name;
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
get_name_generate(
|
||||||
|
guid,
|
||||||
|
announce_payload,
|
||||||
|
first,
|
||||||
|
announce_payload.channel
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function get_name_generate(guid, announce_payload, first, channel) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
var docs = await find("user_names", { guid: guid });
|
||||||
|
if (docs.length == 0) {
|
||||||
|
generate_name(guid, announce_payload, undefined);
|
||||||
|
} else {
|
||||||
|
name = docs[0].name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generate_name(guid, announce_payload, second, round, channel) {
|
||||||
|
if (round == undefined) round = 0;
|
||||||
|
var tmp_name = Helpers.rndName(second ? second : guid, Math.floor(8 + round));
|
||||||
|
var docs = await find("registered_users", { _id: tmp_name });
|
||||||
|
if (docs.length == 0) {
|
||||||
|
var updated = await update(
|
||||||
|
"user_names",
|
||||||
|
{ _id: "all_names" },
|
||||||
|
{ $addToSet: { names: tmp_name } },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
updated.nModified == 1 ||
|
||||||
|
(updated.hasOwnProperty("upserted") &&
|
||||||
|
updated.hasOwnProperty("n") &&
|
||||||
|
updated.n == 1)
|
||||||
|
) {
|
||||||
|
var connection_id = Helpers.hash_pass(
|
||||||
|
announce_payload.socket.handshake.headers["user-agent"] +
|
||||||
|
announce_payload.socket.handshake.address +
|
||||||
|
announce_payload.socket.handshake.headers["accept-language"]
|
||||||
|
);
|
||||||
|
var updateElement = {
|
||||||
|
$set: {
|
||||||
|
name: tmp_name,
|
||||||
|
icon: false,
|
||||||
|
connection_id: connection_id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (channel != undefined && channel != "") {
|
||||||
|
updateElement["$addToSet"] = { channels: channel };
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
announce_payload.hasOwnProperty("channel") &&
|
||||||
|
announce_payload.channel != ""
|
||||||
|
) {
|
||||||
|
updateElement["$addToSet"] = {
|
||||||
|
channels: announce_payload.channel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var updateElement = await update(
|
||||||
|
"user_names",
|
||||||
|
{ guid: guid },
|
||||||
|
updateElement,
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
name = tmp_name;
|
||||||
|
if (announce_payload.announce) {
|
||||||
|
io.to(announce_payload.channel).emit("chat", {
|
||||||
|
from: announce_payload.old_name,
|
||||||
|
msg: " changed name to " + name
|
||||||
|
});
|
||||||
|
io.sockets.emit("chat.all", {
|
||||||
|
from: announce_payload.old_name,
|
||||||
|
msg: " changed name to " + name,
|
||||||
|
channel: announce_payload.channel
|
||||||
|
});
|
||||||
|
} else if (announce_payload.message && !announce_payload.all) {
|
||||||
|
io.to(announce_payload.channel).emit("chat", {
|
||||||
|
from: name,
|
||||||
|
msg: ": " + announce_payload.message
|
||||||
|
});
|
||||||
|
} else if (announce_payload.message && announce_payload.all) {
|
||||||
|
io.sockets.emit("chat.all", {
|
||||||
|
from: name,
|
||||||
|
msg: ": " + announce_payload.message,
|
||||||
|
channel: announce_payload.channel
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.get_name = get_name;
|
||||||
|
module.exports.checkIfChatEnabled = checkIfChatEnabled;
|
||||||
|
module.exports.checkIfUserIsBanned = checkIfUserIsBanned;
|
||||||
|
module.exports.namechange = namechange;
|
||||||
|
module.exports.get_name_generate = get_name_generate;
|
||||||
@@ -1,3 +1,12 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var mongojs = require("mongojs");
|
||||||
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
|
||||||
|
var SessionHandler = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sessionHandler.js");
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
|
||||||
async function end(obj, coll, guid, offline, socket) {
|
async function end(obj, coll, guid, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if (typeof obj !== "object") {
|
if (typeof obj !== "object") {
|
||||||
@@ -45,9 +54,12 @@ async function end(obj, coll, guid, offline, socket) {
|
|||||||
docs.length > 0 &&
|
docs.length > 0 &&
|
||||||
(docs[0].userpass != undefined && docs[0].userpass != "")
|
(docs[0].userpass != undefined && docs[0].userpass != "")
|
||||||
) {
|
) {
|
||||||
callback_function = Functions.getSessionAdminUser;
|
callback_function = SessionHandler.getSessionAdminUser;
|
||||||
authentication_needed = true;
|
authentication_needed = true;
|
||||||
var sessionAdminUser = await Functions.getSessionAdminUser(Functions.getSession(socket), coll);
|
var sessionAdminUser = await SessionHandler.getSessionAdminUser(
|
||||||
|
Helpers.getSession(socket),
|
||||||
|
coll
|
||||||
|
);
|
||||||
obj.userpass = sessionAdminUser.userpass;
|
obj.userpass = sessionAdminUser.userpass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,52 +67,44 @@ async function end(obj, coll, guid, offline, socket) {
|
|||||||
obj.pass = userpass;
|
obj.pass = userpass;
|
||||||
} else {
|
} else {
|
||||||
obj.pass = crypto
|
obj.pass = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
.update(Functions.decrypt_string(obj.pass))
|
.update(Helpers.decrypt_string(obj.pass))
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!authentication_needed ||
|
!authentication_needed ||
|
||||||
(authentication_needed &&
|
(authentication_needed &&
|
||||||
obj.hasOwnProperty("pass") &&
|
obj.hasOwnProperty("pass") &&
|
||||||
docs[0].userpass == obj.pass)
|
docs[0].userpass == obj.pass)
|
||||||
) {
|
) {
|
||||||
Functions.check_inlist(
|
Functions.check_inlist(
|
||||||
coll,
|
coll,
|
||||||
guid,
|
guid,
|
||||||
socket,
|
socket,
|
||||||
offline,
|
offline,
|
||||||
undefined,
|
undefined,
|
||||||
"place 13"
|
"place 13"
|
||||||
);
|
);
|
||||||
var np = await find(coll, { now_playing: true });
|
var np = await find(coll, { now_playing: true });
|
||||||
if (err !== null) console.log(err);
|
if (err !== null) console.log(err);
|
||||||
if (
|
if (np !== null && np !== undefined && np.length == 1 && np[0].id == id) {
|
||||||
np !== null &&
|
var startTime = docs[0].startTime;
|
||||||
np !== undefined &&
|
if (startTime + parseInt(np[0].duration) <= Helpers.get_time() + 5) {
|
||||||
np.length == 1 &&
|
changeSong(coll, false, id, docs);
|
||||||
np[0].id == id
|
|
||||||
) {
|
|
||||||
var startTime = docs[0].startTime;
|
|
||||||
if (
|
|
||||||
startTime + parseInt(np[0].duration) <=
|
|
||||||
Functions.get_time() + 5
|
|
||||||
) {
|
|
||||||
changeSong(coll, false, id, docs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
socket.emit("auth_required");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = {
|
socket.emit("auth_required");
|
||||||
msg: {
|
|
||||||
expected: "object",
|
|
||||||
got: typeof obj
|
|
||||||
}
|
|
||||||
};
|
|
||||||
socket.emit("update_required", result);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
var result = {
|
||||||
|
msg: {
|
||||||
|
expected: "object",
|
||||||
|
got: typeof obj
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socket.emit("update_required", result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.end = end;
|
module.exports.end = end;
|
||||||
|
|||||||
112
server/handlers/dbFunctions/advancedFunctions/frontpageLists.js
Normal file
112
server/handlers/dbFunctions/advancedFunctions/frontpageLists.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var mongojs = require("mongojs");
|
||||||
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
||||||
|
|
||||||
|
async function frontpageLists(msg, socket) {
|
||||||
|
if (
|
||||||
|
msg == undefined ||
|
||||||
|
!msg.hasOwnProperty("version") ||
|
||||||
|
msg.version != VERSION ||
|
||||||
|
msg.version == undefined
|
||||||
|
) {
|
||||||
|
var result = {
|
||||||
|
version: {
|
||||||
|
expected: VERSION,
|
||||||
|
got: msg.hasOwnProperty("version") ? msg.version : undefined
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socket.emit("update_required", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var docs = await find("frontpage_lists", { frontpage: true });
|
||||||
|
var tot = await find("connected_users", { _id: "total_users" });
|
||||||
|
socket.compress(true).emit("playlists", {
|
||||||
|
channels: docs,
|
||||||
|
viewers: tot[0].total_users.length
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getFrontpageLists(callback) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
var project_object = {
|
||||||
|
_id: 1,
|
||||||
|
count: 1,
|
||||||
|
frontpage: 1,
|
||||||
|
id: 1,
|
||||||
|
title: 1,
|
||||||
|
viewers: 1,
|
||||||
|
accessed: 1,
|
||||||
|
pinned: { $ifNull: ["$pinned", 0] },
|
||||||
|
description: {
|
||||||
|
$ifNull: [
|
||||||
|
{
|
||||||
|
$cond: {
|
||||||
|
if: {
|
||||||
|
$or: [
|
||||||
|
{ $eq: ["$description", ""] },
|
||||||
|
{ $eq: ["$description", null] },
|
||||||
|
{ $eq: ["$description", undefined] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
then: "This list has no description",
|
||||||
|
else: "$description"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"This list has no description"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
thumbnail: {
|
||||||
|
$ifNull: [
|
||||||
|
{
|
||||||
|
$cond: {
|
||||||
|
if: {
|
||||||
|
$or: [
|
||||||
|
{ $eq: ["$thumbnail", ""] },
|
||||||
|
{ $eq: ["$thumbnail", null] },
|
||||||
|
{ $eq: ["$thumbnail", undefined] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
then: {
|
||||||
|
$concat: [
|
||||||
|
"https://img.youtube.com/vi/",
|
||||||
|
"$id",
|
||||||
|
"/mqdefault.jpg"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
else: "$thumbnail"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var docs = await aggregate("frontpage_lists", [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
frontpage: true,
|
||||||
|
count: { $gt: 3 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: project_object
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
pinned: -1,
|
||||||
|
viewers: -1,
|
||||||
|
accessed: -1,
|
||||||
|
count: -1,
|
||||||
|
title: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
resolve(docs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.frontpageLists = frontpageLists;
|
||||||
|
module.exports.getFrontpageLists = getFrontpageLists;
|
||||||
@@ -3,16 +3,49 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
async function incrementList(collection, way) {
|
async function incrementList(collection, way) {
|
||||||
return update(
|
return update(
|
||||||
collection,
|
collection,
|
||||||
{ _id: coll, count: { $gt: 0 } },
|
{ _id: coll, count: { $gt: 0 } },
|
||||||
{
|
{
|
||||||
$inc: { count: way },
|
$inc: { count: way },
|
||||||
$set: { accessed: Functions.get_time() }
|
$set: { accessed: Helpers.get_time() }
|
||||||
},
|
},
|
||||||
{ upsert: true }
|
{ upsert: true }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateFrontpage(coll, id, title, thumbnail, source) {
|
||||||
|
//coll = coll.replace(/ /g,'');
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
var doc = await find("frontpage_lists", { _id: coll });
|
||||||
|
var updateObject = {
|
||||||
|
id: id,
|
||||||
|
title: title,
|
||||||
|
accessed: Helpers.get_time()
|
||||||
|
};
|
||||||
|
if (
|
||||||
|
doc.length > 0 &&
|
||||||
|
((doc[0].thumbnail != "" &&
|
||||||
|
doc[0].thumbnail != undefined &&
|
||||||
|
(doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 ||
|
||||||
|
doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 ||
|
||||||
|
doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) ||
|
||||||
|
(doc[0].thumbnail == "" || doc[0].thumbnail == undefined))
|
||||||
|
) {
|
||||||
|
updateObject.thumbnail = thumbnail;
|
||||||
|
if (thumbnail == undefined) updateObject.thumbnail = "";
|
||||||
|
}
|
||||||
|
await update(
|
||||||
|
"frontpage_lists",
|
||||||
|
{ _id: coll },
|
||||||
|
{ $set: updateObject },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.updateFrontpage = updateFrontpage;
|
||||||
module.exports.incrementList = incrementList;
|
module.exports.incrementList = incrementList;
|
||||||
|
|||||||
111
server/handlers/dbFunctions/advancedFunctions/inlistCheck.js
Normal file
111
server/handlers/dbFunctions/advancedFunctions/inlistCheck.js
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
|
||||||
|
var SessionHandler = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sessionHandler.js");
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
var Chat = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/chat.js");
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
|
|
||||||
|
async function check(coll, guid, socket, offline, callback, double_check) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
if (coll == undefined) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//coll = coll.replace(/ /g,'');
|
||||||
|
if (!offline && coll != undefined) {
|
||||||
|
var updated = await update(
|
||||||
|
"connected_users",
|
||||||
|
{ _id: coll },
|
||||||
|
{ $addToSet: { users: guid } },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
if (updated.nModified > 0 || updated.upserted != undefined) {
|
||||||
|
var new_doc = await find("connected_users", { _id: coll });
|
||||||
|
await update(
|
||||||
|
"frontpage_lists",
|
||||||
|
{ _id: coll },
|
||||||
|
{ $set: { viewers: new_doc[0].users.length } }
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
new_doc[0].users == undefined ||
|
||||||
|
new_doc[0].users.length == undefined
|
||||||
|
) {
|
||||||
|
io.to(coll).emit("viewers", 1);
|
||||||
|
} else {
|
||||||
|
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||||
|
}
|
||||||
|
var enabled = await Chat.namechange(
|
||||||
|
{ initial: true, first: true, channel: coll },
|
||||||
|
guid,
|
||||||
|
socket,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
var docs = await find("user_names", { guid: guid });
|
||||||
|
if (docs.length == 1) {
|
||||||
|
var icon = "";
|
||||||
|
if (docs[0].icon != undefined) icon = docs[0].icon;
|
||||||
|
update(
|
||||||
|
"user_names",
|
||||||
|
{ guid: guid },
|
||||||
|
{ $addToSet: { channels: coll } }
|
||||||
|
);
|
||||||
|
if (enabled) {
|
||||||
|
socket.broadcast.to(coll).emit("chat", {
|
||||||
|
from: docs[0].name,
|
||||||
|
icon: icon,
|
||||||
|
msg: " joined"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (docs.length == 0) {
|
||||||
|
//console.log("User doesn't have a name for some reason.");
|
||||||
|
//console.log("guid", guid);
|
||||||
|
//console.log("channel", coll);
|
||||||
|
//console.log("Trying to get a chat-name");
|
||||||
|
Chat.get_name(guid, {
|
||||||
|
announce: false,
|
||||||
|
socket: socket,
|
||||||
|
channel: coll
|
||||||
|
});
|
||||||
|
}
|
||||||
|
update(
|
||||||
|
"connected_users",
|
||||||
|
{ _id: "total_users" },
|
||||||
|
{ $addToSet: { total_users: guid + coll } }
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
var new_doc = await find("connected_users", { _id: coll });
|
||||||
|
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (offline) {
|
||||||
|
update(
|
||||||
|
"connected_users",
|
||||||
|
{ _id: "offline_users" },
|
||||||
|
{ $addToSet: { users: guid } }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
update(
|
||||||
|
"connected_users",
|
||||||
|
{ _id: coll },
|
||||||
|
{ $addToSet: { users: guid } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (coll != undefined && coll != "") {
|
||||||
|
update(
|
||||||
|
"connected_users",
|
||||||
|
{ _id: "total_users" },
|
||||||
|
{ $addToSet: { total_users: guid + coll } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.check = check;
|
||||||
@@ -5,6 +5,19 @@ var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
|||||||
var create = require(pathThumbnails + "/handlers/dbFunctions/create.js");
|
var create = require(pathThumbnails + "/handlers/dbFunctions/create.js");
|
||||||
var insert = require(pathThumbnails + "/handlers/dbFunctions/insert.js");
|
var insert = require(pathThumbnails + "/handlers/dbFunctions/insert.js");
|
||||||
|
|
||||||
|
var sendList = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sendList.js");
|
||||||
|
|
||||||
|
var crypto = require("crypto");
|
||||||
|
var SessionHandler = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sessionHandler.js");
|
||||||
|
var Inlist = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/inlistCheck.js");
|
||||||
|
var Play = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/play.js");
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
async function joinSilent(msg, socket) {
|
async function joinSilent(msg, socket) {
|
||||||
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
||||||
var channelName = msg.channel;
|
var channelName = msg.channel;
|
||||||
@@ -12,7 +25,7 @@ async function joinSilent(msg, socket) {
|
|||||||
var password = "";
|
var password = "";
|
||||||
if (msg.password != "") {
|
if (msg.password != "") {
|
||||||
tryingPassword = true;
|
tryingPassword = true;
|
||||||
password = Functions.decrypt_string(msg.password);
|
password = Helpers.decrypt_string(msg.password);
|
||||||
password = crypto
|
password = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
.update(password)
|
.update(password)
|
||||||
@@ -20,7 +33,7 @@ async function joinSilent(msg, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
channelName = channelName.toLowerCase(); //.replace(/ /g,'');
|
channelName = channelName.toLowerCase(); //.replace(/ /g,'');
|
||||||
channelName = Functions.removeEmojis(channelName).toLowerCase();
|
channelName = Helpers.removeEmojis(channelName).toLowerCase();
|
||||||
var docs = await find(channelName + "_settings");
|
var docs = await find(channelName + "_settings");
|
||||||
if (docs.length == 0) {
|
if (docs.length == 0) {
|
||||||
socket.emit("join_silent_declined", "");
|
socket.emit("join_silent_declined", "");
|
||||||
@@ -34,7 +47,7 @@ async function joinSilent(msg, socket) {
|
|||||||
socket.join(channelName);
|
socket.join(channelName);
|
||||||
socket.emit("join_silent_accepted", "");
|
socket.emit("join_silent_accepted", "");
|
||||||
|
|
||||||
send_play(channelName, socket);
|
Play.sendPlay(channelName, socket);
|
||||||
} else {
|
} else {
|
||||||
socket.emit("join_silent_declined", "");
|
socket.emit("join_silent_declined", "");
|
||||||
}
|
}
|
||||||
@@ -46,8 +59,8 @@ async function joinSilent(msg, socket) {
|
|||||||
async function joinList(msg, guid, coll, offline, socket) {
|
async function joinList(msg, guid, coll, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
||||||
var sessionAdminUser = await Functions.getSessionAdminUser(
|
var sessionAdminUser = await SessionHandler.getSessionAdminUser(
|
||||||
Functions.getSession(socket),
|
Helpers.getSession(socket),
|
||||||
coll
|
coll
|
||||||
);
|
);
|
||||||
var userpass = sessionAdminUser.userpass;
|
var userpass = sessionAdminUser.userpass;
|
||||||
@@ -58,10 +71,10 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
} else {
|
} else {
|
||||||
msg.pass = crypto
|
msg.pass = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
.update(Functions.decrypt_string(msg.pass))
|
.update(Helpers.decrypt_string(msg.pass))
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
adminpass = Functions.hash_pass(adminpass);
|
adminpass = Helpers.hash_pass(adminpass);
|
||||||
if (
|
if (
|
||||||
!msg.hasOwnProperty("version") ||
|
!msg.hasOwnProperty("version") ||
|
||||||
!msg.hasOwnProperty("channel") ||
|
!msg.hasOwnProperty("channel") ||
|
||||||
@@ -87,7 +100,7 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
coll = Helpers.removeEmojis(coll).toLowerCase();
|
||||||
//coll = filter.clean(coll);
|
//coll = filter.clean(coll);
|
||||||
var pass = msg.pass;
|
var pass = msg.pass;
|
||||||
var frontpage_lists = await find("frontpage_lists", { _id: coll });
|
var frontpage_lists = await find("frontpage_lists", { _id: coll });
|
||||||
@@ -106,15 +119,19 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
docs[0].userpass != "" &&
|
docs[0].userpass != "" &&
|
||||||
docs[0].userpass == pass
|
docs[0].userpass == pass
|
||||||
) {
|
) {
|
||||||
Functions.setSessionUserPass(
|
SessionHandler.setSessionUserPass(
|
||||||
Functions.getSession(socket),
|
Helpers.getSession(socket),
|
||||||
msg.pass,
|
msg.pass,
|
||||||
coll
|
coll
|
||||||
);
|
);
|
||||||
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.getSession(socket), "", coll);
|
SessionHandler.setSessionUserPass(
|
||||||
|
Helpers.getSession(socket),
|
||||||
|
"",
|
||||||
|
coll
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
docs.length > 0 &&
|
docs.length > 0 &&
|
||||||
@@ -126,14 +143,7 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
}
|
}
|
||||||
in_list = true;
|
in_list = true;
|
||||||
socket.join(coll);
|
socket.join(coll);
|
||||||
Functions.check_inlist(
|
Inlist.check(coll, guid, socket, offline, undefined, "place 10");
|
||||||
coll,
|
|
||||||
guid,
|
|
||||||
socket,
|
|
||||||
offline,
|
|
||||||
undefined,
|
|
||||||
"place 10"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (frontpage_lists[0].viewers != undefined) {
|
if (frontpage_lists[0].viewers != undefined) {
|
||||||
io.to(coll).emit("viewers", frontpage_lists[0].viewers);
|
io.to(coll).emit("viewers", frontpage_lists[0].viewers);
|
||||||
@@ -141,7 +151,7 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
io.to(coll).emit("viewers", 1);
|
io.to(coll).emit("viewers", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
send_list(coll, socket, true, false, true);
|
sendList(coll, socket, true, false, true);
|
||||||
} else {
|
} else {
|
||||||
socket.emit("auth_required");
|
socket.emit("auth_required");
|
||||||
}
|
}
|
||||||
@@ -159,7 +169,7 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
shuffle: true,
|
shuffle: true,
|
||||||
skip: false,
|
skip: false,
|
||||||
skips: [],
|
skips: [],
|
||||||
startTime: Functions.get_time(),
|
startTime: Helpers.get_time(),
|
||||||
views: [],
|
views: [],
|
||||||
vote: false,
|
vote: false,
|
||||||
description: "",
|
description: "",
|
||||||
@@ -171,22 +181,15 @@ async function joinList(msg, guid, coll, offline, socket) {
|
|||||||
};
|
};
|
||||||
await insert(coll + "_settings", configs);
|
await insert(coll + "_settings", configs);
|
||||||
socket.join(coll);
|
socket.join(coll);
|
||||||
send_list(coll, socket, true, false, true);
|
sendList(coll, socket, true, false, true);
|
||||||
insert("frontpage_lists", {
|
insert("frontpage_lists", {
|
||||||
_id: coll,
|
_id: coll,
|
||||||
count: 0,
|
count: 0,
|
||||||
frontpage: true,
|
frontpage: true,
|
||||||
accessed: Functions.get_time(),
|
accessed: Helpers.get_time(),
|
||||||
viewers: 1
|
viewers: 1
|
||||||
});
|
});
|
||||||
Functions.check_inlist(
|
Inlist.check(coll, guid, socket, offline, undefined, "place 11");
|
||||||
coll,
|
|
||||||
guid,
|
|
||||||
socket,
|
|
||||||
offline,
|
|
||||||
undefined,
|
|
||||||
"place 11"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = {
|
var result = {
|
||||||
|
|||||||
@@ -2,127 +2,130 @@ var path = require("path");
|
|||||||
var mongojs = require("mongojs");
|
var mongojs = require("mongojs");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
||||||
|
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
|
var nextSongAggregate = [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
views: {
|
||||||
|
$exists: false
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
$ne: "suggested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
now_playing: 1,
|
||||||
|
votes: -1,
|
||||||
|
added: 1,
|
||||||
|
title: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$limit: 1
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
async function getNowPlaying(list, socket) {
|
async function getNowPlaying(list, socket) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (typeof list !== "string" || typeof fn !== "function") {
|
if (typeof list !== "string" || typeof fn !== "function") {
|
||||||
socket.emit("update_required");
|
socket.emit("update_required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var docs = await find(list, { now_playing: true });
|
var docs = await find(list, { now_playing: true });
|
||||||
if (docs.length === 0) {
|
if (docs.length === 0) {
|
||||||
resolve("No song currently playing");
|
resolve("No song currently playing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var title = docs[0].title;
|
var title = docs[0].title;
|
||||||
if (title === undefined) resolve("No song currently playing");
|
if (title === undefined) resolve("No song currently playing");
|
||||||
else resolve(title);
|
else resolve(title);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendPlay(coll, socket, broadcast) {
|
async function sendPlay(coll, socket, broadcast) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
var np = await find(coll, { now_playing: true });
|
var np = await find(coll, { now_playing: true });
|
||||||
var conf = await find(coll + "_settings");
|
var conf = await find(coll + "_settings");
|
||||||
if (err !== null) console.log(err);
|
console.log(np);
|
||||||
try {
|
try {
|
||||||
if (Functions.get_time() - conf[0].startTime > np[0].duration) {
|
if (Helpers.get_time() - conf[0].startTime > np[0].duration) {
|
||||||
changeSong(coll, false, np[0].id, conf);
|
changeSong(coll, false, np[0].id, conf);
|
||||||
} else if (conf !== null && conf !== undefined && conf.length !== 0) {
|
} else if (conf !== null && conf !== undefined && conf.length !== 0) {
|
||||||
if (conf[0].adminpass !== "") conf[0].adminpass = true;
|
if (conf[0].adminpass !== "") conf[0].adminpass = true;
|
||||||
if (conf[0].hasOwnProperty("userpass") && conf[0].userpass != "")
|
if (conf[0].hasOwnProperty("userpass") && conf[0].userpass != "")
|
||||||
conf[0].userpass = true;
|
conf[0].userpass = true;
|
||||||
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: Helpers.get_time() };
|
||||||
if (socket === undefined) {
|
if (socket === undefined) {
|
||||||
io.to(coll).emit("np", toSend);
|
io.to(coll).emit("np", toSend);
|
||||||
//
|
//
|
||||||
getNextSong(coll, undefined);
|
getNextSong(coll, undefined);
|
||||||
var url =
|
var url = "https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
|
||||||
"https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
|
if (np[0].source == "soundcloud") url = np[0].thumbnail;
|
||||||
if (np[0].source == "soundcloud") url = np[0].thumbnail;
|
Helpers.sendColor(coll, false, url);
|
||||||
sendColor(coll, false, url);
|
} else {
|
||||||
} else {
|
var url = "https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
|
||||||
var url =
|
if (np[0].source == "soundcloud") url = np[0].thumbnail;
|
||||||
"https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
|
Helpers.sendColor(coll, socket, url);
|
||||||
if (np[0].source == "soundcloud") url = np[0].thumbnail;
|
if (broadcast) {
|
||||||
sendColor(coll, socket, url);
|
socket.to(coll).emit("np", toSend);
|
||||||
if (broadcast) {
|
return;
|
||||||
socket.to(coll).emit("np", toSend);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
socket.emit("np", toSend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (socket) {
|
|
||||||
if (broadcast) {
|
|
||||||
socket.to(coll).emit("np", {});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
socket.emit("np", {});
|
|
||||||
} else {
|
|
||||||
io.to(coll).emit("np", {});
|
|
||||||
}
|
}
|
||||||
|
socket.emit("np", toSend);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
if (socket) {
|
||||||
|
if (broadcast) {
|
||||||
|
socket.to(coll).emit("np", {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socket.emit("np", {});
|
||||||
|
} else {
|
||||||
|
io.to(coll).emit("np", {});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNextSong(coll, socket) {
|
async function getNextSong(coll, socket) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
var docs = await aggregate(coll,
|
var doc = await aggregate(coll, nextSongAggregate);
|
||||||
[
|
if (doc.length == 1) {
|
||||||
{
|
var thumbnail = "";
|
||||||
$match: {
|
var source = "youtube";
|
||||||
views: {
|
if (doc[0].source && doc[0].source == "soundcloud") {
|
||||||
$exists: false
|
source = "soundcloud";
|
||||||
},
|
thumbnail = doc[0].thumbnail;
|
||||||
type: {
|
}
|
||||||
$ne: "suggested"
|
if (socket != undefined) {
|
||||||
}
|
socket.emit("next_song", {
|
||||||
}
|
videoId: doc[0].id,
|
||||||
},
|
title: doc[0].title,
|
||||||
{
|
source: source,
|
||||||
$sort: {
|
thumbnail: thumbnail
|
||||||
now_playing: 1,
|
|
||||||
votes: -1,
|
|
||||||
added: 1,
|
|
||||||
title: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$limit: 1
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
if (doc.length == 1) {
|
|
||||||
var thumbnail = "";
|
|
||||||
var source = "youtube";
|
|
||||||
if (doc[0].source && doc[0].source == "soundcloud") {
|
|
||||||
source = "soundcloud";
|
|
||||||
thumbnail = doc[0].thumbnail;
|
|
||||||
}
|
|
||||||
if (socket != undefined) {
|
|
||||||
socket.emit("next_song", {
|
|
||||||
videoId: doc[0].id,
|
|
||||||
title: doc[0].title,
|
|
||||||
source: source,
|
|
||||||
thumbnail: thumbnail
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
io.to(coll).emit("next_song", {
|
|
||||||
videoId: doc[0].id,
|
|
||||||
title: doc[0].title,
|
|
||||||
source: source,
|
|
||||||
thumbnail: thumbnail
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
io.to(coll).emit("next_song", {
|
||||||
|
videoId: doc[0].id,
|
||||||
|
title: doc[0].title,
|
||||||
|
source: source,
|
||||||
|
thumbnail: thumbnail
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.getNowPlaying = getNowPlaying;
|
module.exports.getNowPlaying = getNowPlaying;
|
||||||
module.exports.getNextSong = getNextSong;
|
module.exports.getNextSong = getNextSong;
|
||||||
module.exports.sendPlay = sendPlay;
|
module.exports.sendPlay = sendPlay;
|
||||||
|
|||||||
@@ -7,9 +7,16 @@ var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
|||||||
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.js");
|
||||||
var sort = require(pathThumbnails + "/handlers/dbFunctions/sort.js");
|
var sort = require(pathThumbnails + "/handlers/dbFunctions/sort.js");
|
||||||
|
|
||||||
|
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||||
|
var Play = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/play.js");
|
||||||
|
var changeSong = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/changeSong.js");
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
var conf = await aggregate(coll + "_settings", [
|
var _conf = await aggregate(coll + "_settings", [
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
id: "config"
|
id: "config"
|
||||||
@@ -32,7 +39,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
shuffle: true,
|
shuffle: true,
|
||||||
skip: false,
|
skip: false,
|
||||||
skips: [],
|
skips: [],
|
||||||
startTime: Functions.get_time(),
|
startTime: Helpers.get_time(),
|
||||||
views: [],
|
views: [],
|
||||||
vote: false,
|
vote: false,
|
||||||
description: "",
|
description: "",
|
||||||
@@ -88,7 +95,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
now_playing: true,
|
now_playing: true,
|
||||||
votes: 0,
|
votes: 0,
|
||||||
guids: [],
|
guids: [],
|
||||||
added: Functions.get_time()
|
added: Helpers.get_time()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -97,7 +104,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
{ id: "config" },
|
{ id: "config" },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
startTime: Functions.get_time(),
|
startTime: Helpers.get_time(),
|
||||||
skips: []
|
skips: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +143,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
);
|
);
|
||||||
sendList(coll, socket, send, list_send, configs, shuffled);
|
sendList(coll, socket, send, list_send, configs, shuffled);
|
||||||
} else {
|
} else {
|
||||||
if (Functions.get_time() - conf[0].startTime > np_docs[0].duration) {
|
if (Helpers.get_time() - conf[0].startTime > np_docs[0].duration) {
|
||||||
await changeSong(coll, false, np_docs[0].id, conf, socket);
|
await changeSong(coll, false, np_docs[0].id, conf, socket);
|
||||||
sendList(coll, socket, send, list_send, configs, shuffled);
|
sendList(coll, socket, send, list_send, configs, shuffled);
|
||||||
} else {
|
} else {
|
||||||
@@ -154,9 +161,9 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (socket === undefined && send) {
|
if (socket === undefined && send) {
|
||||||
sendPlay(coll);
|
Play.sendPlay(coll);
|
||||||
} else if (send) {
|
} else if (send) {
|
||||||
sendPlay(coll, socket);
|
Play.sendPlay(coll, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,9 +182,9 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (socket === undefined && send) {
|
if (socket === undefined && send) {
|
||||||
sendPlay(coll);
|
Play.sendPlay(coll);
|
||||||
} else if (send) {
|
} else if (send) {
|
||||||
sendPlay(coll, socket);
|
Play.sendPlay(coll, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configs) {
|
if (configs) {
|
||||||
@@ -199,7 +206,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
shuffle: true,
|
shuffle: true,
|
||||||
skip: false,
|
skip: false,
|
||||||
skips: [],
|
skips: [],
|
||||||
startTime: Functions.get_time(),
|
startTime: Helpers.get_time(),
|
||||||
views: [],
|
views: [],
|
||||||
vote: false,
|
vote: false,
|
||||||
desc: "",
|
desc: "",
|
||||||
@@ -218,4 +225,4 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.sendList = sendList;
|
module.exports = sendList;
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
var path = require("path");
|
|
||||||
var mongojs = require("mongojs");
|
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
|
||||||
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
var remove = require(pathThumbnails + "/handlers/dbFunctions/remove.js");
|
var remove = require(pathThumbnails + "/handlers/dbFunctions/remove.js");
|
||||||
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
|
||||||
async function setSessionAdminPass(id, adminpass, list) {
|
async function setSessionAdminPass(id, adminpass, list) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve();
|
resolve();
|
||||||
@@ -27,7 +24,7 @@ async function setSessionAdminPass(id, adminpass, list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setSessionChatPass(id, name, pass) {
|
async function setSessionChatPass(id, name, pass) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve();
|
resolve();
|
||||||
@@ -48,7 +45,7 @@ async function setSessionChatPass(id, name, pass) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getSessionChatPass(id) {
|
async function getSessionChatPass(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve({ name: "", pass: "", gotten: false });
|
resolve({ name: "", pass: "", gotten: false });
|
||||||
@@ -75,7 +72,7 @@ async function getSessionChatPass(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setChromecastHost(id, other_id, list) {
|
async function setChromecastHost(id, other_id, list) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
id == "empty" ||
|
id == "empty" ||
|
||||||
@@ -101,7 +98,7 @@ async function setChromecastHost(id, other_id, list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setSessionUserPass(id, userpass, list) {
|
async function setSessionUserPass(id, userpass, list) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (id == "empty" || id == undefined || userpass == undefined) {
|
if (id == "empty" || id == undefined || userpass == undefined) {
|
||||||
reject();
|
reject();
|
||||||
@@ -123,7 +120,7 @@ async function setSessionUserPass(id, userpass, list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getSessionAdminUser(id, list) {
|
async function getSessionAdminUser(id, list) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve({ userpass: "", adminpass: "", gotten: false });
|
resolve({ userpass: "", adminpass: "", gotten: false });
|
||||||
@@ -150,7 +147,7 @@ async function getSessionAdminUser(id, list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function removeSessionChatPass(id) {
|
async function removeSessionChatPass(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
@@ -162,7 +159,7 @@ async function removeSessionChatPass(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function removeSessionAdminPass(id, channel) {
|
async function removeSessionAdminPass(id, channel) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (id == "empty" || id == undefined) {
|
if (id == "empty" || id == undefined) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
@@ -172,40 +169,6 @@ async function removeSessionAdminPass(id, channel) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendColor(coll, socket, url, ajax, res) {
|
|
||||||
if (coll != undefined && typeof coll == "string") {
|
|
||||||
//coll = coll.replace(/ /g,'');
|
|
||||||
}
|
|
||||||
if (url.indexOf("://") == -1)
|
|
||||||
url = "https://img.youtube.com/vi/" + url + "/mqdefault.jpg";
|
|
||||||
//var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg';
|
|
||||||
|
|
||||||
Jimp.read(url)
|
|
||||||
.then(function(image) {
|
|
||||||
var c = ColorThief.getColor(image);
|
|
||||||
if (ajax) {
|
|
||||||
res.header({ "Content-Type": "application/json" });
|
|
||||||
res.status(200).send(c);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (socket) {
|
|
||||||
socket.emit("color", { color: c, only: true });
|
|
||||||
} else {
|
|
||||||
io.to(coll).emit("color", { color: c, only: false });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log("Crashed on fetching image, url is " + url);
|
|
||||||
console.log("Is ajax: " + ajax);
|
|
||||||
if (ajax) {
|
|
||||||
res.header({ "Content-Type": "application/json" });
|
|
||||||
res.status(404);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.setSessionAdminPass = setSessionAdminPass;
|
module.exports.setSessionAdminPass = setSessionAdminPass;
|
||||||
module.exports.setSessionChatPass = setSessionChatPass;
|
module.exports.setSessionChatPass = setSessionChatPass;
|
||||||
module.exports.getSessionChatPass = getSessionChatPass;
|
module.exports.getSessionChatPass = getSessionChatPass;
|
||||||
@@ -214,4 +177,3 @@ module.exports.setSessionUserPass = setSessionUserPass;
|
|||||||
module.exports.getSessionAdminUser = getSessionAdminUser;
|
module.exports.getSessionAdminUser = getSessionAdminUser;
|
||||||
module.exports.removeSessionChatPass = removeSessionChatPass;
|
module.exports.removeSessionChatPass = removeSessionChatPass;
|
||||||
module.exports.removeSessionAdminPass = removeSessionAdminPass;
|
module.exports.removeSessionAdminPass = removeSessionAdminPass;
|
||||||
module.exports.sendColor = sendColor;
|
|
||||||
@@ -4,6 +4,19 @@ var db = require(pathThumbnails + "/handlers/db.js");
|
|||||||
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
|
||||||
|
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
|
||||||
|
var SessionHandler = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/sessionHandler.js");
|
||||||
|
var Inlist = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/inlistCheck.js");
|
||||||
|
var Timeout = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/timeout.js");
|
||||||
|
var changeSong = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/changeSong.js");
|
||||||
|
var Play = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/play.js");
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
|
|
||||||
async function skip(list, guid, coll, offline, socket, callback) {
|
async function skip(list, guid, coll, offline, socket, callback) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
|
|
||||||
@@ -23,7 +36,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
try {
|
try {
|
||||||
coll = list.channel.toLowerCase(); //.replace(/ /g,'');
|
coll = list.channel.toLowerCase(); //.replace(/ /g,'');
|
||||||
if (coll.length == 0) return;
|
if (coll.length == 0) return;
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
coll = Helpers.removeEmojis(coll).toLowerCase();
|
||||||
//coll = coll.replace(/_/g, "");
|
//coll = coll.replace(/_/g, "");
|
||||||
|
|
||||||
//coll = filter.clean(coll);
|
//coll = filter.clean(coll);
|
||||||
@@ -63,18 +76,18 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list.id = list.id + "";
|
list.id = list.id + "";
|
||||||
var sessionAdminUser = await Functions.getSessionAdminUser(
|
var sessionAdminUser = await SessionHandler.getSessionAdminUser(
|
||||||
Functions.getSession(socket),
|
Helpers.getSession(socket),
|
||||||
coll
|
coll
|
||||||
);
|
);
|
||||||
var userpass = sessionAdminUser.userpass;
|
var userpass = sessionAdminUser.userpass;
|
||||||
var adminpass = sessionAdminUser.adminpass;
|
var adminpass = sessionAdminUser.adminpass;
|
||||||
var gotten = sessionAdminUser.gotten;
|
var gotten = sessionAdminUser.gotten;
|
||||||
if (adminpass != "" || list.pass == undefined) {
|
if (adminpass != "" || list.pass == undefined) {
|
||||||
list.pass = Functions.hash_pass(adminpass);
|
list.pass = Helpers.hash_pass(adminpass);
|
||||||
} else if (list.pass != "") {
|
} else if (list.pass != "") {
|
||||||
list.pass = Functions.hash_pass(
|
list.pass = Helpers.hash_pass(
|
||||||
Functions.hash_pass(Functions.decrypt_string(list.pass), true)
|
Helpers.hash_pass(Helpers.decrypt_string(list.pass), true)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
list.pass = "";
|
list.pass = "";
|
||||||
@@ -84,7 +97,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
} else {
|
} else {
|
||||||
list.userpass = crypto
|
list.userpass = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
.update(Functions.decrypt_string(list.userpass))
|
.update(Helpers.decrypt_string(list.userpass))
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,24 +108,27 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
docs[0].userpass == "" ||
|
docs[0].userpass == "" ||
|
||||||
(list.hasOwnProperty("userpass") && docs[0].userpass == list.userpass))
|
(list.hasOwnProperty("userpass") && docs[0].userpass == list.userpass))
|
||||||
) {
|
) {
|
||||||
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 12");
|
Inlist.check(coll, guid, socket, offline, undefined, "place 12");
|
||||||
|
|
||||||
var video_id;
|
var video_id;
|
||||||
adminpass = "";
|
adminpass = "";
|
||||||
video_id = list.id;
|
video_id = list.id;
|
||||||
var err = list.error;
|
var err = list.error;
|
||||||
var trueError = await Search.check_if_error_or_blocked(
|
var trueError = false;
|
||||||
video_id,
|
if (err) {
|
||||||
coll,
|
trueError = await Search.check_if_error_or_blocked(
|
||||||
err == "5" ||
|
video_id,
|
||||||
err == "100" ||
|
coll,
|
||||||
err == "101" ||
|
err == "5" ||
|
||||||
err == "150" ||
|
err == "100" ||
|
||||||
err == 5 ||
|
err == "101" ||
|
||||||
err == 100 ||
|
err == "150" ||
|
||||||
err == 101 ||
|
err == 5 ||
|
||||||
err == 150
|
err == 100 ||
|
||||||
);
|
err == 101 ||
|
||||||
|
err == 150
|
||||||
|
);
|
||||||
|
}
|
||||||
var error = false;
|
var error = false;
|
||||||
if (!trueError) {
|
if (!trueError) {
|
||||||
adminpass = list.pass;
|
adminpass = list.pass;
|
||||||
@@ -139,16 +155,17 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
docs[0].skips.length + 1 >= strictSkipNumber)) ||
|
docs[0].skips.length + 1 >= strictSkipNumber)) ||
|
||||||
(!strictSkip &&
|
(!strictSkip &&
|
||||||
((frontpage_viewers[0].viewers / 2 <= docs[0].skips.length + 1 &&
|
((frontpage_viewers[0].viewers / 2 <= docs[0].skips.length + 1 &&
|
||||||
!Functions.contains(docs[0].skips, guid) &&
|
!Helpers.contains(docs[0].skips, guid) &&
|
||||||
frontpage_viewers[0].viewers != 2) ||
|
frontpage_viewers[0].viewers != 2) ||
|
||||||
(frontpage_viewers[0].viewers == 2 &&
|
(frontpage_viewers[0].viewers == 2 &&
|
||||||
docs[0].skips.length + 1 == 2 &&
|
docs[0].skips.length + 1 == 2 &&
|
||||||
!Functions.contains(docs[0].skips, guid)) ||
|
!Helpers.contains(docs[0].skips, guid)) ||
|
||||||
(docs[0].adminpass == hash &&
|
(docs[0].adminpass == hash &&
|
||||||
docs[0].adminpass !== "" &&
|
docs[0].adminpass !== "" &&
|
||||||
docs[0].skip))))
|
docs[0].skip))))
|
||||||
) {
|
) {
|
||||||
var canContinue = await Functions.checkTimeout(
|
console.log("here");
|
||||||
|
var canContinue = await Timeout.check(
|
||||||
"skip",
|
"skip",
|
||||||
1,
|
1,
|
||||||
coll,
|
coll,
|
||||||
@@ -158,10 +175,19 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
socket,
|
socket,
|
||||||
"The channel is skipping too often, please wait "
|
"The channel is skipping too often, please wait "
|
||||||
);
|
);
|
||||||
|
console.log("canSkip", canContinue);
|
||||||
if (!canContinue) {
|
if (!canContinue) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
change_song(coll, error, video_id, docs);
|
|
||||||
|
try {
|
||||||
|
await changeSong(coll, error, video_id, docs);
|
||||||
|
} catch (e) {
|
||||||
|
socket.emit("toast", "Something went wrong.. Please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Play.sendPlay(coll);
|
||||||
socket.emit("toast", "skip");
|
socket.emit("toast", "skip");
|
||||||
var docs = await find("user_names", { guid: guid });
|
var docs = await find("user_names", { guid: guid });
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
@@ -176,7 +202,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
|
|||||||
msg: " skipped"
|
msg: " skipped"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (!Functions.contains(docs[0].skips, guid)) {
|
} else if (!Helpers.contains(docs[0].skips, guid)) {
|
||||||
await update(
|
await update(
|
||||||
coll + "_settings",
|
coll + "_settings",
|
||||||
{ id: "config" },
|
{ id: "config" },
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ var db = require(pathThumbnails + "/handlers/db.js");
|
|||||||
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
var create = require(pathThumbnails + "/handlers/dbFunctions/create.js");
|
var create = require(pathThumbnails + "/handlers/dbFunctions/create.js");
|
||||||
var insert = require(pathThumbnails + "/handlers/dbFunctions/insert.js");
|
var insert = require(pathThumbnails + "/handlers/dbFunctions/insert.js");
|
||||||
|
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
|
||||||
|
|
||||||
function checkTimeout(
|
function check(
|
||||||
type,
|
type,
|
||||||
timeout,
|
timeout,
|
||||||
channel,
|
channel,
|
||||||
@@ -15,13 +16,12 @@ function checkTimeout(
|
|||||||
socket,
|
socket,
|
||||||
error_message
|
error_message
|
||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (conf_pass != "" && conf_pass == this_pass) {
|
if (conf_pass != "" && conf_pass == this_pass) {
|
||||||
resolve();
|
resolve(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var docs = await find("timeout_api",
|
var docs = await find("timeout_api", {
|
||||||
{
|
|
||||||
type: type,
|
type: type,
|
||||||
guid: guid
|
guid: guid
|
||||||
});
|
});
|
||||||
@@ -32,12 +32,12 @@ function checkTimeout(
|
|||||||
|
|
||||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||||
if (retry_in > 0) {
|
if (retry_in > 0) {
|
||||||
if (typeof error_callback == "function") {
|
if (!error_message) {
|
||||||
reject();
|
resolve(false);
|
||||||
return;
|
return;
|
||||||
} else if (error_message) {
|
} else if (error_message) {
|
||||||
var sOrNot =
|
var sOrNot =
|
||||||
Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : "";
|
Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : "";
|
||||||
socket.emit(
|
socket.emit(
|
||||||
"toast",
|
"toast",
|
||||||
error_message + Math.ceil(retry_in) + " second" + sOrNot + "."
|
error_message + Math.ceil(retry_in) + " second" + sOrNot + "."
|
||||||
@@ -49,18 +49,20 @@ function checkTimeout(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var now_date = new Date();
|
var now_date = new Date();
|
||||||
await update("timeout_api",
|
await update(
|
||||||
{ type: type, guid: guid },
|
"timeout_api",
|
||||||
{
|
{ type: type, guid: guid },
|
||||||
$set: {
|
{
|
||||||
createdAt: now_date,
|
$set: {
|
||||||
type: type,
|
createdAt: now_date,
|
||||||
guid: guid
|
type: type,
|
||||||
}
|
guid: guid
|
||||||
},
|
}
|
||||||
{ upsert: true });
|
},
|
||||||
resolve();
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
resolve(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.checkTimeout = checkTimeout;
|
module.exports.check = check;
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
function aggregate(collection, aggregateObject) {
|
function aggregate(collection, aggregateObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(coll).aggregate(aggregateObject, function(error, results) {
|
db.collection(collection).aggregate(aggregateObject, function(
|
||||||
|
error,
|
||||||
|
results
|
||||||
|
) {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
@@ -14,4 +17,4 @@ function aggregate(collection, aggregateObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.aggregate = aggregate;
|
module.exports = aggregate;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
async function collection(collection) {
|
async function collection(collection) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.createCollection(coll, function(err, docs) {
|
db.createCollection(coll, function(err, docs) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -15,7 +15,7 @@ async function collection(collection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function index(collection, indexObject, extraObject) {
|
async function index(collection, indexObject, extraObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection).createIndex(indexObject, extraObject, function(
|
db.collection(collection).createIndex(indexObject, extraObject, function(
|
||||||
err,
|
err,
|
||||||
docs
|
docs
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
async function find(collection, searchObject) {
|
async function find(collection, searchObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection).find(searchObject, (error, result) => {
|
db.collection(collection).find(searchObject, (error, result) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
@@ -14,4 +14,4 @@ async function find(collection, searchObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.find = find;
|
module.exports = find;
|
||||||
|
|||||||
17
server/handlers/dbFunctions/findAndModify.js
Normal file
17
server/handlers/dbFunctions/findAndModify.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var mongojs = require("mongojs");
|
||||||
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
|
async function findAndModify(collection, query) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
db.collection(collection).findAndModify(query, function(err, docs) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(docs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = findAndModify;
|
||||||
@@ -3,7 +3,7 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
async function insert(collection, insertObject) {
|
async function insert(collection, insertObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection).insert(insertObject, function(err, docs) {
|
db.collection(collection).insert(insertObject, function(err, docs) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -14,4 +14,4 @@ async function insert(collection, insertObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.insert = insert;
|
module.exports = insert;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ var mongojs = require("mongojs");
|
|||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
function remove(collection, removeObject) {
|
function remove(collection, removeObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection).remove(removeObject, (error, result) => {
|
db.collection(collection).remove(removeObject, (error, result) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
@@ -14,4 +14,4 @@ function remove(collection, removeObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.remove = remove;
|
module.exports = remove;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ var path = require("path");
|
|||||||
var mongojs = require("mongojs");
|
var mongojs = require("mongojs");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
async function find(collection, searchObject, sortObject) {
|
async function sort(collection, searchObject, sortObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection)
|
db.collection(collection)
|
||||||
.find(searchObject)
|
.find(searchObject)
|
||||||
.sort(sortObject, (error, result) => {
|
.sort(sortObject, (error, result) => {
|
||||||
@@ -16,4 +16,4 @@ async function find(collection, searchObject, sortObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.find = find;
|
module.exports = sort;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ var path = require("path");
|
|||||||
var mongojs = require("mongojs");
|
var mongojs = require("mongojs");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
function update(collection, searchObject, updateObject, extraObject) {
|
async function update(collection, searchObject, updateObject, extraObject) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
db.collection(collection).update(
|
db.collection(collection).update(
|
||||||
searchObject,
|
searchObject,
|
||||||
updateObject,
|
updateObject,
|
||||||
@@ -19,4 +19,4 @@ function update(collection, searchObject, updateObject, extraObject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.update = update;
|
module.exports = update;
|
||||||
|
|||||||
174
server/handlers/helpers.js
Normal file
174
server/handlers/helpers.js
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
var crypto = require("crypto");
|
||||||
|
var ColorThief = require("color-thief-jimp");
|
||||||
|
var Jimp = require("jimp");
|
||||||
|
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
|
||||||
|
|
||||||
|
function encodeChannelName(str) {
|
||||||
|
var _fn = encodeURIComponent;
|
||||||
|
str = filter.clean(str);
|
||||||
|
var toReturn = _fn(str);
|
||||||
|
toReturn = toReturn.replace(/_/g, "%5F");
|
||||||
|
toReturn = toReturn.replace(/'/g, "%27");
|
||||||
|
toReturn = toReturn.replace(/%26amp%3B/g, "%26").replace(/%26amp%3b/g, "%26");
|
||||||
|
toReturn = toReturn.toLowerCase();
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeChannelName(str) {
|
||||||
|
var _fn = decodeURIComponent;
|
||||||
|
str = str.toUpperCase();
|
||||||
|
var toReturn = _fn(str.replace(/%5F/g, "_").replace(/%27/g, "'"));
|
||||||
|
toReturn = filter.clean(toReturn);
|
||||||
|
return toReturn.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function contains(a, obj) {
|
||||||
|
try {
|
||||||
|
var i = a.length;
|
||||||
|
while (i--) {
|
||||||
|
if (a[i] === obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSession(socket) {
|
||||||
|
try {
|
||||||
|
/*var cookieParser = require("cookie-parser");
|
||||||
|
var cookie = require("cookie");
|
||||||
|
var parsedCookies = cookie.parse(socket.handshake.headers.cookie);
|
||||||
|
return parsedCookies["_uI"];*/
|
||||||
|
if (socket.cookie_id == undefined) throw "Undefined error";
|
||||||
|
return socket.cookie_id;
|
||||||
|
} catch (e) {
|
||||||
|
// Returning "sessiong"-based on place of connection
|
||||||
|
return hash_pass(
|
||||||
|
socket.handshake.headers["user-agent"] +
|
||||||
|
socket.handshake.address +
|
||||||
|
socket.handshake.headers["accept-language"]
|
||||||
|
);
|
||||||
|
//return "empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hash_pass(adminpass, hex) {
|
||||||
|
if (adminpass == undefined || adminpass == "") return "";
|
||||||
|
if (hex)
|
||||||
|
return crypto
|
||||||
|
.createHash("sha256")
|
||||||
|
.update(adminpass)
|
||||||
|
.digest("hex");
|
||||||
|
return crypto
|
||||||
|
.createHash("sha256")
|
||||||
|
.update(adminpass)
|
||||||
|
.digest("base64");
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrypt_string(pw) {
|
||||||
|
try {
|
||||||
|
return Buffer.from(pw, "base64").toString("ascii");
|
||||||
|
} catch (e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeEmojis(string) {
|
||||||
|
//https://stackoverflow.com/a/41164278/4266467
|
||||||
|
var regex = /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g;
|
||||||
|
return string.replace(regex, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_time() {
|
||||||
|
var d = new Date();
|
||||||
|
var time = Math.floor(d.getTime() / 1000);
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendColor(coll, socket, url, ajax, res) {
|
||||||
|
if (coll != undefined && typeof coll == "string") {
|
||||||
|
//coll = coll.replace(/ /g,'');
|
||||||
|
}
|
||||||
|
if (url.indexOf("://") == -1)
|
||||||
|
url = "https://img.youtube.com/vi/" + url + "/mqdefault.jpg";
|
||||||
|
//var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg';
|
||||||
|
|
||||||
|
Jimp.read(url)
|
||||||
|
.then(function(image) {
|
||||||
|
var c = ColorThief.getColor(image);
|
||||||
|
if (ajax) {
|
||||||
|
res.header({ "Content-Type": "application/json" });
|
||||||
|
res.status(200).send(c);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (socket) {
|
||||||
|
socket.emit("color", { color: c, only: true });
|
||||||
|
} else {
|
||||||
|
io.to(coll).emit("color", { color: c, only: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log("Crashed on fetching image, url is " + url);
|
||||||
|
console.log("Is ajax: " + ajax);
|
||||||
|
if (ajax) {
|
||||||
|
res.header({ "Content-Type": "application/json" });
|
||||||
|
res.status(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rndName(seed, len) {
|
||||||
|
var vowels = ["a", "e", "i", "o", "u"];
|
||||||
|
consts = [
|
||||||
|
"b",
|
||||||
|
"c",
|
||||||
|
"d",
|
||||||
|
"f",
|
||||||
|
"g",
|
||||||
|
"h",
|
||||||
|
"j",
|
||||||
|
"k",
|
||||||
|
"l",
|
||||||
|
"m",
|
||||||
|
"n",
|
||||||
|
"p",
|
||||||
|
"r",
|
||||||
|
"s",
|
||||||
|
"t",
|
||||||
|
"v",
|
||||||
|
"w",
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
];
|
||||||
|
len = Math.floor(len);
|
||||||
|
word = "";
|
||||||
|
is_vowel = false;
|
||||||
|
var arr;
|
||||||
|
try {
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
if (is_vowel) arr = vowels;
|
||||||
|
else arr = consts;
|
||||||
|
is_vowel = !is_vowel;
|
||||||
|
word += arr[(seed[i % seed.length].charCodeAt() + i) % (arr.length - 1)];
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return rndName(uniqid.time().toLowerCase(), len);
|
||||||
|
}
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.rndName = rndName;
|
||||||
|
module.exports.contains = contains;
|
||||||
|
module.exports.sendColor = sendColor;
|
||||||
|
module.exports.encodeChannelName = encodeChannelName;
|
||||||
|
module.exports.decodeChannelName = decodeChannelName;
|
||||||
|
module.exports.getSession = getSession;
|
||||||
|
module.exports.hash_pass = hash_pass;
|
||||||
|
module.exports.decrypt_string = decrypt_string;
|
||||||
|
module.exports.removeEmojis = removeEmojis;
|
||||||
|
module.exports.get_time = get_time;
|
||||||
@@ -9,6 +9,10 @@ var Suggestions = require(pathThumbnails + "/handlers/suggestions.js");
|
|||||||
var ListSettings = require(pathThumbnails + "/handlers/list_settings.js");
|
var ListSettings = require(pathThumbnails + "/handlers/list_settings.js");
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
||||||
var Search = require(pathThumbnails + "/handlers/search.js");
|
var Search = require(pathThumbnails + "/handlers/search.js");
|
||||||
|
var Join = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/joinList.js");
|
||||||
|
var Skip = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/skip.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" });
|
||||||
@@ -187,24 +191,8 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("error_video", function(msg) {
|
socket.on("error_video", function(msg) {
|
||||||
try {
|
msg = middleware(msg);
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
coll = msg.channel;
|
||||||
var _list = msg.channel; //.replace(/ /g,'');
|
|
||||||
if (_list.length == 0) return;
|
|
||||||
if (_list.indexOf("?") > -1) {
|
|
||||||
_list = _list.substring(0, _list.indexOf("?"));
|
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
coll = Functions.removeEmojis(_list).toLowerCase();
|
|
||||||
//coll = coll.replace(/_/g, "");
|
|
||||||
|
|
||||||
//coll = filter.clean(coll);
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Search.check_error_video(msg, coll);
|
Search.check_error_video(msg, coll);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -240,57 +228,32 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("suggest_thumbnail", function(msg) {
|
socket.on("suggest_thumbnail", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Suggestions.thumbnail(msg, coll, guid, offline, socket);
|
Suggestions.thumbnail(msg, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("suggest_description", function(msg) {
|
socket.on("suggest_description", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Suggestions.description(msg, coll, guid, offline, socket);
|
Suggestions.description(msg, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("suggest_rules", function(msg) {
|
socket.on("suggest_rules", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Suggestions.rules(msg, coll, guid, offline, socket);
|
Suggestions.rules(msg, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("namechange", function(msg) {
|
socket.on("namechange", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Chat.namechange(msg, guid, socket);
|
Chat.namechange(msg, guid, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("removename", function(msg) {
|
socket.on("removename", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
if (typeof msg != "object" || !msg.hasOwnProperty("channel")) {
|
if (typeof msg != "object" || !msg.hasOwnProperty("channel")) {
|
||||||
var result = {
|
var result = {
|
||||||
channel: {
|
channel: {
|
||||||
@@ -305,13 +268,8 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("offline", function(msg) {
|
socket.on("offline", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!msg.hasOwnProperty("status") ||
|
!msg.hasOwnProperty("status") ||
|
||||||
!msg.hasOwnProperty("channel") ||
|
!msg.hasOwnProperty("channel") ||
|
||||||
@@ -408,13 +366,8 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("get_history", function(msg) {
|
socket.on("get_history", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!msg.hasOwnProperty("channel") ||
|
!msg.hasOwnProperty("channel") ||
|
||||||
!msg.hasOwnProperty("all") ||
|
!msg.hasOwnProperty("all") ||
|
||||||
@@ -442,46 +395,26 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("chat", function(msg) {
|
socket.on("chat", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Chat.chat(msg, guid, offline, socket);
|
Chat.chat(msg, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("all,chat", function(data) {
|
socket.on("all,chat", function(msg) {
|
||||||
if (data.hasOwnProperty("channel") && data.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = data.channel.substring(0, data.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
data.channel = _list;
|
Chat.all_chat(msg, guid, offline, socket);
|
||||||
}
|
|
||||||
if (data.hasOwnProperty("channel")) {
|
|
||||||
data.channel = Functions.encodeChannelName(data.channel);
|
|
||||||
}
|
|
||||||
Chat.all_chat(data, guid, offline, socket);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("frontpage_lists", function(msg) {
|
socket.on("frontpage_lists", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
Frontpage.frontpage_lists(msg, socket);
|
Frontpage.frontpage_lists(msg, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("import_zoff", function(msg) {
|
socket.on("import_zoff", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
ListChange.addFromOtherList(msg, guid, offline, socket);
|
ListChange.addFromOtherList(msg, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -489,42 +422,25 @@ module.exports = function() {
|
|||||||
List.now_playing(list, fn, socket);
|
List.now_playing(list, fn, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("id", function(arr) {
|
socket.on("id", function(msg) {
|
||||||
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
arr.channel = _list;
|
if (typeof msg == "object")
|
||||||
}
|
io.to(msg.id).emit(msg.id.toLowerCase(), {
|
||||||
if (arr.hasOwnProperty("channel")) {
|
type: msg.type,
|
||||||
arr.channel = Functions.encodeChannelName(arr.channel);
|
value: msg.value
|
||||||
}
|
|
||||||
if (typeof arr == "object")
|
|
||||||
io.to(arr.id).emit(arr.id.toLowerCase(), {
|
|
||||||
type: arr.type,
|
|
||||||
value: arr.value
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("join_silent", function(msg) {
|
socket.on("join_silent", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List.join_silent(msg, socket);
|
List.join_silent(msg, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list", function(msg) {
|
socket.on("list", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
//var _list = msg.channel.replace(/ /g,'');
|
//var _list = msg.channel.replace(/ /g,'');
|
||||||
var _list = msg.channel;
|
var _list = msg.channel;
|
||||||
@@ -544,7 +460,7 @@ module.exports = function() {
|
|||||||
if (msg.hasOwnProperty("offline") && msg.offline) {
|
if (msg.hasOwnProperty("offline") && msg.offline) {
|
||||||
offline = true;
|
offline = true;
|
||||||
}
|
}
|
||||||
List.list(msg, guid, coll, offline, socket);
|
Join.joinList(msg, guid, coll, offline, socket);
|
||||||
Functions.get_short_id(socket);
|
Functions.get_short_id(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -570,15 +486,10 @@ module.exports = function() {
|
|||||||
List.end(obj, coll, guid, offline, socket);
|
List.end(obj, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("addPlaylist", function(arr) {
|
socket.on("addPlaylist", function(msg) {
|
||||||
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
arr.channel = _list;
|
ListChange.addPlaylist(msg, guid, offline, socket);
|
||||||
}
|
|
||||||
if (arr.hasOwnProperty("channel")) {
|
|
||||||
arr.channel = Functions.encodeChannelName(arr.channel);
|
|
||||||
}
|
|
||||||
ListChange.addPlaylist(arr, guid, offline, socket);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("add", function(arr) {
|
socket.on("add", function(arr) {
|
||||||
@@ -612,13 +523,8 @@ module.exports = function() {
|
|||||||
|
|
||||||
socket.on("delete_all", function(msg) {
|
socket.on("delete_all", function(msg) {
|
||||||
try {
|
try {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
||||||
if (coll.length == 0) return;
|
if (coll.length == 0) return;
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||||
@@ -633,13 +539,8 @@ module.exports = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("vote", function(msg) {
|
socket.on("vote", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
if (coll !== undefined) {
|
if (coll !== undefined) {
|
||||||
try {
|
try {
|
||||||
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
||||||
@@ -655,53 +556,30 @@ module.exports = function() {
|
|||||||
ListChange.voteUndecided(msg, coll, guid, offline, socket);
|
ListChange.voteUndecided(msg, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("password", function(inp) {
|
socket.on("password", function(msg) {
|
||||||
if (inp.hasOwnProperty("channel") && inp.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = inp.channel.substring(0, inp.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
inp.channel = _list;
|
|
||||||
}
|
|
||||||
if (inp.hasOwnProperty("channel")) {
|
|
||||||
inp.channel = Functions.encodeChannelName(inp.channel);
|
|
||||||
}
|
|
||||||
//if(coll != undefined) coll.replace(/ /g,'');
|
//if(coll != undefined) coll.replace(/ /g,'');
|
||||||
ListSettings.password(inp, coll, guid, offline, socket);
|
ListSettings.password(msg, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("skip", function(list) {
|
socket.on("skip", function(msg) {
|
||||||
if (list.hasOwnProperty("channel") && list.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = list.channel.substring(0, list.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
list.channel = _list;
|
|
||||||
coll = list.channel;
|
|
||||||
}
|
|
||||||
if (list.hasOwnProperty("channel")) {
|
|
||||||
list.channel = Functions.encodeChannelName(list.channel);
|
|
||||||
}
|
|
||||||
//if(coll != undefined) coll.replace(/ /g,'');
|
//if(coll != undefined) coll.replace(/ /g,'');
|
||||||
List.skip(list, guid, coll, offline, socket);
|
Skip.skip(msg, guid, coll, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("conf", function(conf) {
|
socket.on("conf", function(msg) {
|
||||||
if (conf.hasOwnProperty("channel") && conf.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = conf.channel.substring(0, conf.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
conf.channel = _list;
|
|
||||||
coll = conf.channel;
|
|
||||||
}
|
|
||||||
if (conf.hasOwnProperty("channel")) {
|
|
||||||
conf.channel = Functions.encodeChannelName(conf.channel);
|
|
||||||
coll = conf.channel;
|
|
||||||
}
|
|
||||||
//if(coll != undefined) coll.replace(/ /g,'');
|
//if(coll != undefined) coll.replace(/ /g,'');
|
||||||
ListSettings.conf_function(conf, coll, guid, offline, socket);
|
ListSettings.conf_function(conf, coll, guid, offline, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("shuffle", function(msg) {
|
socket.on("shuffle", function(msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
msg = middleware(msg);
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
coll = msg.channel;
|
||||||
msg.channel = _list;
|
|
||||||
}
|
|
||||||
if (msg.hasOwnProperty("channel")) {
|
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
||||||
if (coll.length == 0) return;
|
if (coll.length == 0) return;
|
||||||
@@ -933,6 +811,17 @@ module.exports = function() {
|
|||||||
//send_ping();
|
//send_ping();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function middleware(msg) {
|
||||||
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
|
var _list = list.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
|
msg.channel = _list;
|
||||||
|
}
|
||||||
|
if (msg.hasOwnProperty("channel")) {
|
||||||
|
msg.channel = Functions.encodeChannelName(msg.channel);
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function send_ping() {
|
function send_ping() {
|
||||||
db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){
|
db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
var ColorThief = require("color-thief-jimp");
|
var ColorThief = require("color-thief-jimp");
|
||||||
var Jimp = require("jimp");
|
var Jimp = require("jimp");
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||||
|
|
||||||
|
var AdvancedFunctions = require(pathThumbnails +
|
||||||
|
"/handlers/dbFunctions/advancedFunctions/joinList.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");
|
||||||
@@ -33,216 +36,46 @@ function now_playing(list, fn, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function join_silent(msg, socket) {
|
function join_silent(msg, socket) {
|
||||||
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
||||||
var channelName = msg.channel;
|
var channelName = msg.channel;
|
||||||
var tryingPassword = false;
|
var tryingPassword = false;
|
||||||
var password = "";
|
var password = "";
|
||||||
if(msg.password != "") {
|
if (msg.password != "") {
|
||||||
tryingPassword = true;
|
tryingPassword = true;
|
||||||
password = Functions.decrypt_string(msg.password);
|
password = Functions.decrypt_string(msg.password);
|
||||||
password = crypto
|
password = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
.update(password)
|
.update(password)
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
|
||||||
|
|
||||||
channelName = channelName.toLowerCase(); //.replace(/ /g,'');
|
|
||||||
channelName = Functions.removeEmojis(channelName).toLowerCase();
|
|
||||||
db.collection(channelName + "_settings").find(function(err, docs) {
|
|
||||||
if(docs.length == 0) {
|
|
||||||
socket.emit("join_silent_declined", "");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(docs[0].userpass == "" || docs[0].userpass == undefined || docs[0].userpass == password) {
|
|
||||||
socket.join(channelName);
|
|
||||||
socket.emit("join_silent_accepted", "");
|
|
||||||
|
|
||||||
send_play(channelName, socket);
|
|
||||||
} else {
|
|
||||||
socket.emit("join_silent_declined", "");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channelName = channelName.toLowerCase(); //.replace(/ /g,'');
|
||||||
|
channelName = Functions.removeEmojis(channelName).toLowerCase();
|
||||||
|
db.collection(channelName + "_settings").find(function(err, docs) {
|
||||||
|
if (docs.length == 0) {
|
||||||
|
socket.emit("join_silent_declined", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
docs[0].userpass == "" ||
|
||||||
|
docs[0].userpass == undefined ||
|
||||||
|
docs[0].userpass == password
|
||||||
|
) {
|
||||||
|
socket.join(channelName);
|
||||||
|
socket.emit("join_silent_accepted", "");
|
||||||
|
|
||||||
|
send_play(channelName, socket);
|
||||||
|
} else {
|
||||||
|
socket.emit("join_silent_declined", "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function list(msg, guid, coll, offline, socket) {
|
function list(msg, guid, coll, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
AdvancedFunctions.joinList(msg, guid, coll, offline, socket);
|
||||||
if (typeof msg === "object" && msg !== undefined && msg !== null) {
|
|
||||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
|
|
||||||
userpass,
|
|
||||||
adminpass,
|
|
||||||
gotten
|
|
||||||
) {
|
|
||||||
if (gotten && userpass != "" && !msg.hasOwnProperty("pass")) {
|
|
||||||
msg.pass = userpass;
|
|
||||||
} else {
|
|
||||||
msg.pass = crypto
|
|
||||||
.createHash("sha256")
|
|
||||||
.update(Functions.decrypt_string(msg.pass))
|
|
||||||
.digest("base64");
|
|
||||||
}
|
|
||||||
adminpass = Functions.hash_pass(adminpass);
|
|
||||||
if (
|
|
||||||
!msg.hasOwnProperty("version") ||
|
|
||||||
!msg.hasOwnProperty("channel") ||
|
|
||||||
msg.version != VERSION ||
|
|
||||||
msg.version == undefined ||
|
|
||||||
typeof msg.channel != "string"
|
|
||||||
) {
|
|
||||||
var result = {
|
|
||||||
channel: {
|
|
||||||
expected: "string",
|
|
||||||
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
|
||||||
},
|
|
||||||
version: {
|
|
||||||
expected: VERSION,
|
|
||||||
got: msg.version
|
|
||||||
},
|
|
||||||
pass: {
|
|
||||||
expected: "string",
|
|
||||||
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
|
|
||||||
}
|
|
||||||
};
|
|
||||||
socket.emit("update_required", result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
|
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
|
||||||
//coll = filter.clean(coll);
|
|
||||||
var pass = msg.pass;
|
|
||||||
db.collection("frontpage_lists").find({ _id: coll }, function(
|
|
||||||
err,
|
|
||||||
frontpage_lists
|
|
||||||
) {
|
|
||||||
if (frontpage_lists.length == 1) {
|
|
||||||
db.collection(coll + "_settings").find(function(err, docs) {
|
|
||||||
if (
|
|
||||||
docs.length == 0 ||
|
|
||||||
(docs.length > 0 &&
|
|
||||||
(docs[0].userpass == undefined ||
|
|
||||||
docs[0].userpass == "" ||
|
|
||||||
docs[0].userpass == pass))
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
docs.length > 0 &&
|
|
||||||
docs[0].hasOwnProperty("userpass") &&
|
|
||||||
docs[0].userpass != "" &&
|
|
||||||
docs[0].userpass == pass
|
|
||||||
) {
|
|
||||||
Functions.setSessionUserPass(
|
|
||||||
Functions.getSession(socket),
|
|
||||||
msg.pass,
|
|
||||||
coll,
|
|
||||||
function() {}
|
|
||||||
);
|
|
||||||
socket.emit("auth_accepted", { value: true });
|
|
||||||
}
|
|
||||||
if (docs.length > 0 && docs[0].userpass != pass) {
|
|
||||||
Functions.setSessionUserPass(
|
|
||||||
Functions.getSession(socket),
|
|
||||||
"",
|
|
||||||
coll,
|
|
||||||
function() {}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
docs.length > 0 &&
|
|
||||||
docs[0].hasOwnProperty("adminpass") &&
|
|
||||||
docs[0].adminpass != "" &&
|
|
||||||
docs[0].adminpass == adminpass
|
|
||||||
) {
|
|
||||||
socket.emit("pw", true);
|
|
||||||
}
|
|
||||||
in_list = true;
|
|
||||||
socket.join(coll);
|
|
||||||
Functions.check_inlist(
|
|
||||||
coll,
|
|
||||||
guid,
|
|
||||||
socket,
|
|
||||||
offline,
|
|
||||||
undefined,
|
|
||||||
"place 10"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (frontpage_lists[0].viewers != undefined) {
|
|
||||||
io.to(coll).emit("viewers", frontpage_lists[0].viewers);
|
|
||||||
} else {
|
|
||||||
io.to(coll).emit("viewers", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
send_list(coll, socket, true, false, true);
|
|
||||||
} else {
|
|
||||||
socket.emit("auth_required");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
db.createCollection(coll, function(err, docs) {
|
|
||||||
db.collection(coll).createIndex(
|
|
||||||
{ id: 1 },
|
|
||||||
{ unique: true },
|
|
||||||
function(e, d) {
|
|
||||||
var configs = {
|
|
||||||
addsongs: false,
|
|
||||||
adminpass: "",
|
|
||||||
allvideos: true,
|
|
||||||
frontpage: true,
|
|
||||||
longsongs: false,
|
|
||||||
removeplay: false,
|
|
||||||
shuffle: true,
|
|
||||||
skip: false,
|
|
||||||
skips: [],
|
|
||||||
startTime: Functions.get_time(),
|
|
||||||
views: [],
|
|
||||||
vote: false,
|
|
||||||
description: "",
|
|
||||||
thumbnail: "",
|
|
||||||
rules: "",
|
|
||||||
userpass: "",
|
|
||||||
id: "config",
|
|
||||||
toggleChat: true
|
|
||||||
};
|
|
||||||
db.collection(coll + "_settings").insert(configs, function(
|
|
||||||
err,
|
|
||||||
docs
|
|
||||||
) {
|
|
||||||
socket.join(coll);
|
|
||||||
send_list(coll, socket, true, false, true);
|
|
||||||
db.collection("frontpage_lists").insert(
|
|
||||||
{
|
|
||||||
_id: coll,
|
|
||||||
count: 0,
|
|
||||||
frontpage: true,
|
|
||||||
accessed: Functions.get_time(),
|
|
||||||
viewers: 1
|
|
||||||
},
|
|
||||||
function(e, d) {}
|
|
||||||
);
|
|
||||||
Functions.check_inlist(
|
|
||||||
coll,
|
|
||||||
guid,
|
|
||||||
socket,
|
|
||||||
offline,
|
|
||||||
undefined,
|
|
||||||
"place 11"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var result = {
|
|
||||||
msg: {
|
|
||||||
expected: "object",
|
|
||||||
got: typeof msg
|
|
||||||
}
|
|
||||||
};
|
|
||||||
socket.emit("update_required", result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function skip(list, guid, coll, offline, socket, callback) {
|
function skip(list, guid, coll, offline, socket, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user