mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-29 21:41:00 +00:00
Add cleanup of var and scoping with even more cleanup
This commit is contained in:
@@ -1,5 +1 @@
|
|||||||
VERSION = 6;
|
export const VERSION = 6;
|
||||||
|
|
||||||
try {
|
|
||||||
module.exports = VERSION;
|
|
||||||
} catch (e) {}
|
|
||||||
@@ -1,27 +1,18 @@
|
|||||||
import {
|
import {
|
||||||
publicPath,
|
publicPath,
|
||||||
pathThumbnails,
|
handlersPath,
|
||||||
|
clientRoutingPath,
|
||||||
|
certAvailble
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var secure = false;
|
let express = require("express");
|
||||||
var path = require("path");
|
let app = express();
|
||||||
try {
|
let compression = require("compression");
|
||||||
var cert_config = require(path.join(
|
let exphbs = require("express-handlebars");
|
||||||
path.join(__dirname, "../config/"),
|
let cors = require("cors");
|
||||||
"cert_config.js"
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
));
|
|
||||||
var fs = require("fs");
|
|
||||||
secure = true;
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
var express = require("express");
|
let hbs = exphbs.create({
|
||||||
var app = express();
|
|
||||||
var compression = require("compression");
|
|
||||||
var exphbs = require("express-handlebars");
|
|
||||||
var cors = require("cors");
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
|
||||||
|
|
||||||
var hbs = exphbs.create({
|
|
||||||
defaultLayout: publicPath + "/layouts/client/main",
|
defaultLayout: publicPath + "/layouts/client/main",
|
||||||
layoutsDir: publicPath + "/layouts/client",
|
layoutsDir: publicPath + "/layouts/client",
|
||||||
partialsDir: publicPath + "/partials",
|
partialsDir: publicPath + "/partials",
|
||||||
@@ -39,7 +30,32 @@ var hbs = exphbs.create({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var uniqid = require("uniqid");
|
|
||||||
|
let uniqid = require("uniqid");
|
||||||
|
let bodyParser = require("body-parser");
|
||||||
|
let cookieParser = require("cookie-parser");
|
||||||
|
let referrerPolicy = require("referrer-policy");
|
||||||
|
let helmet = require("helmet");
|
||||||
|
let featurePolicy = require("feature-policy");
|
||||||
|
|
||||||
|
/* Globally needed "libraries" and files */
|
||||||
|
let router = require(clientRoutingPath + "/router.js");
|
||||||
|
let api_file = require(clientRoutingPath + "/api.js");
|
||||||
|
let api = api_file.router;
|
||||||
|
api_file.sIO = app.socketIO;
|
||||||
|
let ico_router = require(clientRoutingPath + "/icons_routing.js");
|
||||||
|
|
||||||
|
app.engine("handlebars", hbs.engine);
|
||||||
|
app.set("view engine", "handlebars");
|
||||||
|
app.enable("view cache");
|
||||||
|
app.set("views", publicPath);
|
||||||
|
app.set("trust proxy", "127.0.0.1");
|
||||||
|
|
||||||
|
import {
|
||||||
|
start
|
||||||
|
} from "../handlers/io";
|
||||||
|
app.socketIO = start();
|
||||||
|
|
||||||
app.use(compression({
|
app.use(compression({
|
||||||
filter: shouldCompress
|
filter: shouldCompress
|
||||||
}));
|
}));
|
||||||
@@ -53,19 +69,10 @@ function shouldCompress(req, res) {
|
|||||||
// fallback to standard filter function
|
// fallback to standard filter function
|
||||||
return compression.filter(req, res);
|
return compression.filter(req, res);
|
||||||
}
|
}
|
||||||
|
app.get("/robots.txt", function (req, res) {
|
||||||
app.engine("handlebars", hbs.engine);
|
res.type("text/plain");
|
||||||
app.set("view engine", "handlebars");
|
res.send("User-agent: *\nAllow: /$\nDisallow: /");
|
||||||
app.enable("view cache");
|
});
|
||||||
app.set("views", publicPath);
|
|
||||||
app.set("trust proxy", "127.0.0.1");
|
|
||||||
|
|
||||||
var bodyParser = require("body-parser");
|
|
||||||
var cookieParser = require("cookie-parser");
|
|
||||||
var referrerPolicy = require("referrer-policy");
|
|
||||||
var helmet = require("helmet");
|
|
||||||
var featurePolicy = require("feature-policy");
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
featurePolicy({
|
featurePolicy({
|
||||||
features: {
|
features: {
|
||||||
@@ -95,30 +102,10 @@ app.use(
|
|||||||
);
|
);
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
io = require("socket.io")({
|
|
||||||
pingTimeout: 25000
|
|
||||||
});
|
|
||||||
|
|
||||||
var socketIO = require(pathThumbnails + "/handlers/io.js");
|
|
||||||
socketIO();
|
|
||||||
|
|
||||||
app.socketIO = io;
|
|
||||||
|
|
||||||
/* Globally needed "libraries" and files */
|
|
||||||
var router = require(pathThumbnails + "/routing/client/router.js");
|
|
||||||
var api_file = require(pathThumbnails + "/routing/client/api.js");
|
|
||||||
var api = api_file.router;
|
|
||||||
api_file.sIO = app.socketIO;
|
|
||||||
var ico_router = require(pathThumbnails + "/routing/client/icons_routing.js");
|
|
||||||
|
|
||||||
app.get("/robots.txt", function (req, res) {
|
|
||||||
res.type("text/plain");
|
|
||||||
res.send("User-agent: *\nAllow: /$\nDisallow: /");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
var cookie = req.cookies._uI;
|
let cookie = req.cookies._uI;
|
||||||
var skipElements = [
|
let skipElements = [
|
||||||
"/_embed",
|
"/_embed",
|
||||||
"/assets/manifest.json",
|
"/assets/manifest.json",
|
||||||
"/apple-touch-icon.png"
|
"/apple-touch-icon.png"
|
||||||
@@ -146,13 +133,13 @@ app.use(function (req, res, next) {
|
|||||||
res.cookie("_uI", user_name, {
|
res.cookie("_uI", user_name, {
|
||||||
maxAge: 365 * 10000 * 3600000,
|
maxAge: 365 * 10000 * 3600000,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: secure
|
secure: certAvailble
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.cookie("_uI", cookie, {
|
res.cookie("_uI", cookie, {
|
||||||
maxAge: 365 * 10000 * 3600000,
|
maxAge: 365 * 10000 * 3600000,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: secure
|
secure: certAvailble
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
|
|
||||||
function get_history(channel, all, socket) {
|
function get_history(channel, all, socket) {
|
||||||
var query = {};
|
let query = {};
|
||||||
if (all) {
|
if (all) {
|
||||||
query = {
|
query = {
|
||||||
all: true
|
all: true
|
||||||
@@ -18,7 +18,7 @@ function get_history(channel, all, socket) {
|
|||||||
channel: channel
|
channel: channel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var pass = "";
|
let pass = "";
|
||||||
if (!query.all) {
|
if (!query.all) {
|
||||||
Functions.getSessionAdminUser(
|
Functions.getSessionAdminUser(
|
||||||
Functions.getSession(socket),
|
Functions.getSession(socket),
|
||||||
@@ -93,7 +93,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
typeof msg.data != "string" ||
|
typeof msg.data != "string" ||
|
||||||
typeof msg.channel != "string"
|
typeof msg.channel != "string"
|
||||||
) {
|
) {
|
||||||
var result = {
|
const result = {
|
||||||
data: {
|
data: {
|
||||||
expected: "string",
|
expected: "string",
|
||||||
got: msg.hasOwnProperty("data") ? typeof msg.data : undefined
|
got: msg.hasOwnProperty("data") ? typeof msg.data : undefined
|
||||||
@@ -110,7 +110,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
socket.emit("update_required", result);
|
socket.emit("update_required", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var coll = msg.channel.toLowerCase();
|
let coll = msg.channel.toLowerCase();
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||||
|
|
||||||
checkIfUserIsBanned(coll, socket, guid, function () {
|
checkIfUserIsBanned(coll, socket, guid, function () {
|
||||||
@@ -143,7 +143,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
conf[0].userpass == "" ||
|
conf[0].userpass == "" ||
|
||||||
(msg.hasOwnProperty("pass") && conf[0].userpass == msg.pass))
|
(msg.hasOwnProperty("pass") && conf[0].userpass == msg.pass))
|
||||||
) {
|
) {
|
||||||
var data = msg.data;
|
let data = msg.data;
|
||||||
|
|
||||||
Functions.check_inlist(
|
Functions.check_inlist(
|
||||||
coll,
|
coll,
|
||||||
@@ -157,7 +157,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
channels: coll
|
channels: coll
|
||||||
},
|
},
|
||||||
function (err, docs) {
|
function (err, docs) {
|
||||||
var userAdd = "s";
|
let userAdd = "s";
|
||||||
if (docs.length == 1) userAdd = "";
|
if (docs.length == 1) userAdd = "";
|
||||||
socket.emit("chat", {
|
socket.emit("chat", {
|
||||||
from: "System",
|
from: "System",
|
||||||
@@ -183,13 +183,13 @@ function chat(msg, guid, offline, socket) {
|
|||||||
docs
|
docs
|
||||||
) {
|
) {
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
var splitData = data.split(" ");
|
let splitData = data.split(" ");
|
||||||
if (
|
if (
|
||||||
(data.startsWith("/ban") && splitData.length >= 3) ||
|
(data.startsWith("/ban") && splitData.length >= 3) ||
|
||||||
(data.startsWith("/unban") && splitData.length >= 2)
|
(data.startsWith("/unban") && splitData.length >= 2)
|
||||||
) {
|
) {
|
||||||
if (splitData[1].length > 0) {
|
if (splitData[1].length > 0) {
|
||||||
var passToCompare = Functions.hash_pass(adminpass);
|
const passToCompare = Functions.hash_pass(adminpass);
|
||||||
if (passToCompare == conf[0].adminpass) {
|
if (passToCompare == conf[0].adminpass) {
|
||||||
db.collection("user_names").find({
|
db.collection("user_names").find({
|
||||||
name: splitData[1]
|
name: splitData[1]
|
||||||
@@ -200,11 +200,11 @@ function chat(msg, guid, offline, socket) {
|
|||||||
data.startsWith("/ban") &&
|
data.startsWith("/ban") &&
|
||||||
splitData.length >= 3
|
splitData.length >= 3
|
||||||
) {
|
) {
|
||||||
var reason = splitData
|
let reason = splitData
|
||||||
.slice(2, splitData.length)
|
.slice(2, splitData.length)
|
||||||
.join(" ");
|
.join(" ");
|
||||||
var connection_id = name[0].connection_id;
|
let connection_id = name[0].connection_id;
|
||||||
var yourSelf = Functions.hash_pass(
|
let yourSelf = Functions.hash_pass(
|
||||||
socket.handshake.headers["user-agent"] +
|
socket.handshake.headers["user-agent"] +
|
||||||
socket.handshake.address +
|
socket.handshake.address +
|
||||||
socket.handshake.headers[
|
socket.handshake.headers[
|
||||||
@@ -213,11 +213,11 @@ function chat(msg, guid, offline, socket) {
|
|||||||
);
|
);
|
||||||
if (connection_id != yourSelf) {
|
if (connection_id != yourSelf) {
|
||||||
db.collection(coll + "_banned_chat").update({
|
db.collection(coll + "_banned_chat").update({
|
||||||
connection_id: connection_id
|
connection_id
|
||||||
}, {
|
}, {
|
||||||
connection_id: connection_id,
|
connection_id,
|
||||||
by: docs[0].name,
|
by: docs[0].name,
|
||||||
reason: reason
|
reason
|
||||||
}, {
|
}, {
|
||||||
upsert: true
|
upsert: true
|
||||||
},
|
},
|
||||||
@@ -317,7 +317,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
_id: docs[0].name
|
_id: docs[0].name
|
||||||
},
|
},
|
||||||
function (err, n) {
|
function (err, n) {
|
||||||
var icon = false;
|
let icon = false;
|
||||||
if (n.length > 0 && n[0].icon) {
|
if (n.length > 0 && n[0].icon) {
|
||||||
icon = n[0].icon;
|
icon = n[0].icon;
|
||||||
}
|
}
|
||||||
@@ -327,12 +327,12 @@ function chat(msg, guid, offline, socket) {
|
|||||||
channel: coll,
|
channel: coll,
|
||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
msg: ": " + data,
|
msg: ": " + data,
|
||||||
icon: icon
|
icon
|
||||||
});
|
});
|
||||||
io.to(coll).emit("chat", {
|
io.to(coll).emit("chat", {
|
||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
msg: ": " + data,
|
msg: ": " + data,
|
||||||
icon: icon
|
icon
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -343,7 +343,7 @@ function chat(msg, guid, offline, socket) {
|
|||||||
channel: coll,
|
channel: coll,
|
||||||
message: data,
|
message: data,
|
||||||
all: false,
|
all: false,
|
||||||
socket: socket
|
socket
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -367,7 +367,7 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
typeof msg.data != "string" ||
|
typeof msg.data != "string" ||
|
||||||
typeof msg.channel != "string"
|
typeof msg.channel != "string"
|
||||||
) {
|
) {
|
||||||
var result = {
|
const result = {
|
||||||
data: {
|
data: {
|
||||||
expected: "string",
|
expected: "string",
|
||||||
got: msg.hasOwnProperty("data") ? typeof msg.data : undefined
|
got: msg.hasOwnProperty("data") ? typeof msg.data : undefined
|
||||||
@@ -380,8 +380,8 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
socket.emit("update_required", result);
|
socket.emit("update_required", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var coll = msg.channel.toLowerCase();
|
let coll = msg.channel.toLowerCase();
|
||||||
var data = msg.data;
|
const data = msg.data;
|
||||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||||
Functions.check_inlist(
|
Functions.check_inlist(
|
||||||
coll,
|
coll,
|
||||||
@@ -397,7 +397,7 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
data.replace(/\s/g, "").length
|
data.replace(/\s/g, "").length
|
||||||
) {
|
) {
|
||||||
db.collection("user_names").find({
|
db.collection("user_names").find({
|
||||||
guid: guid
|
guid
|
||||||
}, function (err, docs) {
|
}, function (err, docs) {
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
db.collection("registered_users").find({
|
db.collection("registered_users").find({
|
||||||
@@ -414,7 +414,7 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
channel: coll,
|
channel: coll,
|
||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
msg: ": " + data,
|
msg: ": " + data,
|
||||||
icon: icon
|
icon
|
||||||
},
|
},
|
||||||
function (err, docs) {}
|
function (err, docs) {}
|
||||||
);
|
);
|
||||||
@@ -422,7 +422,7 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
msg: ": " + data,
|
msg: ": " + data,
|
||||||
channel: coll,
|
channel: coll,
|
||||||
icon: icon
|
icon
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -432,7 +432,7 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
channel: coll,
|
channel: coll,
|
||||||
message: data,
|
message: data,
|
||||||
all: true,
|
all: true,
|
||||||
socket: socket
|
socket
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -443,8 +443,9 @@ function all_chat(msg, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkIfChatEnabled(channel, socket, callback) {
|
function checkIfChatEnabled(channel, socket, callback) {
|
||||||
if (channel == "" || channel == undefined) callback();
|
if (channel == "" || channel == undefined) {
|
||||||
else {
|
callback();
|
||||||
|
} else {
|
||||||
db.collection(channel + "_settings").find(function (err, docs) {
|
db.collection(channel + "_settings").find(function (err, docs) {
|
||||||
if (
|
if (
|
||||||
docs.length > 0 &&
|
docs.length > 0 &&
|
||||||
@@ -471,17 +472,18 @@ function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) {
|
|||||||
);
|
);
|
||||||
db.collection(channel + "_banned_chat").find({
|
db.collection(channel + "_banned_chat").find({
|
||||||
$or: [{
|
$or: [{
|
||||||
connection_id: connection_id
|
connection_id
|
||||||
}, {
|
}, {
|
||||||
connection_id: guid
|
connection_id: guid
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
function (err, docs) {
|
function (err, docs) {
|
||||||
if (docs.length == 0) callback();
|
if (docs.length == 0) {
|
||||||
else {
|
callback();
|
||||||
|
} else {
|
||||||
db.collection("user_names").findAndModify({
|
db.collection("user_names").findAndModify({
|
||||||
query: {
|
query: {
|
||||||
guid: guid
|
guid
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
$addToSet: {
|
$addToSet: {
|
||||||
@@ -516,9 +518,9 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
socket,
|
socket,
|
||||||
guid,
|
guid,
|
||||||
function () {
|
function () {
|
||||||
var pw = "";
|
let pw = "";
|
||||||
var new_password;
|
let new_password;
|
||||||
var first = false;
|
let first = false;
|
||||||
Functions.getSessionChatPass(Functions.getSession(socket), function (
|
Functions.getSessionChatPass(Functions.getSession(socket), function (
|
||||||
name,
|
name,
|
||||||
pass
|
pass
|
||||||
@@ -565,8 +567,8 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
_id: name.toLowerCase()
|
_id: name.toLowerCase()
|
||||||
},
|
},
|
||||||
function (err, docs) {
|
function (err, docs) {
|
||||||
var accepted_password = false;
|
let accepted_password = false;
|
||||||
var icon = false;
|
let icon = false;
|
||||||
if (docs.length == 0) {
|
if (docs.length == 0) {
|
||||||
if (new_password) {
|
if (new_password) {
|
||||||
if (typeof callback == "function") callback(true);
|
if (typeof callback == "function") callback(true);
|
||||||
@@ -582,7 +584,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
_id: name.toLowerCase()
|
_id: name.toLowerCase()
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
password: password
|
password
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
upsert: true
|
upsert: true
|
||||||
@@ -604,7 +606,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
function () {
|
function () {
|
||||||
db.collection("registered_users").update({
|
db.collection("registered_users").update({
|
||||||
_id: name.toLowerCase(),
|
_id: name.toLowerCase(),
|
||||||
password: password
|
password
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
password: Functions.hash_pass(new_password)
|
password: Functions.hash_pass(new_password)
|
||||||
@@ -629,7 +631,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
}
|
}
|
||||||
if (accepted_password) {
|
if (accepted_password) {
|
||||||
db.collection("user_names").find({
|
db.collection("user_names").find({
|
||||||
guid: guid
|
guid
|
||||||
}, function (
|
}, function (
|
||||||
err,
|
err,
|
||||||
names
|
names
|
||||||
@@ -639,9 +641,11 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
(docs.length != 0 && docs[0].password == password)
|
(docs.length != 0 && docs[0].password == password)
|
||||||
) {
|
) {
|
||||||
var no_name = false;
|
var no_name = false;
|
||||||
if (names.length == 0) no_name = true;
|
if (names.length == 0) {
|
||||||
|
no_name = true;
|
||||||
|
};
|
||||||
if (!no_name) {
|
if (!no_name) {
|
||||||
var old_name = names[0].name;
|
const old_name = names[0].name;
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
_id: "all_names"
|
_id: "all_names"
|
||||||
}, {
|
}, {
|
||||||
@@ -652,25 +656,25 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
function () {}
|
function () {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var connection_id = Functions.hash_pass(
|
const connection_id = Functions.hash_pass(
|
||||||
socket.handshake.headers["user-agent"] +
|
socket.handshake.headers["user-agent"] +
|
||||||
socket.handshake.address +
|
socket.handshake.address +
|
||||||
socket.handshake.headers["accept-language"]
|
socket.handshake.headers["accept-language"]
|
||||||
);
|
);
|
||||||
var updateElement = {
|
let updateElement = {
|
||||||
$set: {
|
$set: {
|
||||||
name: name,
|
name,
|
||||||
icon: icon,
|
icon,
|
||||||
connection_id: connection_id
|
connection_id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (data.hasOwnProperty("channel") && data.channel != "") {
|
if (data.hasOwnProperty("channel") && data.channel != "") {
|
||||||
updateElement["$addToSet"] = {
|
updateElement.$addToSet = {
|
||||||
channels: data.channel
|
channels: data.channel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
guid: guid
|
guid
|
||||||
},
|
},
|
||||||
updateElement, {
|
updateElement, {
|
||||||
upsert: true
|
upsert: true
|
||||||
@@ -742,10 +746,10 @@ function removename(guid, coll, socket) {
|
|||||||
checkIfChatEnabled(coll, socket, function (enabled) {
|
checkIfChatEnabled(coll, socket, function (enabled) {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
db.collection("user_names").find({
|
db.collection("user_names").find({
|
||||||
guid: guid
|
guid
|
||||||
}, function (err, docs) {
|
}, function (err, docs) {
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
var old_name = docs[0].name;
|
const old_name = docs[0].name;
|
||||||
Functions.removeSessionChatPass(
|
Functions.removeSessionChatPass(
|
||||||
Functions.getSession(socket),
|
Functions.getSession(socket),
|
||||||
function () {
|
function () {
|
||||||
@@ -758,16 +762,16 @@ function removename(guid, coll, socket) {
|
|||||||
},
|
},
|
||||||
function (err, updated) {
|
function (err, updated) {
|
||||||
db.collection("user_names").remove({
|
db.collection("user_names").remove({
|
||||||
guid: guid
|
guid
|
||||||
}, function (
|
}, function (
|
||||||
err,
|
err,
|
||||||
removed
|
removed
|
||||||
) {
|
) {
|
||||||
get_name(guid, {
|
get_name(guid, {
|
||||||
announce: true,
|
announce: true,
|
||||||
old_name: old_name,
|
old_name,
|
||||||
channel: coll,
|
channel: coll,
|
||||||
socket: socket
|
socket
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -780,8 +784,10 @@ function removename(guid, coll, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generate_name(guid, announce_payload, second, round, channel) {
|
function generate_name(guid, announce_payload, second, round, channel) {
|
||||||
if (round == undefined) round = 0;
|
if (round == undefined) {
|
||||||
var tmp_name = Functions.rndName(
|
round = 0;
|
||||||
|
}
|
||||||
|
const tmp_name = Functions.rndName(
|
||||||
second ? second : guid,
|
second ? second : guid,
|
||||||
Math.floor(8 + round)
|
Math.floor(8 + round)
|
||||||
);
|
);
|
||||||
@@ -817,11 +823,11 @@ function generate_name(guid, announce_payload, second, round, channel) {
|
|||||||
$set: {
|
$set: {
|
||||||
name: tmp_name,
|
name: tmp_name,
|
||||||
icon: false,
|
icon: false,
|
||||||
connection_id: connection_id
|
connection_id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (channel != undefined && channel != "") {
|
if (channel != undefined && channel != "") {
|
||||||
updateElement["$addToSet"] = {
|
updateElement.$addToSet = {
|
||||||
channels: channel
|
channels: channel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -829,12 +835,12 @@ function generate_name(guid, announce_payload, second, round, channel) {
|
|||||||
announce_payload.hasOwnProperty("channel") &&
|
announce_payload.hasOwnProperty("channel") &&
|
||||||
announce_payload.channel != ""
|
announce_payload.channel != ""
|
||||||
) {
|
) {
|
||||||
updateElement["$addToSet"] = {
|
updateElement.$addToSet = {
|
||||||
channels: announce_payload.channel
|
channels: announce_payload.channel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
guid: guid
|
guid
|
||||||
},
|
},
|
||||||
updateElement, {
|
updateElement, {
|
||||||
upsert: true
|
upsert: true
|
||||||
@@ -921,20 +927,20 @@ function get_name(guid, announce_payload, first) {
|
|||||||
);
|
);
|
||||||
var updateElement = {
|
var updateElement = {
|
||||||
$set: {
|
$set: {
|
||||||
name: name,
|
name,
|
||||||
icon: icon,
|
icon,
|
||||||
connection_id: connection_id
|
connection_id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
announce_payload.hasOwnProperty("channel") &&
|
announce_payload.hasOwnProperty("channel") &&
|
||||||
announce_payload.channel != ""
|
announce_payload.channel != ""
|
||||||
)
|
)
|
||||||
updateElement["$addToSet"] = {
|
updateElement.$addToSet = {
|
||||||
channel: announce_payload.channel
|
channel: announce_payload.channel
|
||||||
};
|
};
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
guid: guid
|
guid
|
||||||
},
|
},
|
||||||
updateElement, {
|
updateElement, {
|
||||||
upsert: true
|
upsert: true
|
||||||
@@ -965,7 +971,7 @@ function get_name(guid, announce_payload, first) {
|
|||||||
|
|
||||||
function get_name_generate(guid, announce_payload, first, channel) {
|
function get_name_generate(guid, announce_payload, first, channel) {
|
||||||
db.collection("user_names").find({
|
db.collection("user_names").find({
|
||||||
guid: guid
|
guid
|
||||||
}, function (err, docs) {
|
}, function (err, docs) {
|
||||||
if (docs.length == 0) {
|
if (docs.length == 0) {
|
||||||
generate_name(guid, announce_payload, undefined);
|
generate_name(guid, announce_payload, undefined);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { join } from "path";
|
|
||||||
import {
|
import {
|
||||||
mongojs
|
join
|
||||||
} from 'mongojs';
|
} from "path";
|
||||||
|
import mongojs from 'mongojs';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var mongo_config = require(
|
var mongo_config = require(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails,
|
handlersPath,
|
||||||
VERSION
|
VERSION
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
|
|
||||||
function frontpage_lists(msg, socket) {
|
function frontpage_lists(msg, socket) {
|
||||||
if (
|
if (
|
||||||
@@ -13,7 +13,7 @@ function frontpage_lists(msg, socket) {
|
|||||||
msg.version != VERSION ||
|
msg.version != VERSION ||
|
||||||
msg.version == undefined
|
msg.version == undefined
|
||||||
) {
|
) {
|
||||||
var result = {
|
const result = {
|
||||||
version: {
|
version: {
|
||||||
expected: VERSION,
|
expected: VERSION,
|
||||||
got: msg.hasOwnProperty("version") ? msg.version : undefined
|
got: msg.hasOwnProperty("version") ? msg.version : undefined
|
||||||
@@ -46,7 +46,7 @@ function frontpage_lists(msg, socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_frontpage_lists(callback) {
|
function get_frontpage_lists(callback) {
|
||||||
var project_object = {
|
const project_object = {
|
||||||
_id: 1,
|
_id: 1,
|
||||||
count: 1,
|
count: 1,
|
||||||
frontpage: 1,
|
frontpage: 1,
|
||||||
@@ -136,9 +136,9 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
|
|||||||
db.collection("frontpage_lists").find({
|
db.collection("frontpage_lists").find({
|
||||||
_id: coll
|
_id: coll
|
||||||
}, function (e, doc) {
|
}, function (e, doc) {
|
||||||
var updateObject = {
|
const updateObject = {
|
||||||
id: id,
|
id,
|
||||||
title: title,
|
title,
|
||||||
accessed: Functions.get_time()
|
accessed: Functions.get_time()
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
try {
|
try {
|
||||||
var mongo_config = require(path.join(
|
var mongo_config = require(path.join(
|
||||||
path.join(__dirname, "../config/"),
|
path.join(__dirname, "../config/"),
|
||||||
@@ -14,24 +14,24 @@ try {
|
|||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
var mongojs = require("mongojs");
|
let mongojs = require("mongojs");
|
||||||
var connected_db = mongojs(
|
let connected_db = mongojs(
|
||||||
"mongodb://" + mongo_config.host + "/user_credentials"
|
"mongodb://" + mongo_config.host + "/user_credentials"
|
||||||
);
|
);
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
var uniqid = require("uniqid");
|
let uniqid = require("uniqid");
|
||||||
var Filter = require("bad-words");
|
let Filter = require("bad-words");
|
||||||
var filter = new Filter({
|
let filter = new Filter({
|
||||||
placeHolder: "x"
|
placeHolder: "x"
|
||||||
});
|
});
|
||||||
|
|
||||||
var Chat = require(pathThumbnails + "/handlers/chat.js");
|
let Chat = require(handlersPath + "/chat.js");
|
||||||
|
|
||||||
function encodeChannelName(str) {
|
function encodeChannelName(str) {
|
||||||
var _fn = encodeURIComponent;
|
const _fn = encodeURIComponent;
|
||||||
str = filter.clean(str);
|
str = filter.clean(str);
|
||||||
var toReturn = _fn(str);
|
let toReturn = _fn(str);
|
||||||
toReturn = toReturn.replace(/_/g, "%5F");
|
toReturn = toReturn.replace(/_/g, "%5F");
|
||||||
toReturn = toReturn.replace(/'/g, "%27");
|
toReturn = toReturn.replace(/'/g, "%27");
|
||||||
toReturn = toReturn.replace(/%26amp%3B/g, "%26").replace(/%26amp%3b/g, "%26");
|
toReturn = toReturn.replace(/%26amp%3B/g, "%26").replace(/%26amp%3b/g, "%26");
|
||||||
@@ -40,9 +40,9 @@ function encodeChannelName(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function decodeChannelName(str) {
|
function decodeChannelName(str) {
|
||||||
var _fn = decodeURIComponent;
|
const _fn = decodeURIComponent;
|
||||||
str = str.toUpperCase();
|
str = str.toUpperCase();
|
||||||
var toReturn = _fn(str.replace(/%5F/g, "_").replace(/%27/g, "'"));
|
let toReturn = _fn(str.replace(/%5F/g, "_").replace(/%27/g, "'"));
|
||||||
toReturn = filter.clean(toReturn);
|
toReturn = filter.clean(toReturn);
|
||||||
return toReturn.toLowerCase();
|
return toReturn.toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ function remove_name_from_db(guid, channel) {
|
|||||||
} else {
|
} else {
|
||||||
if (channel == undefined || channel == "") return;
|
if (channel == undefined || channel == "") return;
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
guid: guid
|
guid
|
||||||
}, {
|
}, {
|
||||||
$pull: {
|
$pull: {
|
||||||
channels: channel
|
channels: channel
|
||||||
@@ -111,7 +111,7 @@ function remove_name_from_db(guid, channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isUrl(str) {
|
function isUrl(str) {
|
||||||
var pattern = new RegExp(
|
const pattern = new RegExp(
|
||||||
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
|
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
|
||||||
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
|
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
|
||||||
"|mil|biz|info|mobi|name|aero|jobs|museum" +
|
"|mil|biz|info|mobi|name|aero|jobs|museum" +
|
||||||
@@ -146,13 +146,13 @@ function getSession(socket) {
|
|||||||
|
|
||||||
function remove_from_array(array, element) {
|
function remove_from_array(array, element) {
|
||||||
if (contains(array, element)) {
|
if (contains(array, element)) {
|
||||||
var index = array.indexOf(element);
|
const index = array.indexOf(element);
|
||||||
if (index != -1) array.splice(index, 1);
|
if (index != -1) array.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_channel_name(res) {
|
function generate_channel_name(res) {
|
||||||
var trying_id = uniqid.time().toLowerCase();
|
const trying_id = uniqid.time().toLowerCase();
|
||||||
db.collection("frontpage_lists").find({
|
db.collection("frontpage_lists").find({
|
||||||
frontpage: {
|
frontpage: {
|
||||||
$exists: true
|
$exists: true
|
||||||
@@ -172,7 +172,7 @@ function generate_channel_name(res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_short_id(socket) {
|
function get_short_id(socket) {
|
||||||
var new_short_id = uniqid.time().toLowerCase();
|
const new_short_id = uniqid.time().toLowerCase();
|
||||||
|
|
||||||
socket.join(new_short_id);
|
socket.join(new_short_id);
|
||||||
socket.emit("id", new_short_id);
|
socket.emit("id", new_short_id);
|
||||||
@@ -233,10 +233,10 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
|
|||||||
docs
|
docs
|
||||||
) {
|
) {
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
var icon = "";
|
let icon = "";
|
||||||
if (docs[0].icon != undefined) icon = docs[0].icon;
|
if (docs[0].icon != undefined) icon = docs[0].icon;
|
||||||
db.collection("user_names").update({
|
db.collection("user_names").update({
|
||||||
guid: guid
|
guid
|
||||||
}, {
|
}, {
|
||||||
$addToSet: {
|
$addToSet: {
|
||||||
channels: coll
|
channels: coll
|
||||||
@@ -247,14 +247,14 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
socket.broadcast.to(coll).emit("chat", {
|
socket.broadcast.to(coll).emit("chat", {
|
||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
icon: icon,
|
icon,
|
||||||
msg: " joined"
|
msg: " joined"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (docs.length == 0) {
|
} else if (docs.length == 0) {
|
||||||
Chat.get_name(guid, {
|
Chat.get_name(guid, {
|
||||||
announce: false,
|
announce: false,
|
||||||
socket: socket,
|
socket,
|
||||||
channel: coll
|
channel: coll
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rndName(seed, len) {
|
function rndName(seed, len) {
|
||||||
var vowels = ["a", "e", "i", "o", "u"];
|
const vowels = ["a", "e", "i", "o", "u"];
|
||||||
consts = [
|
consts = [
|
||||||
"b",
|
"b",
|
||||||
"c",
|
"c",
|
||||||
@@ -356,9 +356,9 @@ function rndName(seed, len) {
|
|||||||
len = Math.floor(len);
|
len = Math.floor(len);
|
||||||
word = "";
|
word = "";
|
||||||
is_vowel = false;
|
is_vowel = false;
|
||||||
var arr;
|
let arr;
|
||||||
try {
|
try {
|
||||||
for (var i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
if (is_vowel) arr = vowels;
|
if (is_vowel) arr = vowels;
|
||||||
else arr = consts;
|
else arr = consts;
|
||||||
is_vowel = !is_vowel;
|
is_vowel = !is_vowel;
|
||||||
@@ -372,7 +372,7 @@ function rndName(seed, len) {
|
|||||||
|
|
||||||
function removeEmojis(string) {
|
function removeEmojis(string) {
|
||||||
//https://stackoverflow.com/a/41164278/4266467
|
//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;
|
const 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, "");
|
return string.replace(regex, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,14 +385,14 @@ function decrypt_string(pw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_time() {
|
function get_time() {
|
||||||
var d = new Date();
|
const d = new Date();
|
||||||
var time = Math.floor(d.getTime() / 1000);
|
const time = Math.floor(d.getTime() / 1000);
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
function contains(a, obj) {
|
function contains(a, obj) {
|
||||||
try {
|
try {
|
||||||
var i = a.length;
|
let i = a.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (a[i] === obj) {
|
if (a[i] === obj) {
|
||||||
return true;
|
return true;
|
||||||
@@ -483,8 +483,8 @@ function getSessionChatPass(id, callback) {
|
|||||||
_id: "_chat_"
|
_id: "_chat_"
|
||||||
}, function (e, d) {
|
}, function (e, d) {
|
||||||
if (d.length > 0) {
|
if (d.length > 0) {
|
||||||
var name = "";
|
let name = "";
|
||||||
var pass = "";
|
let pass = "";
|
||||||
if (d[0].name != undefined) name = d[0].name;
|
if (d[0].name != undefined) name = d[0].name;
|
||||||
if (d[0].password != undefined) pass = d[0].password;
|
if (d[0].password != undefined) pass = d[0].password;
|
||||||
callback(name, pass);
|
callback(name, pass);
|
||||||
@@ -568,8 +568,8 @@ function getSessionAdminUser(id, list, callback) {
|
|||||||
connected_db.collection(id).find({
|
connected_db.collection(id).find({
|
||||||
_id: list
|
_id: list
|
||||||
}, function (e, d) {
|
}, function (e, d) {
|
||||||
var userpass = "";
|
let userpass = "";
|
||||||
var adminpass = "";
|
let adminpass = "";
|
||||||
if (d.length > 0) {
|
if (d.length > 0) {
|
||||||
if (d[0].hasOwnProperty("chromecast") && d[0].chromecast) {
|
if (d[0].hasOwnProperty("chromecast") && d[0].chromecast) {
|
||||||
getSessionAdminUser(d[0].id, list, callback);
|
getSessionAdminUser(d[0].id, list, callback);
|
||||||
@@ -682,7 +682,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
|
|||||||
docs
|
docs
|
||||||
) {
|
) {
|
||||||
if (docs.length == 1) {
|
if (docs.length == 1) {
|
||||||
var icon = "";
|
let icon = "";
|
||||||
if (docs[0].icon != undefined) icon = docs[0].icon;
|
if (docs[0].icon != undefined) icon = docs[0].icon;
|
||||||
io.to(coll).emit("chat", {
|
io.to(coll).emit("chat", {
|
||||||
from: docs[0].name,
|
from: docs[0].name,
|
||||||
@@ -749,21 +749,21 @@ function checkTimeout(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.collection("timeout_api").find({
|
db.collection("timeout_api").find({
|
||||||
type: type,
|
type,
|
||||||
guid: guid
|
guid
|
||||||
},
|
},
|
||||||
function (err, docs) {
|
function (err, docs) {
|
||||||
if (docs.length > 0) {
|
if (docs.length > 0) {
|
||||||
var date = new Date(docs[0].createdAt);
|
const date = new Date(docs[0].createdAt);
|
||||||
date.setSeconds(date.getSeconds() + timeout);
|
date.setSeconds(date.getSeconds() + timeout);
|
||||||
var now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
const retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||||
if (retry_in > 0) {
|
if (retry_in > 0) {
|
||||||
if (typeof error_callback == "function") {
|
if (typeof error_callback == "function") {
|
||||||
error_callback();
|
error_callback();
|
||||||
} else if (error_message) {
|
} else if (error_message) {
|
||||||
var sOrNot =
|
const 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",
|
||||||
@@ -775,15 +775,14 @@ function checkTimeout(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var now_date = new Date();
|
|
||||||
db.collection("timeout_api").update({
|
db.collection("timeout_api").update({
|
||||||
type: type,
|
type,
|
||||||
guid: guid
|
guid
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
createdAt: now_date,
|
createdAt: now,
|
||||||
type: type,
|
type,
|
||||||
guid: guid
|
guid
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
upsert: true
|
upsert: true
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var cookie = require("cookie");
|
let cookie = require("cookie");
|
||||||
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
|
let ListChange = require(handlersPath + "/list_change.js");
|
||||||
|
let Chat = require(handlersPath + "/chat.js");
|
||||||
|
let List = require(handlersPath + "/list.js");
|
||||||
|
let Suggestions = require(handlersPath + "/suggestions.js");
|
||||||
|
let ListSettings = require(handlersPath + "/list_settings.js");
|
||||||
|
let Frontpage = require(handlersPath + "/frontpage.js");
|
||||||
|
let Search = require(handlersPath + "/search.js");
|
||||||
|
let crypto = require("crypto");
|
||||||
|
let db = require(handlersPath + "/db.js");
|
||||||
|
let ioServer = require("socket.io")({
|
||||||
|
pingTimeout: 25000
|
||||||
|
});
|
||||||
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
function start() {
|
||||||
var ListChange = require(pathThumbnails + "/handlers/list_change.js");
|
ioServer.on("connection", function (socket) {
|
||||||
var Chat = require(pathThumbnails + "/handlers/chat.js");
|
|
||||||
var List = require(pathThumbnails + "/handlers/list.js");
|
|
||||||
var Suggestions = require(pathThumbnails + "/handlers/suggestions.js");
|
|
||||||
var ListSettings = require(pathThumbnails + "/handlers/list_settings.js");
|
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
|
||||||
var Search = require(pathThumbnails + "/handlers/search.js");
|
|
||||||
var crypto = require("crypto");
|
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
|
||||||
|
|
||||||
module.exports = function () {
|
|
||||||
io.on("connection", function (socket) {
|
|
||||||
try {
|
try {
|
||||||
var parsedCookies = cookie.parse(socket.handshake.headers.cookie);
|
const parsedCookies = cookie.parse(socket.handshake.headers.cookie);
|
||||||
socket.cookie_id = parsedCookies["_uI"];
|
socket.cookie_id = parsedCookies._uI;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
socket.cookie_id = "empty";
|
socket.cookie_id = "empty";
|
||||||
}
|
}
|
||||||
socket.zoff_id = socket.id;
|
socket.zoff_id = socket.id;
|
||||||
socket.emit("get_list");
|
socket.emit("get_list");
|
||||||
var guid = socket.cookie_id;
|
let guid = socket.cookie_id;
|
||||||
if (guid == "empty" || guid == null || guid == undefined)
|
if (guid == "empty" || guid == null || guid == undefined)
|
||||||
guid = Functions.hash_pass(
|
guid = Functions.hash_pass(
|
||||||
socket.handshake.headers["user-agent"] +
|
socket.handshake.headers["user-agent"] +
|
||||||
@@ -40,22 +42,22 @@ module.exports = function () {
|
|||||||
socket.emit("ok");
|
socket.emit("ok");
|
||||||
});
|
});
|
||||||
|
|
||||||
var socketid = socket.zoff_id;
|
let socketid = socket.zoff_id;
|
||||||
var coll;
|
let coll;
|
||||||
var in_list = false;
|
let in_list = false;
|
||||||
var name = "";
|
let name = "";
|
||||||
var short_id;
|
let short_id;
|
||||||
Chat.get_name(guid, {
|
Chat.get_name(guid, {
|
||||||
announce: false,
|
announce: false,
|
||||||
socket: socket
|
socket: socket
|
||||||
});
|
});
|
||||||
var offline = false;
|
let offline = false;
|
||||||
var chromecast_object = false;
|
let chromecast_object = false;
|
||||||
|
|
||||||
socket.emit("guid", guid);
|
socket.emit("guid", guid);
|
||||||
|
|
||||||
socket.on("self_ping", function (msg) {
|
socket.on("self_ping", function (msg) {
|
||||||
var channel = msg.channel;
|
let channel = msg.channel;
|
||||||
if (channel.indexOf("?") > -1) {
|
if (channel.indexOf("?") > -1) {
|
||||||
channel = channel.substring(0, channel.indexOf("?"));
|
channel = channel.substring(0, channel.indexOf("?"));
|
||||||
}
|
}
|
||||||
@@ -126,7 +128,7 @@ module.exports = function () {
|
|||||||
if (obj == undefined || !obj.hasOwnProperty("channel")) return;
|
if (obj == undefined || !obj.hasOwnProperty("channel")) return;
|
||||||
db.collection(obj.channel + "_settings").find(function (e, docs) {
|
db.collection(obj.channel + "_settings").find(function (e, docs) {
|
||||||
if (docs.length == 0) return;
|
if (docs.length == 0) return;
|
||||||
var pass = "";
|
let pass = "";
|
||||||
if (obj.hasOwnProperty("pass")) {
|
if (obj.hasOwnProperty("pass")) {
|
||||||
pass = crypto
|
pass = crypto
|
||||||
.createHash("sha256")
|
.createHash("sha256")
|
||||||
@@ -198,14 +200,14 @@ module.exports = function () {
|
|||||||
socket.on("get_id", function () {
|
socket.on("get_id", function () {
|
||||||
socket.emit("id_chromecast", {
|
socket.emit("id_chromecast", {
|
||||||
cookie_id: Functions.getSession(socket),
|
cookie_id: Functions.getSession(socket),
|
||||||
guid: guid
|
guid
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("error_video", function (msg) {
|
socket.on("error_video", function (msg) {
|
||||||
try {
|
try {
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
msg.channel = Functions.encodeChannelName(msg.channel);
|
||||||
var _list = msg.channel;
|
let _list = msg.channel;
|
||||||
if (_list.length == 0) return;
|
if (_list.length == 0) return;
|
||||||
if (_list.indexOf("?") > -1) {
|
if (_list.indexOf("?") > -1) {
|
||||||
_list = _list.substring(0, _list.indexOf("?"));
|
_list = _list.substring(0, _list.indexOf("?"));
|
||||||
@@ -263,7 +265,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("suggest_thumbnail", function (msg) {
|
socket.on("suggest_thumbnail", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -274,7 +276,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("suggest_description", function (msg) {
|
socket.on("suggest_description", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -285,7 +287,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("suggest_rules", function (msg) {
|
socket.on("suggest_rules", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -296,7 +298,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("namechange", function (msg) {
|
socket.on("namechange", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -307,14 +309,14 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("removename", function (msg) {
|
socket.on("removename", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
msg.channel = Functions.encodeChannelName(msg.channel);
|
||||||
}
|
}
|
||||||
if (typeof msg != "object" || !msg.hasOwnProperty("channel")) {
|
if (typeof msg != "object" || !msg.hasOwnProperty("channel")) {
|
||||||
var result = {
|
const result = {
|
||||||
channel: {
|
channel: {
|
||||||
expected: "string",
|
expected: "string",
|
||||||
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
||||||
@@ -328,7 +330,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("offline", function (msg) {
|
socket.on("offline", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -340,7 +342,7 @@ module.exports = function () {
|
|||||||
typeof msg.status != "boolean" ||
|
typeof msg.status != "boolean" ||
|
||||||
typeof msg.channel != "string"
|
typeof msg.channel != "string"
|
||||||
) {
|
) {
|
||||||
var result = {
|
const result = {
|
||||||
status: {
|
status: {
|
||||||
expected: "boolean",
|
expected: "boolean",
|
||||||
got: msg.hasOwnProperty("status") ? typeof msg.status : undefined
|
got: msg.hasOwnProperty("status") ? typeof msg.status : undefined
|
||||||
@@ -353,8 +355,8 @@ module.exports = function () {
|
|||||||
socket.emit("update_required", result);
|
socket.emit("update_required", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var status = msg.status;
|
const status = msg.status;
|
||||||
var channel = msg.channel;
|
const channel = msg.channel;
|
||||||
if (status) {
|
if (status) {
|
||||||
in_list = false;
|
in_list = false;
|
||||||
offline = true;
|
offline = true;
|
||||||
@@ -374,11 +376,11 @@ module.exports = function () {
|
|||||||
},
|
},
|
||||||
function (err, updated, d) {
|
function (err, updated, d) {
|
||||||
if (d.n == 1) {
|
if (d.n == 1) {
|
||||||
var num = 0;
|
let num = 0;
|
||||||
if (updated && updated.users) {
|
if (updated && updated.users) {
|
||||||
num = updated.users.length;
|
num = updated.users.length;
|
||||||
}
|
}
|
||||||
io.to(coll).emit("viewers", num);
|
ioServer.to(coll).emit("viewers", num);
|
||||||
db.collection("frontpage_lists").update({
|
db.collection("frontpage_lists").update({
|
||||||
_id: coll,
|
_id: coll,
|
||||||
viewers: {
|
viewers: {
|
||||||
@@ -459,7 +461,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("get_history", function (msg) {
|
socket.on("get_history", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -471,7 +473,7 @@ module.exports = function () {
|
|||||||
typeof msg.channel != "string" ||
|
typeof msg.channel != "string" ||
|
||||||
typeof msg.all != "boolean"
|
typeof msg.all != "boolean"
|
||||||
) {
|
) {
|
||||||
var result = {
|
const result = {
|
||||||
all: {
|
all: {
|
||||||
expected: "boolean",
|
expected: "boolean",
|
||||||
got: msg.hasOwnProperty("all") ? typeof msg.all : undefined
|
got: msg.hasOwnProperty("all") ? typeof msg.all : undefined
|
||||||
@@ -493,7 +495,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("chat", function (msg) {
|
socket.on("chat", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -504,7 +506,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("all,chat", function (data) {
|
socket.on("all,chat", function (data) {
|
||||||
if (data.hasOwnProperty("channel") && data.channel.indexOf("?") > -1) {
|
if (data.hasOwnProperty("channel") && data.channel.indexOf("?") > -1) {
|
||||||
var _list = data.channel.substring(0, data.channel.indexOf("?"));
|
const _list = data.channel.substring(0, data.channel.indexOf("?"));
|
||||||
data.channel = _list;
|
data.channel = _list;
|
||||||
}
|
}
|
||||||
if (data.hasOwnProperty("channel")) {
|
if (data.hasOwnProperty("channel")) {
|
||||||
@@ -515,7 +517,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("frontpage_lists", function (msg) {
|
socket.on("frontpage_lists", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -526,7 +528,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("import_zoff", function (msg) {
|
socket.on("import_zoff", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -541,14 +543,14 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("id", function (arr) {
|
socket.on("id", function (arr) {
|
||||||
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
||||||
var _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
const _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
||||||
arr.channel = _list;
|
arr.channel = _list;
|
||||||
}
|
}
|
||||||
if (arr.hasOwnProperty("channel")) {
|
if (arr.hasOwnProperty("channel")) {
|
||||||
arr.channel = Functions.encodeChannelName(arr.channel);
|
arr.channel = Functions.encodeChannelName(arr.channel);
|
||||||
}
|
}
|
||||||
if (typeof arr == "object")
|
if (typeof arr == "object")
|
||||||
io.to(arr.id).emit(arr.id.toLowerCase(), {
|
ioServer.to(arr.id).emit(arr.id.toLowerCase(), {
|
||||||
type: arr.type,
|
type: arr.type,
|
||||||
value: arr.value
|
value: arr.value
|
||||||
});
|
});
|
||||||
@@ -556,7 +558,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("join_silent", function (msg) {
|
socket.on("join_silent", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -569,14 +571,14 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("list", function (msg) {
|
socket.on("list", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
msg.channel = Functions.encodeChannelName(msg.channel);
|
msg.channel = Functions.encodeChannelName(msg.channel);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var _list = msg.channel;
|
let _list = msg.channel;
|
||||||
if (_list.length == 0) return;
|
if (_list.length == 0) return;
|
||||||
if (_list.indexOf("?") > -1) {
|
if (_list.indexOf("?") > -1) {
|
||||||
_list = _list.substring(0, _list.indexOf("?"));
|
_list = _list.substring(0, _list.indexOf("?"));
|
||||||
@@ -596,7 +598,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("end", function (obj) {
|
socket.on("end", function (obj) {
|
||||||
if (obj.hasOwnProperty("channel") && obj.channel.indexOf("?") > -1) {
|
if (obj.hasOwnProperty("channel") && obj.channel.indexOf("?") > -1) {
|
||||||
var _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
const _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
||||||
obj.channel = _list;
|
obj.channel = _list;
|
||||||
}
|
}
|
||||||
if (obj.hasOwnProperty("channel")) {
|
if (obj.hasOwnProperty("channel")) {
|
||||||
@@ -615,7 +617,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("addPlaylist", function (arr) {
|
socket.on("addPlaylist", function (arr) {
|
||||||
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) {
|
||||||
var _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
const _list = arr.channel.substring(0, arr.channel.indexOf("?"));
|
||||||
arr.channel = _list;
|
arr.channel = _list;
|
||||||
}
|
}
|
||||||
if (arr.hasOwnProperty("channel")) {
|
if (arr.hasOwnProperty("channel")) {
|
||||||
@@ -626,7 +628,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("add", function (arr) {
|
socket.on("add", function (arr) {
|
||||||
if (arr.hasOwnProperty("list") && arr.list.indexOf("?") > -1) {
|
if (arr.hasOwnProperty("list") && arr.list.indexOf("?") > -1) {
|
||||||
var _list = arr.list.substring(0, arr.list.indexOf("?"));
|
const _list = arr.list.substring(0, arr.list.indexOf("?"));
|
||||||
arr.list = _list;
|
arr.list = _list;
|
||||||
}
|
}
|
||||||
if (arr.hasOwnProperty("list")) {
|
if (arr.hasOwnProperty("list")) {
|
||||||
@@ -653,7 +655,7 @@ 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) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -671,7 +673,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("vote", function (msg) {
|
socket.on("vote", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -691,7 +693,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("password", function (inp) {
|
socket.on("password", function (inp) {
|
||||||
if (inp.hasOwnProperty("channel") && inp.channel.indexOf("?") > -1) {
|
if (inp.hasOwnProperty("channel") && inp.channel.indexOf("?") > -1) {
|
||||||
var _list = inp.channel.substring(0, inp.channel.indexOf("?"));
|
const _list = inp.channel.substring(0, inp.channel.indexOf("?"));
|
||||||
inp.channel = _list;
|
inp.channel = _list;
|
||||||
}
|
}
|
||||||
if (inp.hasOwnProperty("channel")) {
|
if (inp.hasOwnProperty("channel")) {
|
||||||
@@ -702,7 +704,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("skip", function (list) {
|
socket.on("skip", function (list) {
|
||||||
if (list.hasOwnProperty("channel") && list.channel.indexOf("?") > -1) {
|
if (list.hasOwnProperty("channel") && list.channel.indexOf("?") > -1) {
|
||||||
var _list = list.channel.substring(0, list.channel.indexOf("?"));
|
const _list = list.channel.substring(0, list.channel.indexOf("?"));
|
||||||
list.channel = _list;
|
list.channel = _list;
|
||||||
coll = list.channel;
|
coll = list.channel;
|
||||||
}
|
}
|
||||||
@@ -714,7 +716,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("conf", function (conf) {
|
socket.on("conf", function (conf) {
|
||||||
if (conf.hasOwnProperty("channel") && conf.channel.indexOf("?") > -1) {
|
if (conf.hasOwnProperty("channel") && conf.channel.indexOf("?") > -1) {
|
||||||
var _list = conf.channel.substring(0, conf.channel.indexOf("?"));
|
const _list = conf.channel.substring(0, conf.channel.indexOf("?"));
|
||||||
conf.channel = _list;
|
conf.channel = _list;
|
||||||
coll = conf.channel;
|
coll = conf.channel;
|
||||||
}
|
}
|
||||||
@@ -727,7 +729,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("shuffle", function (msg) {
|
socket.on("shuffle", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -753,7 +755,7 @@ module.exports = function () {
|
|||||||
obj.hasOwnProperty("channel") &&
|
obj.hasOwnProperty("channel") &&
|
||||||
obj.channel.indexOf("?") > -1
|
obj.channel.indexOf("?") > -1
|
||||||
) {
|
) {
|
||||||
var _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
const _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
||||||
obj.channel = _list;
|
obj.channel = _list;
|
||||||
}
|
}
|
||||||
if (obj == undefined && coll == undefined) {
|
if (obj == undefined && coll == undefined) {
|
||||||
@@ -813,7 +815,7 @@ module.exports = function () {
|
|||||||
|
|
||||||
socket.on("left_channel", function (msg) {
|
socket.on("left_channel", function (msg) {
|
||||||
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) {
|
||||||
var _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
const _list = msg.channel.substring(0, msg.channel.indexOf("?"));
|
||||||
msg.channel = _list;
|
msg.channel = _list;
|
||||||
}
|
}
|
||||||
if (msg.hasOwnProperty("channel")) {
|
if (msg.hasOwnProperty("channel")) {
|
||||||
@@ -880,7 +882,7 @@ module.exports = function () {
|
|||||||
obj.hasOwnProperty("channel") &&
|
obj.hasOwnProperty("channel") &&
|
||||||
obj.channel.indexOf("?") > -1
|
obj.channel.indexOf("?") > -1
|
||||||
) {
|
) {
|
||||||
var _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
const _list = obj.channel.substring(0, obj.channel.indexOf("?"));
|
||||||
obj.channel = _list;
|
obj.channel = _list;
|
||||||
}
|
}
|
||||||
if (obj != undefined && obj.hasOwnProperty("channel")) {
|
if (obj != undefined && obj.hasOwnProperty("channel")) {
|
||||||
@@ -900,7 +902,7 @@ module.exports = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!obj.hasOwnProperty("channel") || typeof obj.channel != "string") {
|
if (!obj.hasOwnProperty("channel") || typeof obj.channel != "string") {
|
||||||
var result = {
|
const result = {
|
||||||
channel: {
|
channel: {
|
||||||
expected: "string",
|
expected: "string",
|
||||||
got: obj.hasOwnProperty("channel") ? typeof obj.channel : undefined
|
got: obj.hasOwnProperty("channel") ? typeof obj.channel : undefined
|
||||||
@@ -950,4 +952,9 @@ module.exports = function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
return ioServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
start
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails,
|
handlersPath,
|
||||||
VERSION
|
VERSION
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var ColorThief = require("color-thief-jimp");
|
let ColorThief = require("color-thief-jimp");
|
||||||
var Jimp = require("jimp");
|
let Jimp = require("jimp");
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
let Frontpage = require(handlersPath + "/frontpage.js");
|
||||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
let projects = require(handlersPath + "/aggregates.js");
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var Search = require(pathThumbnails + "/handlers/search.js");
|
let Search = require(handlersPath + "/search.js");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
|
|
||||||
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") {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
var List = require(pathThumbnails + "/handlers/list.js");
|
let List = require(handlersPath + "/list.js");
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
let Frontpage = require(handlersPath + "/frontpage.js");
|
||||||
var Search = require(pathThumbnails + "/handlers/search.js");
|
let Search = require(handlersPath + "/search.js");
|
||||||
var Chat = require(pathThumbnails + "/handlers/chat.js");
|
let Chat = require(handlersPath + "/chat.js");
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
|
|
||||||
function addFromOtherList(arr, guid, offline, socket) {
|
function addFromOtherList(arr, guid, offline, socket) {
|
||||||
if (typeof arr == "object") {
|
if (typeof arr == "object") {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let crypto = require("crypto");
|
||||||
var crypto = require("crypto");
|
let projects = require(handlersPath + "/aggregates.js");
|
||||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
|
||||||
|
|
||||||
function password(inp, coll, guid, offline, socket) {
|
function password(inp, coll, guid, offline, socket) {
|
||||||
var sessionId = Functions.getSession(socket);
|
var sessionId = Functions.getSession(socket);
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
var path = require("path");
|
let path = require("path");
|
||||||
|
|
||||||
function requested_change(type, string, channel) {
|
function requested_change(type, string, channel) {
|
||||||
try {
|
try {
|
||||||
var nodemailer = require("nodemailer");
|
let nodemailer = require("nodemailer");
|
||||||
var mailconfig = require(path.join(__dirname, "../config/mailconfig.js"));
|
let mailconfig = require(path.join(__dirname, "../config/mailconfig.js"));
|
||||||
var transporter = nodemailer.createTransport(mailconfig);
|
let transporter = nodemailer.createTransport(mailconfig);
|
||||||
|
|
||||||
transporter.verify(function (error, success) {
|
transporter.verify(function (error, success) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
var message =
|
let message =
|
||||||
"A " +
|
"A " +
|
||||||
type +
|
type +
|
||||||
" change was requested on <b>" +
|
" change was requested on <b>" +
|
||||||
@@ -19,7 +19,7 @@ function requested_change(type, string, channel) {
|
|||||||
string +
|
string +
|
||||||
"</b><br><br><br> \
|
"</b><br><br><br> \
|
||||||
Go to <a href='https://admin.zoff.me/'>https://admin.zoff.me/</a> to accept or decline the request.";
|
Go to <a href='https://admin.zoff.me/'>https://admin.zoff.me/</a> to accept or decline the request.";
|
||||||
var msg = {
|
let msg = {
|
||||||
from: mailconfig.from,
|
from: mailconfig.from,
|
||||||
to: mailconfig.notify_mail,
|
to: mailconfig.notify_mail,
|
||||||
subject: "ZOFF: Requested new " + type,
|
subject: "ZOFF: Requested new " + type,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
@@ -15,7 +15,7 @@ try {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
var request = require("request");
|
var request = require("request");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(handlersPath + "/db.js");
|
||||||
var countryCodes = ["US", "NO", "SE", "DK", "CA", "EU", "UK"];
|
var countryCodes = ["US", "NO", "SE", "DK", "CA", "EU", "UK"];
|
||||||
|
|
||||||
function check_if_error_or_blocked(id, channel, errored, callback) {
|
function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../settings/globals";
|
||||||
|
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
var Notifications = require(pathThumbnails + "/handlers/notifications.js");
|
let Notifications = require(handlersPath + "/notifications.js");
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
|
|
||||||
function thumbnail(msg, coll, guid, offline, socket) {
|
function thumbnail(msg, coll, guid, offline, socket) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ if (domain.length > 0 && domain[0] == "client") {
|
|||||||
client = true;
|
client = true;
|
||||||
}
|
}
|
||||||
var _VERSION;
|
var _VERSION;
|
||||||
try {
|
|
||||||
_VERSION = localStorage.getItem("VERSION");
|
_VERSION = localStorage.getItem("VERSION");
|
||||||
if (_VERSION == null || _VERSION == undefined) throw "Some error";
|
if (_VERSION == null || _VERSION == undefined) {
|
||||||
} catch (e) {
|
|
||||||
_VERSION = VERSION;
|
_VERSION = VERSION;
|
||||||
}
|
};
|
||||||
|
|
||||||
var SC_widget;
|
var SC_widget;
|
||||||
var scUsingWidget = false;
|
var scUsingWidget = false;
|
||||||
var SC_player;
|
var SC_player;
|
||||||
@@ -197,9 +197,7 @@ window.addEventListener(
|
|||||||
function () {
|
function () {
|
||||||
addDynamicListeners();
|
addDynamicListeners();
|
||||||
if (!_VERSION || parseInt(_VERSION) != VERSION) {
|
if (!_VERSION || parseInt(_VERSION) != VERSION) {
|
||||||
try {
|
localStorage.setItem("VERSION", VERSION);
|
||||||
localStorage.setItem("VERSION", VERSION);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromFront && window.location.pathname != "/") Channel.init();
|
if (!fromFront && window.location.pathname != "/") Channel.init();
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
pathThumbnails,
|
||||||
} from "../settings/globals";
|
handlersPath
|
||||||
|
} from "../../settings/globals";
|
||||||
|
|
||||||
var express = require("express");
|
let express = require("express");
|
||||||
var router = express.Router();
|
let router = express.Router();
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
var mongojs = require("mongojs");
|
let mongojs = require("mongojs");
|
||||||
var token_db = mongojs("tokens");
|
let token_db = mongojs("tokens");
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
let db = require(handlersPath + "/db.js");
|
||||||
var allowed_key;
|
let allowed_key;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
allowed_key = require(pathThumbnails + "/config/allowed_api.js");
|
allowed_key = require(pathThumbnails + "/config/allowed_api.js");
|
||||||
@@ -18,25 +19,25 @@ try {
|
|||||||
"(!) Missing file - /config/allowed_api.js Have a look at /config/allowed_api.example.js."
|
"(!) Missing file - /config/allowed_api.js Have a look at /config/allowed_api.example.js."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
var List = require(pathThumbnails + "/handlers/list.js");
|
let List = require(handlersPath + "/list.js");
|
||||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
let Functions = require(handlersPath + "/functions.js");
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
let Frontpage = require(handlersPath + "/frontpage.js");
|
||||||
var Search = require(pathThumbnails + "/handlers/search.js");
|
let Search = require(handlersPath + "/search.js");
|
||||||
var uniqid = require("uniqid");
|
let uniqid = require("uniqid");
|
||||||
var Filter = require("bad-words");
|
let Filter = require("bad-words");
|
||||||
var filter = new Filter({
|
let filter = new Filter({
|
||||||
placeHolder: "x"
|
placeHolder: "x"
|
||||||
});
|
});
|
||||||
var paginate = require("mongojs-paginate");
|
let paginate = require("mongojs-paginate");
|
||||||
|
|
||||||
var _exports = {
|
let _exports = {
|
||||||
router: router,
|
router: router,
|
||||||
sIO: {}
|
sIO: {}
|
||||||
};
|
};
|
||||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
let projects = require(handlersPath + "/aggregates.js");
|
||||||
|
|
||||||
var error = {
|
let error = {
|
||||||
not_found: {
|
not_found: {
|
||||||
youtube: {
|
youtube: {
|
||||||
status: 404,
|
status: 404,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
pathThumbnails
|
||||||
} from "../settings/globals";
|
} from "../../settings/globals";
|
||||||
|
|
||||||
|
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
pathThumbnails
|
handlersPath
|
||||||
} from "../settings/globals";
|
} from "../../settings/globals";
|
||||||
|
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
@@ -13,9 +13,9 @@ var adsense = "xx";
|
|||||||
var adds = false;
|
var adds = false;
|
||||||
var mongojs = require("mongojs");
|
var mongojs = require("mongojs");
|
||||||
var token_db = mongojs("tokens");
|
var token_db = mongojs("tokens");
|
||||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
var Frontpage = require(handlersPath + "/frontpage.js");
|
||||||
|
|
||||||
var db = require(pathThumbnails + "/handlers/db.js");
|
var db = require(handlersPath + "/db.js");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
google = require(path.join(
|
google = require(path.join(
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import version from "../VERSION";
|
import version from "../VERSION";
|
||||||
|
|
||||||
export const publicPath = path.join(__dirname, "public");
|
export const clientRoutingPath = path.resolve('server', 'routing/client');
|
||||||
|
console.log('rounting path: ', clientRoutingPath);
|
||||||
|
export const publicPath = path.resolve('server', 'public');
|
||||||
|
export const handlersPath = path.resolve('server', "handlers");
|
||||||
export const pathThumbnails = __dirname;
|
export const pathThumbnails = __dirname;
|
||||||
export const VERSION = version;
|
export const VERSION = version;
|
||||||
|
|
||||||
|
function checkCert() {
|
||||||
|
let secure = false;
|
||||||
|
try {
|
||||||
|
const cert_config = require(path.join(
|
||||||
|
__dirname, "../config/cert_config.js"));
|
||||||
|
secure = true;
|
||||||
|
} catch (err) {}
|
||||||
|
return secure;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const certAvailble = checkCert();
|
||||||
Reference in New Issue
Block a user