More intermediary work

This commit is contained in:
Kasper Rynning-Tønnesen
2019-10-08 15:52:55 +02:00
parent c6382c0af1
commit cb712d9555
23 changed files with 1299 additions and 706 deletions

View File

@@ -1,9 +1,12 @@
var path = require("path");
var db = require(pathThumbnails + "/handlers/db.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 Helpers = require(pathThumbnails + "/handlers/helpers.js");
var frontpage = require(pathThumbnails +
"/handlers/dbFunctions/frontpageUpdates.js");
"/handlers/dbFunctions/advancedFunctions/frontpageUpdates.js");
var findAggregate = [
{
$match: {
@@ -49,12 +52,14 @@ var verifyAggregate = [
}
];
var sIO = require(pathThumbnails + "/apps/client.js").socketIO;
async function changeSong(coll, error, id, conf, socket) {
console.log("hello");
return 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;
if (conf === null || conf.length == 0) {
return;
@@ -72,13 +77,12 @@ async function pre(coll, error, id, conf, socket) {
next_song = now_playing_doc[1].id;
}
await post(coll, next_song, conf, socket, error);
/*if (!callback) {
io.to(coll).emit("channel", {
type: "deleted",
value: now_playing_doc[0].id,
removed: true
});
}*/
io.to(coll).emit("channel", {
type: "deleted",
value: now_playing_doc[0].id,
removed: true
});
if (docs.deletedCount == 1) {
frontpage.incrementList("frontpage_lists", -1);
}
@@ -95,9 +99,10 @@ async function pre(coll, error, id, conf, socket) {
resolve();
return;
} else {
console.log("here 2");
if (
(conf[0].skipped_time != undefined &&
conf[0].skipped_time != Functions.get_time()) ||
conf[0].skipped_time != Helpers.get_time()) ||
conf[0].skipped_time == undefined
) {
var docs = await update(
@@ -112,6 +117,7 @@ async function pre(coll, error, id, conf, socket) {
},
{ multi: true }
);
console.log("update", docs);
var next_song;
if (now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
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) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
var docs = await aggregate(coll, verifyAggregate);
if (docs === null || docs.length == 0) {
reject();
@@ -163,7 +169,7 @@ async function post(coll, next_song, conf, socket, removed) {
now_playing: true,
votes: 0,
guids: [],
added: Functions.get_time()
added: Helpers.get_time()
}
},
{}
@@ -175,12 +181,18 @@ async function post(coll, next_song, conf, socket, removed) {
resolve();
return;
}
io.to(coll).emit("channel", {
type: "song_change",
time: Helpers.get_time(),
remove: conf[0].removeplay || removed,
id: id
});
returnDocs = await update(
coll + "_settings",
{ id: "config" },
{
$set: {
startTime: Functions.get_time(),
startTime: Helpers.get_time(),
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.post = post;

View 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;

View File

@@ -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) {
var socketid = socket.zoff_id;
if (typeof obj !== "object") {
@@ -45,9 +54,12 @@ async function end(obj, coll, guid, offline, socket) {
docs.length > 0 &&
(docs[0].userpass != undefined && docs[0].userpass != "")
) {
callback_function = Functions.getSessionAdminUser;
callback_function = SessionHandler.getSessionAdminUser;
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;
}
@@ -55,52 +67,44 @@ async function end(obj, coll, guid, offline, socket) {
obj.pass = userpass;
} else {
obj.pass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(obj.pass))
.digest("base64");
.createHash("sha256")
.update(Helpers.decrypt_string(obj.pass))
.digest("base64");
}
if (
!authentication_needed ||
(authentication_needed &&
obj.hasOwnProperty("pass") &&
docs[0].userpass == obj.pass)
) {
Functions.check_inlist(
coll,
guid,
socket,
offline,
undefined,
"place 13"
);
var np = await find(coll, { now_playing: true });
if (err !== null) console.log(err);
if (
np !== null &&
np !== undefined &&
np.length == 1 &&
np[0].id == id
) {
var startTime = docs[0].startTime;
if (
startTime + parseInt(np[0].duration) <=
Functions.get_time() + 5
) {
changeSong(coll, false, id, docs);
}
) {
Functions.check_inlist(
coll,
guid,
socket,
offline,
undefined,
"place 13"
);
var np = await find(coll, { now_playing: true });
if (err !== null) console.log(err);
if (np !== null && np !== undefined && np.length == 1 && np[0].id == id) {
var startTime = docs[0].startTime;
if (startTime + parseInt(np[0].duration) <= Helpers.get_time() + 5) {
changeSong(coll, false, id, docs);
}
} else {
socket.emit("auth_required");
}
} else {
var result = {
msg: {
expected: "object",
got: typeof obj
}
};
socket.emit("update_required", result);
socket.emit("auth_required");
}
} else {
var result = {
msg: {
expected: "object",
got: typeof obj
}
};
socket.emit("update_required", result);
}
}
module.exports.end = end;
module.exports.end = end;

View 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;

View File

@@ -3,16 +3,49 @@ var mongojs = require("mongojs");
var db = require(pathThumbnails + "/handlers/db.js");
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
var Helpers = require(pathThumbnails + "/handlers/helpers.js");
async function incrementList(collection, way) {
return update(
collection,
{ _id: coll, count: { $gt: 0 } },
{
$inc: { count: way },
$set: { accessed: Functions.get_time() }
$set: { accessed: Helpers.get_time() }
},
{ 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;

View 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;

View File

@@ -5,6 +5,19 @@ var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
var create = require(pathThumbnails + "/handlers/dbFunctions/create.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) {
if (typeof msg === "object" && msg !== undefined && msg !== null) {
var channelName = msg.channel;
@@ -12,7 +25,7 @@ async function joinSilent(msg, socket) {
var password = "";
if (msg.password != "") {
tryingPassword = true;
password = Functions.decrypt_string(msg.password);
password = Helpers.decrypt_string(msg.password);
password = crypto
.createHash("sha256")
.update(password)
@@ -20,7 +33,7 @@ async function joinSilent(msg, socket) {
}
channelName = channelName.toLowerCase(); //.replace(/ /g,'');
channelName = Functions.removeEmojis(channelName).toLowerCase();
channelName = Helpers.removeEmojis(channelName).toLowerCase();
var docs = await find(channelName + "_settings");
if (docs.length == 0) {
socket.emit("join_silent_declined", "");
@@ -34,7 +47,7 @@ async function joinSilent(msg, socket) {
socket.join(channelName);
socket.emit("join_silent_accepted", "");
send_play(channelName, socket);
Play.sendPlay(channelName, socket);
} else {
socket.emit("join_silent_declined", "");
}
@@ -46,8 +59,8 @@ async function joinSilent(msg, socket) {
async function joinList(msg, guid, coll, offline, socket) {
var socketid = socket.zoff_id;
if (typeof msg === "object" && msg !== undefined && msg !== null) {
var sessionAdminUser = await Functions.getSessionAdminUser(
Functions.getSession(socket),
var sessionAdminUser = await SessionHandler.getSessionAdminUser(
Helpers.getSession(socket),
coll
);
var userpass = sessionAdminUser.userpass;
@@ -58,10 +71,10 @@ async function joinList(msg, guid, coll, offline, socket) {
} else {
msg.pass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(msg.pass))
.update(Helpers.decrypt_string(msg.pass))
.digest("base64");
}
adminpass = Functions.hash_pass(adminpass);
adminpass = Helpers.hash_pass(adminpass);
if (
!msg.hasOwnProperty("version") ||
!msg.hasOwnProperty("channel") ||
@@ -87,7 +100,7 @@ async function joinList(msg, guid, coll, offline, socket) {
return;
}
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = Helpers.removeEmojis(coll).toLowerCase();
//coll = filter.clean(coll);
var pass = msg.pass;
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 == pass
) {
Functions.setSessionUserPass(
Functions.getSession(socket),
SessionHandler.setSessionUserPass(
Helpers.getSession(socket),
msg.pass,
coll
);
socket.emit("auth_accepted", { value: true });
}
if (docs.length > 0 && docs[0].userpass != pass) {
Functions.setSessionUserPass(Functions.getSession(socket), "", coll);
SessionHandler.setSessionUserPass(
Helpers.getSession(socket),
"",
coll
);
}
if (
docs.length > 0 &&
@@ -126,14 +143,7 @@ async function joinList(msg, guid, coll, offline, socket) {
}
in_list = true;
socket.join(coll);
Functions.check_inlist(
coll,
guid,
socket,
offline,
undefined,
"place 10"
);
Inlist.check(coll, guid, socket, offline, undefined, "place 10");
if (frontpage_lists[0].viewers != undefined) {
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);
}
send_list(coll, socket, true, false, true);
sendList(coll, socket, true, false, true);
} else {
socket.emit("auth_required");
}
@@ -159,7 +169,7 @@ async function joinList(msg, guid, coll, offline, socket) {
shuffle: true,
skip: false,
skips: [],
startTime: Functions.get_time(),
startTime: Helpers.get_time(),
views: [],
vote: false,
description: "",
@@ -171,22 +181,15 @@ async function joinList(msg, guid, coll, offline, socket) {
};
await insert(coll + "_settings", configs);
socket.join(coll);
send_list(coll, socket, true, false, true);
sendList(coll, socket, true, false, true);
insert("frontpage_lists", {
_id: coll,
count: 0,
frontpage: true,
accessed: Functions.get_time(),
accessed: Helpers.get_time(),
viewers: 1
});
Functions.check_inlist(
coll,
guid,
socket,
offline,
undefined,
"place 11"
);
Inlist.check(coll, guid, socket, offline, undefined, "place 11");
}
} else {
var result = {

View File

@@ -2,127 +2,130 @@ 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");
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) {
return new Promise((resolve, reject) => {
if (typeof list !== "string" || typeof fn !== "function") {
socket.emit("update_required");
return;
}
var docs = await find(list, { now_playing: true });
if (docs.length === 0) {
resolve("No song currently playing");
return;
}
var title = docs[0].title;
if (title === undefined) resolve("No song currently playing");
else resolve(title);
});
return new Promise(async (resolve, reject) => {
if (typeof list !== "string" || typeof fn !== "function") {
socket.emit("update_required");
return;
}
var docs = await find(list, { now_playing: true });
if (docs.length === 0) {
resolve("No song currently playing");
return;
}
var title = docs[0].title;
if (title === undefined) resolve("No song currently playing");
else resolve(title);
});
}
async function sendPlay(coll, socket, broadcast) {
//coll = coll.replace(/ /g,'');
var np = await find(coll, { now_playing: true });
var conf = await find(coll + "_settings");
if (err !== null) console.log(err);
try {
if (Functions.get_time() - conf[0].startTime > np[0].duration) {
changeSong(coll, false, np[0].id, conf);
} else if (conf !== null && conf !== undefined && conf.length !== 0) {
if (conf[0].adminpass !== "") conf[0].adminpass = true;
if (conf[0].hasOwnProperty("userpass") && conf[0].userpass != "")
conf[0].userpass = true;
else conf[0].userpass = false;
if (!np.hasOwnProperty("start")) np.start = 0;
if (!np.hasOwnProperty("end")) np.end = np.duration;
toSend = { np: np, conf: conf, time: Functions.get_time() };
if (socket === undefined) {
io.to(coll).emit("np", toSend);
//
getNextSong(coll, undefined);
var url =
"https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
if (np[0].source == "soundcloud") url = np[0].thumbnail;
sendColor(coll, false, url);
} else {
var url =
"https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
if (np[0].source == "soundcloud") url = np[0].thumbnail;
sendColor(coll, socket, url);
if (broadcast) {
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", {});
//coll = coll.replace(/ /g,'');
var np = await find(coll, { now_playing: true });
var conf = await find(coll + "_settings");
console.log(np);
try {
if (Helpers.get_time() - conf[0].startTime > np[0].duration) {
changeSong(coll, false, np[0].id, conf);
} else if (conf !== null && conf !== undefined && conf.length !== 0) {
if (conf[0].adminpass !== "") conf[0].adminpass = true;
if (conf[0].hasOwnProperty("userpass") && conf[0].userpass != "")
conf[0].userpass = true;
else conf[0].userpass = false;
if (!np.hasOwnProperty("start")) np.start = 0;
if (!np.hasOwnProperty("end")) np.end = np.duration;
toSend = { np: np, conf: conf, time: Helpers.get_time() };
if (socket === undefined) {
io.to(coll).emit("np", toSend);
//
getNextSong(coll, undefined);
var url = "https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
if (np[0].source == "soundcloud") url = np[0].thumbnail;
Helpers.sendColor(coll, false, url);
} else {
var url = "https://img.youtube.com/vi/" + np[0].id + "/mqdefault.jpg";
if (np[0].source == "soundcloud") url = np[0].thumbnail;
Helpers.sendColor(coll, socket, url);
if (broadcast) {
socket.to(coll).emit("np", toSend);
return;
}
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) {
//coll = coll.replace(/ /g,'');
return new Promise((resolve, reject) => {
var docs = await aggregate(coll,
[
{
$match: {
views: {
$exists: false
},
type: {
$ne: "suggested"
}
}
},
{
$sort: {
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();
//coll = coll.replace(/ /g,'');
return new Promise(async (resolve, reject) => {
var doc = await aggregate(coll, nextSongAggregate);
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();
});
}
module.exports.getNowPlaying = getNowPlaying;
module.exports.getNextSong = getNextSong;
module.exports.sendPlay = sendPlay;
module.exports.getNowPlaying = getNowPlaying;
module.exports.getNextSong = getNextSong;
module.exports.sendPlay = sendPlay;

View File

@@ -7,9 +7,16 @@ var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
var aggregate = require(pathThumbnails + "/handlers/dbFunctions/aggregate.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) {
//coll = coll.replace(/ /g,'');
var conf = await aggregate(coll + "_settings", [
var _conf = await aggregate(coll + "_settings", [
{
$match: {
id: "config"
@@ -32,7 +39,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
shuffle: true,
skip: false,
skips: [],
startTime: Functions.get_time(),
startTime: Helpers.get_time(),
views: [],
vote: false,
description: "",
@@ -88,7 +95,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
now_playing: true,
votes: 0,
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" },
{
$set: {
startTime: Functions.get_time(),
startTime: Helpers.get_time(),
skips: []
}
}
@@ -136,7 +143,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
);
sendList(coll, socket, send, list_send, configs, shuffled);
} 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);
sendList(coll, socket, send, list_send, configs, shuffled);
} else {
@@ -154,9 +161,9 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
});
}
if (socket === undefined && send) {
sendPlay(coll);
Play.sendPlay(coll);
} 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) {
sendPlay(coll);
Play.sendPlay(coll);
} else if (send) {
sendPlay(coll, socket);
Play.sendPlay(coll, socket);
}
}
if (configs) {
@@ -199,7 +206,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
shuffle: true,
skip: false,
skips: [],
startTime: Functions.get_time(),
startTime: Helpers.get_time(),
views: [],
vote: false,
desc: "",
@@ -218,4 +225,4 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
}
}
module.exports.sendList = sendList;
module.exports = sendList;

View File

@@ -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 remove = require(pathThumbnails + "/handlers/dbFunctions/remove.js");
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
async function setSessionAdminPass(id, adminpass, list) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (id == "empty" || id == undefined) {
resolve();
@@ -27,7 +24,7 @@ async function setSessionAdminPass(id, adminpass, list) {
}
async function setSessionChatPass(id, name, pass) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (id == "empty" || id == undefined) {
resolve();
@@ -48,7 +45,7 @@ async function setSessionChatPass(id, name, pass) {
}
async function getSessionChatPass(id) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (id == "empty" || id == undefined) {
resolve({ name: "", pass: "", gotten: false });
@@ -75,7 +72,7 @@ async function getSessionChatPass(id) {
}
async function setChromecastHost(id, other_id, list) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (
id == "empty" ||
@@ -101,7 +98,7 @@ async function setChromecastHost(id, other_id, list) {
}
async function setSessionUserPass(id, userpass, list) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (id == "empty" || id == undefined || userpass == undefined) {
reject();
@@ -123,7 +120,7 @@ async function setSessionUserPass(id, userpass, list) {
}
async function getSessionAdminUser(id, list) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
if (id == "empty" || id == undefined) {
resolve({ userpass: "", adminpass: "", gotten: false });
@@ -150,7 +147,7 @@ async function getSessionAdminUser(id, list) {
}
async function removeSessionChatPass(id) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (id == "empty" || id == undefined) {
resolve();
return;
@@ -162,7 +159,7 @@ async function removeSessionChatPass(id) {
}
async function removeSessionAdminPass(id, channel) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (id == "empty" || id == undefined) {
resolve();
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.setSessionChatPass = setSessionChatPass;
module.exports.getSessionChatPass = getSessionChatPass;
@@ -214,4 +177,3 @@ module.exports.setSessionUserPass = setSessionUserPass;
module.exports.getSessionAdminUser = getSessionAdminUser;
module.exports.removeSessionChatPass = removeSessionChatPass;
module.exports.removeSessionAdminPass = removeSessionAdminPass;
module.exports.sendColor = sendColor;

View File

@@ -4,6 +4,19 @@ var db = require(pathThumbnails + "/handlers/db.js");
var find = require(pathThumbnails + "/handlers/dbFunctions/find.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) {
var socketid = socket.zoff_id;
@@ -23,7 +36,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
try {
coll = list.channel.toLowerCase(); //.replace(/ /g,'');
if (coll.length == 0) return;
coll = Functions.removeEmojis(coll).toLowerCase();
coll = Helpers.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
//coll = filter.clean(coll);
@@ -63,18 +76,18 @@ async function skip(list, guid, coll, offline, socket, callback) {
return;
}
list.id = list.id + "";
var sessionAdminUser = await Functions.getSessionAdminUser(
Functions.getSession(socket),
var sessionAdminUser = await SessionHandler.getSessionAdminUser(
Helpers.getSession(socket),
coll
);
var userpass = sessionAdminUser.userpass;
var adminpass = sessionAdminUser.adminpass;
var gotten = sessionAdminUser.gotten;
if (adminpass != "" || list.pass == undefined) {
list.pass = Functions.hash_pass(adminpass);
list.pass = Helpers.hash_pass(adminpass);
} else if (list.pass != "") {
list.pass = Functions.hash_pass(
Functions.hash_pass(Functions.decrypt_string(list.pass), true)
list.pass = Helpers.hash_pass(
Helpers.hash_pass(Helpers.decrypt_string(list.pass), true)
);
} else {
list.pass = "";
@@ -84,7 +97,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
} else {
list.userpass = crypto
.createHash("sha256")
.update(Functions.decrypt_string(list.userpass))
.update(Helpers.decrypt_string(list.userpass))
.digest("base64");
}
@@ -95,24 +108,27 @@ async function skip(list, guid, coll, offline, socket, callback) {
docs[0].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;
adminpass = "";
video_id = list.id;
var err = list.error;
var trueError = await Search.check_if_error_or_blocked(
video_id,
coll,
err == "5" ||
err == "100" ||
err == "101" ||
err == "150" ||
err == 5 ||
err == 100 ||
err == 101 ||
err == 150
);
var trueError = false;
if (err) {
trueError = await Search.check_if_error_or_blocked(
video_id,
coll,
err == "5" ||
err == "100" ||
err == "101" ||
err == "150" ||
err == 5 ||
err == 100 ||
err == 101 ||
err == 150
);
}
var error = false;
if (!trueError) {
adminpass = list.pass;
@@ -139,16 +155,17 @@ async function skip(list, guid, coll, offline, socket, callback) {
docs[0].skips.length + 1 >= strictSkipNumber)) ||
(!strictSkip &&
((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 &&
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 !== "" &&
docs[0].skip))))
) {
var canContinue = await Functions.checkTimeout(
console.log("here");
var canContinue = await Timeout.check(
"skip",
1,
coll,
@@ -158,10 +175,19 @@ async function skip(list, guid, coll, offline, socket, callback) {
socket,
"The channel is skipping too often, please wait "
);
console.log("canSkip", canContinue);
if (!canContinue) {
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");
var docs = await find("user_names", { guid: guid });
if (docs.length == 1) {
@@ -176,7 +202,7 @@ async function skip(list, guid, coll, offline, socket, callback) {
msg: " skipped"
});
}
} else if (!Functions.contains(docs[0].skips, guid)) {
} else if (!Helpers.contains(docs[0].skips, guid)) {
await update(
coll + "_settings",
{ id: "config" },

View File

@@ -4,8 +4,9 @@ var db = require(pathThumbnails + "/handlers/db.js");
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
var create = require(pathThumbnails + "/handlers/dbFunctions/create.js");
var insert = require(pathThumbnails + "/handlers/dbFunctions/insert.js");
var update = require(pathThumbnails + "/handlers/dbFunctions/update.js");
function checkTimeout(
function check(
type,
timeout,
channel,
@@ -15,13 +16,12 @@ function checkTimeout(
socket,
error_message
) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (conf_pass != "" && conf_pass == this_pass) {
resolve();
resolve(true);
return;
}
var docs = await find("timeout_api",
{
var docs = await find("timeout_api", {
type: type,
guid: guid
});
@@ -32,12 +32,12 @@ function checkTimeout(
var retry_in = (date.getTime() - now.getTime()) / 1000;
if (retry_in > 0) {
if (typeof error_callback == "function") {
reject();
if (!error_message) {
resolve(false);
return;
} else if (error_message) {
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(
"toast",
error_message + Math.ceil(retry_in) + " second" + sOrNot + "."
@@ -49,18 +49,20 @@ function checkTimeout(
}
}
var now_date = new Date();
await update("timeout_api",
{ type: type, guid: guid },
{
$set: {
createdAt: now_date,
type: type,
guid: guid
}
},
{ upsert: true });
resolve();
await update(
"timeout_api",
{ type: type, guid: guid },
{
$set: {
createdAt: now_date,
type: type,
guid: guid
}
},
{ upsert: true }
);
resolve(true);
});
}
module.exports.checkTimeout = checkTimeout;
module.exports.check = check;