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