v1.7.6/release
- website optimization - new assets - server catches
This commit is contained in:
@@ -10,76 +10,76 @@ module.exports = async (req, res) => {
|
||||
console.log('Requested Create - UID - ', bodydata.uid);
|
||||
if (!bodydata.userName) {
|
||||
return res.status(400).send({ message: 'Missing user name' });
|
||||
}
|
||||
if (!bodydata.partyName) {
|
||||
} else if (!bodydata.partyName) {
|
||||
return res.status(400).send({ message: 'Missing party name' });
|
||||
}
|
||||
if (!bodydata.partyPin) {
|
||||
} else if (!bodydata.partyPin) {
|
||||
return res.status(400).send({ message: 'Missing party pin' });
|
||||
}
|
||||
if (partyNameHasInvalidChar(bodydata.partyName)) {
|
||||
} else if (partyNameHasInvalidChar(bodydata.partyName)) {
|
||||
res.status(400).send({ message: 'Party name can not have "\\" or "/" or "."' });
|
||||
}
|
||||
if (!isValidPin(bodydata.partyPin)) {
|
||||
} 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('/', '\\'))
|
||||
.get()
|
||||
.then((docSnap) => docSnap.exists);
|
||||
if (roomNameTaken) {
|
||||
return res.status(409).send({ message: 'That party name is already taken' });
|
||||
} else {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.set({
|
||||
name: bodydata.partyName,
|
||||
pin: bodydata.partyPin,
|
||||
player: bodydata.player,
|
||||
createdAt: new Date(),
|
||||
adminUid: bodydata.uid,
|
||||
adminOnly: bodydata.adminOnly,
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
console.error(err);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `${bodydata.userName} started the party.`,
|
||||
time: new Date(),
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to add system create party message : \n\t Room: ${bodydata.partyName}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: true,
|
||||
name: bodydata.userName,
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to set admin when creating party : \n\t Room: ${bodydata.partyName} \n\t User: ${bodydata.uid}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
return res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
||||
}
|
||||
}
|
||||
const roomNameTaken = await admin
|
||||
.firestore()
|
||||
.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' });
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.set({
|
||||
name: bodydata.partyName,
|
||||
pin: bodydata.partyPin,
|
||||
player: bodydata.player,
|
||||
createdAt: new Date(),
|
||||
adminUid: bodydata.uid,
|
||||
adminOnly: bodydata.adminOnly,
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
console.error(err);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `${bodydata.userName} started the party.`,
|
||||
time: new Date(),
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to add system create party message : \n\t Room: ${bodydata.partyName}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: true,
|
||||
name: bodydata.userName,
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to set admin when creating party : \n\t Room: ${bodydata.partyName} \n\t User: ${bodydata.uid}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
||||
};
|
||||
|
||||
@@ -2,39 +2,43 @@ const admin = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
console.log('Requested Leave - UID - ', req.params.uid, '\n\tRoom - ', req.params.rid);
|
||||
if (req.params.uid === 'undefined') return res.status(400).send({ message: 'No UID' });
|
||||
if (req.params.rid === 'undefined') return res.status(400).send({ message: 'No Party Name' });
|
||||
const userName = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('users')
|
||||
.doc(req.params.uid)
|
||||
.get()
|
||||
.then((userSnap) => userSnap.data().name);
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('users')
|
||||
.doc(req.params.uid)
|
||||
.delete()
|
||||
.catch((err) =>
|
||||
console.error(
|
||||
`Failed to remove user from party : \n\t Room: ${req.params.rid} \n\t User: ${req.params.uid}`,
|
||||
err
|
||||
)
|
||||
);
|
||||
admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
time: new Date(),
|
||||
name: '',
|
||||
text: `${userName} left the party.`,
|
||||
});
|
||||
res.status(200).send({ message: 'Left the party' });
|
||||
if (req.params.uid === 'undefined') {
|
||||
return res.status(400).send({ message: 'No UID' });
|
||||
} else if (req.params.rid === 'undefined') {
|
||||
return res.status(400).send({ message: 'No Party Name' });
|
||||
} else {
|
||||
const userName = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('users')
|
||||
.doc(req.params.uid)
|
||||
.get()
|
||||
.then((userSnap) => userSnap.data().name);
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('users')
|
||||
.doc(req.params.uid)
|
||||
.delete()
|
||||
.catch((err) =>
|
||||
console.error(
|
||||
`Failed to remove user from party : \n\t Room: ${req.params.rid} \n\t User: ${req.params.uid}`,
|
||||
err
|
||||
)
|
||||
);
|
||||
admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
time: new Date(),
|
||||
name: '',
|
||||
text: `${userName} left the party.`,
|
||||
});
|
||||
return res.status(200).send({ message: 'Left the party' });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user