mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-29 05:21:01 +00:00
intermediary
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
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") {
|
||||||
return;
|
return;
|
||||||
@@ -38,67 +38,69 @@ function end(obj, coll, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
db.collection(coll + "_settings").find(function(err, docs) {
|
var docs = await find(coll + "_settings");
|
||||||
var authentication_needed = false;
|
var authentication_needed = false;
|
||||||
if (
|
|
||||||
docs.length > 0 &&
|
if (
|
||||||
(docs[0].userpass != undefined && docs[0].userpass != "")
|
docs.length > 0 &&
|
||||||
|
(docs[0].userpass != undefined && docs[0].userpass != "")
|
||||||
|
) {
|
||||||
|
callback_function = Functions.getSessionAdminUser;
|
||||||
|
authentication_needed = true;
|
||||||
|
var sessionAdminUser = await Functions.getSessionAdminUser(Functions.getSession(socket), coll);
|
||||||
|
obj.userpass = sessionAdminUser.userpass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userpass != "" || obj.pass == undefined) {
|
||||||
|
obj.pass = userpass;
|
||||||
|
} else {
|
||||||
|
obj.pass = crypto
|
||||||
|
.createHash("sha256")
|
||||||
|
.update(Functions.decrypt_string(obj.pass))
|
||||||
|
.digest("base64");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!authentication_needed ||
|
||||||
|
(authentication_needed &&
|
||||||
|
obj.hasOwnProperty("pass") &&
|
||||||
|
docs[0].userpass == obj.pass)
|
||||||
) {
|
) {
|
||||||
callback_function = Functions.getSessionAdminUser;
|
Functions.check_inlist(
|
||||||
authentication_needed = true;
|
coll,
|
||||||
}
|
guid,
|
||||||
callback_function(Functions.getSession(socket), coll, function(userpass) {
|
socket,
|
||||||
if (userpass != "" || obj.pass == undefined) {
|
offline,
|
||||||
obj.pass = userpass;
|
undefined,
|
||||||
} else {
|
"place 13"
|
||||||
obj.pass = crypto
|
);
|
||||||
.createHash("sha256")
|
var np = await find(coll, { now_playing: true });
|
||||||
.update(Functions.decrypt_string(obj.pass))
|
if (err !== null) console.log(err);
|
||||||
.digest("base64");
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!authentication_needed ||
|
np !== null &&
|
||||||
(authentication_needed &&
|
np !== undefined &&
|
||||||
obj.hasOwnProperty("pass") &&
|
np.length == 1 &&
|
||||||
docs[0].userpass == obj.pass)
|
np[0].id == id
|
||||||
) {
|
) {
|
||||||
Functions.check_inlist(
|
var startTime = docs[0].startTime;
|
||||||
coll,
|
if (
|
||||||
guid,
|
startTime + parseInt(np[0].duration) <=
|
||||||
socket,
|
Functions.get_time() + 5
|
||||||
offline,
|
) {
|
||||||
undefined,
|
changeSong(coll, false, id, docs);
|
||||||
"place 13"
|
}
|
||||||
);
|
|
||||||
db.collection(coll).find({ now_playing: true }, function(err, np) {
|
|
||||||
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
|
|
||||||
) {
|
|
||||||
change_song(coll, false, id, docs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
socket.emit("auth_required");
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
});
|
socket.emit("auth_required");
|
||||||
} else {
|
|
||||||
var result = {
|
|
||||||
msg: {
|
|
||||||
expected: "object",
|
|
||||||
got: typeof obj
|
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
socket.emit("update_required", result);
|
var result = {
|
||||||
|
msg: {
|
||||||
|
expected: "object",
|
||||||
|
got: typeof obj
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socket.emit("update_required", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
module.exports.end = end;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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");
|
||||||
|
|
||||||
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 } },
|
||||||
|
|||||||
@@ -4,126 +4,125 @@ var db = require(pathThumbnails + "/handlers/db.js");
|
|||||||
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
var find = require(pathThumbnails + "/handlers/dbFunctions/find.js");
|
||||||
|
|
||||||
async function getNowPlaying(list, socket) {
|
async function getNowPlaying(list, socket) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function send_play(coll, socket, broadcast) {
|
|
||||||
//coll = coll.replace(/ /g,'');
|
|
||||||
db.collection(coll).find({ now_playing: true }, function(err, np) {
|
|
||||||
db.collection(coll + "_settings").find(function(err, conf) {
|
|
||||||
if (err !== null) console.log(err);
|
|
||||||
try {
|
|
||||||
if (Functions.get_time() - conf[0].startTime > np[0].duration) {
|
|
||||||
change_song(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;
|
return;
|
||||||
}
|
|
||||||
socket.emit("np", {});
|
|
||||||
} else {
|
|
||||||
io.to(coll).emit("np", {});
|
|
||||||
}
|
}
|
||||||
}
|
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);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextSong(coll, socket, callback) {
|
async function sendPlay(coll, socket, broadcast) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
db.collection(coll).aggregate(
|
var np = await find(coll, { now_playing: true });
|
||||||
[
|
var conf = await find(coll + "_settings");
|
||||||
{
|
if (err !== null) console.log(err);
|
||||||
$match: {
|
try {
|
||||||
views: {
|
if (Functions.get_time() - conf[0].startTime > np[0].duration) {
|
||||||
$exists: false
|
changeSong(coll, false, np[0].id, conf);
|
||||||
},
|
} else if (conf !== null && conf !== undefined && conf.length !== 0) {
|
||||||
type: {
|
if (conf[0].adminpass !== "") conf[0].adminpass = true;
|
||||||
$ne: "suggested"
|
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) {
|
||||||
$sort: {
|
if (broadcast) {
|
||||||
now_playing: 1,
|
socket.to(coll).emit("np", {});
|
||||||
votes: -1,
|
return;
|
||||||
added: 1,
|
}
|
||||||
title: 1
|
socket.emit("np", {});
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$limit: 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
function(err, doc) {
|
|
||||||
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 {
|
} else {
|
||||||
io.to(coll).emit("next_song", {
|
io.to(coll).emit("np", {});
|
||||||
videoId: doc[0].id,
|
|
||||||
title: doc[0].title,
|
|
||||||
source: source,
|
|
||||||
thumbnail: thumbnail
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (typeof callback == "function") callback();
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getNowPlaying = getNowPlaying;
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getNowPlaying = getNowPlaying;
|
||||||
|
module.exports.getNextSong = getNextSong;
|
||||||
|
module.exports.sendPlay = sendPlay;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
userpass: ""
|
userpass: ""
|
||||||
};
|
};
|
||||||
await update(coll + "_settings", { id: "config" }, conf, { upsert: true });
|
await update(coll + "_settings", { id: "config" }, conf, { upsert: true });
|
||||||
send_list(coll, socket, send, list_send, configs, shuffled);
|
sendList(coll, socket, send, list_send, configs, shuffled);
|
||||||
} else {
|
} else {
|
||||||
var docs = await aggregate(coll, [
|
var docs = await aggregate(coll, [
|
||||||
{
|
{
|
||||||
@@ -134,11 +134,11 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
{ $set: { now_playing: false } },
|
{ $set: { now_playing: false } },
|
||||||
{ multi: true }
|
{ multi: true }
|
||||||
);
|
);
|
||||||
send_list(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 (Functions.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);
|
||||||
send_list(coll, socket, send, list_send, configs, shuffled);
|
sendList(coll, socket, send, list_send, configs, shuffled);
|
||||||
} else {
|
} else {
|
||||||
if (list_send) {
|
if (list_send) {
|
||||||
io.to(coll).emit("channel", {
|
io.to(coll).emit("channel", {
|
||||||
@@ -154,9 +154,9 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (socket === undefined && send) {
|
if (socket === undefined && send) {
|
||||||
send_play(coll);
|
sendPlay(coll);
|
||||||
} else if (send) {
|
} else if (send) {
|
||||||
send_play(coll, socket);
|
sendPlay(coll, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,9 +175,9 @@ async function sendList(coll, socket, send, list_send, configs, shuffled) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (socket === undefined && send) {
|
if (socket === undefined && send) {
|
||||||
send_play(coll);
|
sendPlay(coll);
|
||||||
} else if (send) {
|
} else if (send) {
|
||||||
send_play(coll, socket);
|
sendPlay(coll, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configs) {
|
if (configs) {
|
||||||
|
|||||||
66
server/handlers/dbFunctions/advancedFunctions/timeout.js
Normal file
66
server/handlers/dbFunctions/advancedFunctions/timeout.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var mongojs = require("mongojs");
|
||||||
|
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");
|
||||||
|
|
||||||
|
function checkTimeout(
|
||||||
|
type,
|
||||||
|
timeout,
|
||||||
|
channel,
|
||||||
|
guid,
|
||||||
|
conf_pass,
|
||||||
|
this_pass,
|
||||||
|
socket,
|
||||||
|
error_message
|
||||||
|
) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (conf_pass != "" && conf_pass == this_pass) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var docs = await find("timeout_api",
|
||||||
|
{
|
||||||
|
type: type,
|
||||||
|
guid: guid
|
||||||
|
});
|
||||||
|
if (docs.length > 0) {
|
||||||
|
var date = new Date(docs[0].createdAt);
|
||||||
|
date.setSeconds(date.getSeconds() + timeout);
|
||||||
|
var now = new Date();
|
||||||
|
|
||||||
|
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||||
|
if (retry_in > 0) {
|
||||||
|
if (typeof error_callback == "function") {
|
||||||
|
reject();
|
||||||
|
return;
|
||||||
|
} else if (error_message) {
|
||||||
|
var sOrNot =
|
||||||
|
Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : "";
|
||||||
|
socket.emit(
|
||||||
|
"toast",
|
||||||
|
error_message + Math.ceil(retry_in) + " second" + sOrNot + "."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
socket.emit("toast", "wait_longer");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var now_date = new Date();
|
||||||
|
await update("timeout_api",
|
||||||
|
{ type: type, guid: guid },
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
createdAt: now_date,
|
||||||
|
type: type,
|
||||||
|
guid: guid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ upsert: true });
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.checkTimeout = checkTimeout;
|
||||||
@@ -15,6 +15,7 @@ var filter = new Filter({ placeHolder: "x" });
|
|||||||
var request = require("request");
|
var request = require("request");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(pathThumbnails + "/handlers/db.js");
|
||||||
|
|
||||||
|
// done
|
||||||
function now_playing(list, fn, socket) {
|
function now_playing(list, fn, socket) {
|
||||||
if (typeof list !== "string" || typeof fn !== "function") {
|
if (typeof list !== "string" || typeof fn !== "function") {
|
||||||
socket.emit("update_required");
|
socket.emit("update_required");
|
||||||
|
|||||||
Reference in New Issue
Block a user