v1.7.8/release
- Video Listener Optimizations - Auto Leave Fix - Edge support - Admin Dashboard Update - Vimeo & Dailymotion
This commit is contained in:
+24
-24
@@ -1,7 +1,7 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
|
||||
require('https').globalAgent.keepAlive = true;
|
||||
require("https").globalAgent.keepAlive = true;
|
||||
|
||||
let authenticator;
|
||||
let tokenValidator;
|
||||
@@ -19,47 +19,47 @@ let updateAdminOnly;
|
||||
const app = express();
|
||||
app.use(cors({ origin: true }));
|
||||
app.use((req, res, next) => {
|
||||
if (!authenticator) authenticator = require('./authenticator');
|
||||
if (!authenticator) authenticator = require("./authenticator");
|
||||
authenticator(req, res, next);
|
||||
});
|
||||
app.get('/validator/:partyName', (req, res) => {
|
||||
if (!tokenValidator) tokenValidator = require('./tokenValidator');
|
||||
app.get("/validator/:partyName", (req, res) => {
|
||||
if (!tokenValidator) tokenValidator = require("./tokenValidator");
|
||||
tokenValidator(req, res);
|
||||
});
|
||||
app.get('/refresher/:token', (req, res) => {
|
||||
if (!tokenRefresher) tokenRefresher = require('./tokenRefresher');
|
||||
app.get("/refresher/:token", (req, res) => {
|
||||
if (!tokenRefresher) tokenRefresher = require("./tokenRefresher");
|
||||
tokenRefresher(req, res);
|
||||
});
|
||||
app.post('/create', (req, res) => {
|
||||
if (!createRoom) createRoom = require('./createRoom');
|
||||
app.post("/create", (req, res) => {
|
||||
if (!createRoom) createRoom = require("./createRoom");
|
||||
createRoom(req, res);
|
||||
});
|
||||
app.post('/join', (req, res) => {
|
||||
if (!joinRoom) joinRoom = require('./joinRoom');
|
||||
app.post("/join", (req, res) => {
|
||||
if (!joinRoom) joinRoom = require("./joinRoom");
|
||||
joinRoom(req, res);
|
||||
});
|
||||
app.post('/message', (req, res) => {
|
||||
if (!sendMessage) sendMessage = require('./sendMessage');
|
||||
app.post("/message", (req, res) => {
|
||||
if (!sendMessage) sendMessage = require("./sendMessage");
|
||||
sendMessage(req, res);
|
||||
});
|
||||
app.post('/updatePlayer', (req, res) => {
|
||||
if (!updatePlayer) updatePlayer = require('./updatePlayer');
|
||||
app.post("/updatePlayer", (req, res) => {
|
||||
if (!updatePlayer) updatePlayer = require("./updatePlayer");
|
||||
updatePlayer(req, res);
|
||||
});
|
||||
app.post('/updateVoxeet', (req, res) => {
|
||||
if (!updateVoxeet) updateVoxeet = require('./updateVoxeet');
|
||||
app.post("/updateVoxeet", (req, res) => {
|
||||
if (!updateVoxeet) updateVoxeet = require("./updateVoxeet");
|
||||
updateVoxeet(req, res);
|
||||
});
|
||||
app.delete('/leave/:rid/users/:uid', (req, res) => {
|
||||
if (!leaveRoom) leaveRoom = require('./leaveRoom');
|
||||
app.delete("/leave/:rid/users/:uid", (req, res) => {
|
||||
if (!leaveRoom) leaveRoom = require("./leaveRoom");
|
||||
leaveRoom(req, res);
|
||||
});
|
||||
app.delete('/delete/:rid', (req, res) => {
|
||||
if (!deleteRoom) deleteRoom = require('./deleteRoom');
|
||||
app.delete("/delete/:rid", (req, res) => {
|
||||
if (!deleteRoom) deleteRoom = require("./deleteRoom");
|
||||
deleteRoom(req, res);
|
||||
});
|
||||
app.put('/updateAdminOnly/:rid/:adminOnly', (req, res) => {
|
||||
if (!updateAdminOnly) updateAdminOnly = require('./updateAdminOnly');
|
||||
app.put("/updateAdminOnly/:rid/:adminOnly", (req, res) => {
|
||||
if (!updateAdminOnly) updateAdminOnly = require("./updateAdminOnly");
|
||||
updateAdminOnly(req, res);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,59 +1,67 @@
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('modules', 'authenticator');
|
||||
const admin = require("firebase-admin");
|
||||
const Logger = require("../Logger");
|
||||
const mLogger = new Logger("modules", "authenticator");
|
||||
|
||||
module.exports = (req, res, next) => {
|
||||
mLogger.start();
|
||||
res.set('Access-Control-Allow-Origin', ['*']);
|
||||
if (req.url === '/') {
|
||||
mLogger.success('HEARTBEAT', { URL: req.url });
|
||||
res.status(200).send({ message: 'ALIVE' });
|
||||
res.set("Access-Control-Allow-Origin", ["*"]);
|
||||
if (req.url === "/") {
|
||||
mLogger.success("HEARTBEAT", { URL: req.url });
|
||||
res.status(200).send({ message: "ALIVE" });
|
||||
return next();
|
||||
}
|
||||
if (req.method === 'OPTIONS') {
|
||||
mLogger.success('OPTIONS CALL', { URL: req.url });
|
||||
if (req.method === "OPTIONS") {
|
||||
mLogger.success("OPTIONS CALL", { URL: req.url });
|
||||
res.status(200).send();
|
||||
return next();
|
||||
}
|
||||
if (req.headers.authorization) {
|
||||
try {
|
||||
const token = req.headers.authorization.split(' ')[1];
|
||||
const reqToken = token.split(':')[0];
|
||||
const reqUid = token.split(':')[1];
|
||||
const token = req.headers.authorization.split(" ")[1];
|
||||
const reqToken = token.split(":")[0];
|
||||
const reqUid = token.split(":")[1];
|
||||
admin
|
||||
.auth()
|
||||
.verifyIdToken(reqToken)
|
||||
.then((user) => {
|
||||
if (user.uid === reqUid) {
|
||||
if (req.method === 'POST') {
|
||||
if (req.method === "POST") {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
bodydata.uid = user.uid;
|
||||
req.body = JSON.stringify(bodydata);
|
||||
}
|
||||
if (req.method === 'GET' || req.method === 'DELETE' || req.method === 'PUT') {
|
||||
if (
|
||||
req.method === "GET" ||
|
||||
req.method === "DELETE" ||
|
||||
req.method === "PUT"
|
||||
) {
|
||||
req.body = JSON.stringify({ uid: user.uid });
|
||||
}
|
||||
mLogger.success('AUTHORIZED', { URL: req.url, UID: reqUid });
|
||||
mLogger.success("AUTHORIZED", { URL: req.url, UID: reqUid });
|
||||
return next();
|
||||
} else {
|
||||
mLogger.success('NOT AUTHORIZED', { URL: req.url });
|
||||
return res.status(401).send({ message: 'Unauthorized' });
|
||||
mLogger.success("NOT AUTHORIZED", { URL: req.url });
|
||||
return res.status(401).send({ message: "Unauthorized" });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('AUTH VALIDATE FIREBASE ERROR', {
|
||||
mLogger.error("AUTH VALIDATE FIREBASE ERROR", {
|
||||
URL: req.url,
|
||||
Error: err,
|
||||
});
|
||||
return res.status(500).send({ message: 'Unable to verify user token' });
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: "Unable to verify user token" });
|
||||
});
|
||||
} catch (err) {
|
||||
mLogger.error('AUTH VALIDATE ERROR', { URL: req.url, Error: err });
|
||||
return res.status(401).send({ message: 'Something went wrong when authorizing' });
|
||||
mLogger.error("AUTH VALIDATE ERROR", { URL: req.url, Error: err });
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: "Something went wrong when authorizing" });
|
||||
}
|
||||
} else {
|
||||
mLogger.error('NO AUTH TOKEN', { URL: req.url });
|
||||
res.status(401).send({ message: 'Got no user token' });
|
||||
mLogger.error("NO AUTH TOKEN", { URL: req.url });
|
||||
res.status(401).send({ message: "Got no user token" });
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const admin = require('firebase-admin');
|
||||
const admin = require("firebase-admin");
|
||||
|
||||
const partyNameHasInvalidChar = (partyName) =>
|
||||
/\\/gi.test(partyName) || /\//gi.test(partyName) || /\./gi.test(partyName);
|
||||
@@ -7,32 +7,36 @@ const isValidPin = (pin) => /^.*[0-9].{2}$/.test(pin);
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
console.log('Requested Create - UID - ', bodydata.uid);
|
||||
console.log("Requested Create - UID - ", bodydata.uid);
|
||||
if (!bodydata.userName) {
|
||||
return res.status(400).send({ message: 'Missing user name' });
|
||||
return res.status(400).send({ message: "Missing user name" });
|
||||
} else if (!bodydata.partyName) {
|
||||
return res.status(400).send({ message: 'Missing party name' });
|
||||
return res.status(400).send({ message: "Missing party name" });
|
||||
} else if (!bodydata.partyPin) {
|
||||
return res.status(400).send({ message: 'Missing party pin' });
|
||||
return res.status(400).send({ message: "Missing party pin" });
|
||||
} else if (partyNameHasInvalidChar(bodydata.partyName)) {
|
||||
res.status(400).send({ message: 'Party name can not have "\\" or "/" or "."' });
|
||||
} else if (!isValidPin(bodydata.partyPin)) {
|
||||
return res
|
||||
res
|
||||
.status(400)
|
||||
.send({ message: 'Party pin can only have digits and must be atleast 3 digits' });
|
||||
.send({ message: 'Party name can not have "\\" or "/" or "."' });
|
||||
} else if (!isValidPin(bodydata.partyPin)) {
|
||||
return res.status(400).send({
|
||||
message: "Party pin can only have digits and must be atleast 3 digits",
|
||||
});
|
||||
} else {
|
||||
const roomNameTaken = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName.replace('/', '\\'))
|
||||
.collection("rooms")
|
||||
.doc(bodydata.partyName.replace("/", "\\"))
|
||||
.get()
|
||||
.then((docSnap) => docSnap.exists);
|
||||
if (roomNameTaken) {
|
||||
return res.status(409).send({ message: 'That party name is already taken' });
|
||||
return res
|
||||
.status(409)
|
||||
.send({ message: "That party name is already taken" });
|
||||
} else {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(bodydata.partyName)
|
||||
.set({
|
||||
name: bodydata.partyName,
|
||||
@@ -41,19 +45,20 @@ module.exports = async (req, res) => {
|
||||
createdAt: new Date(),
|
||||
adminUid: bodydata.uid,
|
||||
adminOnly: bodydata.adminOnly,
|
||||
publicParty: !!bodydata.publicParty,
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
res.status(500).send({ message: "Unable to start party." });
|
||||
console.error(err);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(bodydata.partyName)
|
||||
.collection('messages')
|
||||
.collection("messages")
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
uid: "<system>",
|
||||
name: "",
|
||||
text: `${bodydata.userName} started the party.`,
|
||||
time: new Date(),
|
||||
})
|
||||
@@ -65,9 +70,9 @@ module.exports = async (req, res) => {
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(bodydata.partyName)
|
||||
.collection('users')
|
||||
.collection("users")
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: true,
|
||||
@@ -79,7 +84,9 @@ module.exports = async (req, res) => {
|
||||
err
|
||||
);
|
||||
});
|
||||
return res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
||||
return res
|
||||
.status(201)
|
||||
.send({ roomId: bodydata.partyName, message: "Started a party!" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user