v1.6.0/admin only mode
This commit is contained in:
@@ -16,6 +16,7 @@ app.post('/updatePlayer', FunctionModules.updatePlayer);
|
||||
app.post('/updateVoxeet', FunctionModules.updateVoxeet);
|
||||
app.delete('/leave/:rid/users/:uid', FunctionModules.leaveRoom);
|
||||
app.delete('/delete/:rid', FunctionModules.deleteRoom);
|
||||
app.put('/updateAdminOnly/:rid/:adminOnly', FunctionModules.updateAdminOnly);
|
||||
|
||||
// VERSION 2
|
||||
const app2 = express();
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = (req, res, next) => {
|
||||
bodydata.uid = user.uid;
|
||||
req.body = JSON.stringify(bodydata);
|
||||
}
|
||||
if (req.method === 'GET' || req.method === 'DELETE') {
|
||||
if (req.method === 'GET' || req.method === 'DELETE' || req.method === 'PUT') {
|
||||
req.body = JSON.stringify({ uid: user.uid });
|
||||
}
|
||||
return next();
|
||||
|
||||
@@ -24,6 +24,7 @@ module.exports = async (req, res) => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
adminUid: bodydata.uid,
|
||||
adminOnly: bodydata.adminOnly,
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
@@ -46,23 +47,6 @@ module.exports = async (req, res) => {
|
||||
err
|
||||
);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `Voice calls are unavailable temporarily. Voice calls will be back within 12 hours.`,
|
||||
time: new Date(),
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to add system voice call message : \n\t Room: ${bodydata.partyName}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
|
||||
@@ -2,7 +2,6 @@ const admin = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
console.log('Requested Delete - Room - ', req.params.rid);
|
||||
console.log(req.body);
|
||||
const isAdmin = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
|
||||
@@ -11,6 +11,7 @@ const updatePlayer = require('./updatePlayer');
|
||||
const tokenValidator = require('./tokenValidator');
|
||||
const tokenRefresher = require('./tokenRefresher');
|
||||
const updateVoxeet = require('./updateVoxeet');
|
||||
const updateAdminOnly = require('./updateAdminOnly');
|
||||
|
||||
module.exports = {
|
||||
authenticator,
|
||||
@@ -26,4 +27,5 @@ module.exports = {
|
||||
tokenValidator,
|
||||
tokenRefresher,
|
||||
updateVoxeet,
|
||||
updateAdminOnly,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const admin = require('firebase-admin');
|
||||
const { firestore } = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
@@ -137,7 +136,7 @@ module.exports = async (req, res) => {
|
||||
.update({
|
||||
player: {
|
||||
showName: null,
|
||||
source: null,
|
||||
source: bodydata.source,
|
||||
status: 'NOT_PLAYING',
|
||||
time: 0,
|
||||
updatedBy: bodydata.uid,
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
const VoxeetSecret = require('../VoxeetSecret.json');
|
||||
module.exports = async (req, res) => {
|
||||
res.status(403).send({ message: 'Voice calls are unavailable temporarily.' });
|
||||
// const { key, secret } = VoxeetSecret;
|
||||
// const credentials = btoa(encodeURI(key) + ':' + encodeURI(secret));
|
||||
// const headers = {
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Cache-Control': 'no-cache',
|
||||
// Authorization: 'Basic ' + credentials,
|
||||
// };
|
||||
// const oauth = await fetch(VoxeetSecret.refreshURL, {
|
||||
// method: 'POST',
|
||||
// headers,
|
||||
// body: JSON.stringify({
|
||||
// refresh_token: req.params.token,
|
||||
// }),
|
||||
// })
|
||||
// .then((oauthResponse) => oauthResponse.json())
|
||||
// .catch((err) => res.status(500).send(err));
|
||||
// if (oauth) res.status(200).send(oauth);
|
||||
const { key, secret } = VoxeetSecret;
|
||||
const credentials = btoa(encodeURI(key) + ':' + encodeURI(secret));
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
Authorization: 'Basic ' + credentials,
|
||||
};
|
||||
const oauth = await fetch(VoxeetSecret.refreshURL, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
refresh_token: req.params.token,
|
||||
}),
|
||||
})
|
||||
.then((oauthResponse) => oauthResponse.json())
|
||||
.catch((err) => res.status(500).send(err));
|
||||
if (oauth) res.status(200).send(oauth);
|
||||
};
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
const VoxeetSecret = require('../VoxeetSecret.json');
|
||||
const fetch = require('node-fetch');
|
||||
module.exports = async (req, res) => {
|
||||
res.status(403).send({ message: 'Voice calls are unavailable temporarily.' });
|
||||
// const { key, secret } = VoxeetSecret;
|
||||
// const credentials = Buffer.from(encodeURI(key) + ':' + encodeURI(secret)).toString('base64');
|
||||
// const headers = {
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Cache-Control': 'no-cache',
|
||||
// Authorization: 'Basic ' + credentials,
|
||||
// };
|
||||
// const oauth = await fetch(VoxeetSecret.validateURL, {
|
||||
// method: 'POST',
|
||||
// headers,
|
||||
// body: JSON.stringify({
|
||||
// grant_type: 'client_credentials',
|
||||
// }),
|
||||
// })
|
||||
// .then((oauthResponse) => oauthResponse.json())
|
||||
// .catch((err) => res.status(500).send(err));
|
||||
// if (oauth) res.status(200).send(oauth);
|
||||
const { key, secret } = VoxeetSecret;
|
||||
const credentials = Buffer.from(encodeURI(key) + ':' + encodeURI(secret)).toString('base64');
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
Authorization: 'Basic ' + credentials,
|
||||
};
|
||||
const oauth = await fetch(VoxeetSecret.validateURL, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
grant_type: 'client_credentials',
|
||||
}),
|
||||
})
|
||||
.then((oauthResponse) => oauthResponse.json())
|
||||
.catch((err) => res.status(500).send(err));
|
||||
if (oauth) res.status(200).send(oauth);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
const admin = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
const isAdmin = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.rid)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.get()
|
||||
.then((v) => {
|
||||
if (v.exists) {
|
||||
return v.data().admin;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.err('Failed to get party to update adminOnly', err);
|
||||
return res.status(404).send({ message: 'Failed to get party.' });
|
||||
});
|
||||
if (!isAdmin) {
|
||||
console.log('[UNAUTHORIZED] Requested Admin Mode Update - Room - ', req.params.rid);
|
||||
res.status(401).send({ message: 'Not authorized to update admin only mode for this party.' });
|
||||
return;
|
||||
}
|
||||
const adminOnly = req.params.adminOnly === 'true';
|
||||
await admin.firestore().collection('rooms').doc(req.params.rid).update({
|
||||
adminOnly
|
||||
}).catch((err) => {
|
||||
console.err('Failed to update adminOnly for party', err);
|
||||
res.status(409).send({ message: 'Failed to update party.' });
|
||||
});
|
||||
res.status(200).send({ message: 'Updated admin only mode for party' });
|
||||
return;
|
||||
};
|
||||
@@ -14,6 +14,7 @@ module.exports = async (req, res) => {
|
||||
// player.time > 3600
|
||||
// ? new Date(player.time * 1000).toISOString().substr(11, 8)
|
||||
// : new Date(player.time * 1000).toISOString().substr(14, 5);
|
||||
if (!roomId) return res.status(204).send({ message: 'Party name not sent.' });
|
||||
const [roomExists, roomData] = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
@@ -30,7 +31,7 @@ module.exports = async (req, res) => {
|
||||
.get()
|
||||
.then((userSnap) => userSnap.exists);
|
||||
if (userExists) {
|
||||
if (showChanged === true) {
|
||||
if (showChanged === true && player.showName) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
|
||||
Generated
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "watch-party-api",
|
||||
"version": "1.2.1",
|
||||
"version": "1.6.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -1909,9 +1909,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
"version": "4.17.19",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
|
||||
},
|
||||
"lodash.at": {
|
||||
"version": "4.6.0",
|
||||
|
||||
Reference in New Issue
Block a user