v1.6.1/release

-amazon fix
-play movies fix
This commit is contained in:
2020-08-12 10:39:39 -04:00
parent e1cc9fa6f5
commit 0de3788e13
10 changed files with 410 additions and 267 deletions
+31 -20
View File
@@ -1,51 +1,62 @@
const admin = require('firebase-admin');
const Logger = require('../Logger');
const mLogger = 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.method === 'OPTIONS') {
mLogger.success('OPTIONS CALL', { URL: req.url });
res.set("Access-Control-Allow-Origin", ["*"]);
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', { URL: req.url, Error: err });
return res.status(500).send({ message: 'Unable to verify user token' });
mLogger.error("AUTH VALIDATE FIREBASE ERROR", {
URL: req.url,
Error: err,
});
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;
};
+44 -17
View File
@@ -1,21 +1,27 @@
const admin = require('firebase-admin');
const admin = require("firebase-admin");
module.exports = async (req, res) => {
const bodydata = JSON.parse(req.body);
console.log('Requested Create - UID - ', bodydata.uid);
if (!bodydata.userName) res.status(400).send({ message: 'Missing user name' });
if (!bodydata.partyName) res.status(400).send({ message: 'Missing party name' });
if (!bodydata.partyPin) res.status(400).send({ message: 'Missing party pin' });
console.log("Requested Create - UID - ", bodydata.uid);
if (!bodydata.userName)
res.status(400).send({ message: "Missing user name" });
if (!bodydata.partyName)
res.status(400).send({ message: "Missing party name" });
if (!bodydata.partyPin)
res.status(400).send({ message: "Missing party pin" });
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' });
if (roomNameTaken)
return res
.status(409)
.send({ message: "That party name is already taken" });
await admin
.firestore()
.collection('rooms')
.collection("rooms")
.doc(bodydata.partyName)
.set({
name: bodydata.partyName,
@@ -26,17 +32,17 @@ module.exports = async (req, res) => {
adminOnly: bodydata.adminOnly,
})
.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(),
})
@@ -48,9 +54,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,
@@ -62,5 +68,26 @@ module.exports = async (req, res) => {
err
);
});
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
if (bodydata.player && bodydata.player.source === "amazon.") {
await admin
.firestore()
.collection("rooms")
.doc(bodydata.partyName)
.collection("messages")
.add({
uid: "<system>",
name: "",
text: `Watch Party may not work with Prime Video temporarily. An update is coming to fix this.`,
time: new Date(),
})
.catch((err) => {
console.error(
`Failed to add amazon error message : \n\t Room: ${bodydata.partyName}`,
err
);
});
}
res
.status(201)
.send({ roomId: bodydata.partyName, message: "Started a party!" });
};