v1.6.1/dynamic video selectors

This commit is contained in:
2020-08-13 19:21:53 -04:00
parent 8530f4e727
commit 3c4fffe598
4 changed files with 265 additions and 381 deletions
+27 -35
View File
@@ -1,27 +1,21 @@
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,
@@ -32,17 +26,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(),
})
@@ -54,9 +48,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,
@@ -68,26 +62,24 @@ module.exports = async (req, res) => {
err
);
});
if (bodydata.player && bodydata.player.source === "amazon.") {
if (
bodydata.player &&
(bodydata.player.source === 'amazon.' || bodydata.player.source === 'hulu.')
) {
await admin
.firestore()
.collection("rooms")
.collection('rooms')
.doc(bodydata.partyName)
.collection("messages")
.collection('messages')
.add({
uid: "<system>",
name: "",
text: `Watch Party may not work with Prime Video temporarily. An update is coming to fix this.`,
uid: '<system>',
name: '',
text: `Watch Party may not work 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
);
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!" });
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
};