v1.6.2/admin dashboard
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
const superAuth = require('./superAuth');
|
||||
const partyDashboard = require('./partyDashboard');
|
||||
const serverDashboard = require('./serverDashboard');
|
||||
const updateVersionActive = require('./updateVersionActive');
|
||||
const updateVideoSelectors = require('./updateVideoSelectors');
|
||||
|
||||
module.exports = {
|
||||
updateVideoSelectors,
|
||||
updateVersionActive,
|
||||
serverDashboard,
|
||||
partyDashboard,
|
||||
superAuth,
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
/* eslint-disable promise/no-nesting */
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('admin', 'partyDashboard');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
mLogger.start();
|
||||
|
||||
var partyData = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.get()
|
||||
.then((roomSnapshot) => {
|
||||
const docData = [];
|
||||
roomSnapshot.docs.forEach((doc) => {
|
||||
docData.push({
|
||||
id: doc.id,
|
||||
createTime: doc.createTime.toDate().toUTCString(),
|
||||
updateTime: doc.updateTime.toDate().toUTCString(),
|
||||
source: doc.data().player.source,
|
||||
onCall: doc.data().hasOwnProperty('conference'),
|
||||
showName: doc.data().player.showName || '',
|
||||
time: doc.data().player.time || 0,
|
||||
status: doc.data().player.status || '',
|
||||
});
|
||||
});
|
||||
return docData;
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('FAILED TO RESOLVE PARTIES', err);
|
||||
res.status(500).send({ message: 'Unable to get all parties', error: err });
|
||||
});
|
||||
|
||||
await partyData.forEach((party) => {
|
||||
const messageCount = admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(party.id)
|
||||
.collection('messages')
|
||||
.get()
|
||||
.then((snap) => snap.size);
|
||||
const userCount = admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(party.id)
|
||||
.collection('users')
|
||||
.get()
|
||||
.then((snap) => snap.size);
|
||||
party.messageCount = messageCount || 0;
|
||||
party.userCount = userCount || 0;
|
||||
});
|
||||
|
||||
mLogger.success('GOT ALL PARTIES', { parties: partyData.length });
|
||||
return res.status(200).send({ partyData });
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('admin', 'serverDashboard');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
mLogger.start();
|
||||
|
||||
const serverData = await admin
|
||||
.firestore()
|
||||
.collection('server')
|
||||
.doc('status')
|
||||
.get()
|
||||
.then((snap) => {
|
||||
const status = snap.data();
|
||||
const { nameSelectors, selectors } = status;
|
||||
delete status.nameSelectors;
|
||||
delete status.selectors;
|
||||
const versions = Object.keys(status).map((v) =>
|
||||
Object.assign({ version: v.split('').join('.') }, status[v])
|
||||
);
|
||||
return { nameSelectors, selectors, versions };
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('FAILED TO RESOLVE SERVER', err);
|
||||
res.status(500).send({ message: 'Unable to get all parties', error: err });
|
||||
});
|
||||
|
||||
mLogger.success('GOT ALL SERVER STATUS');
|
||||
return res.status(200).send({ serverData });
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('admin', 'superAuth');
|
||||
|
||||
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.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];
|
||||
admin
|
||||
.auth()
|
||||
.verifyIdToken(reqToken)
|
||||
.then((user) => {
|
||||
if (user.uid === 'cgEJNxHVFxTeCCeWnAiNyalaFax1' && user.uid === reqUid) {
|
||||
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') {
|
||||
req.body = JSON.stringify({ uid: user.uid });
|
||||
}
|
||||
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' });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
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' });
|
||||
}
|
||||
} else {
|
||||
mLogger.error('NO AUTH TOKEN', { URL: req.url });
|
||||
res.status(401).send({ message: 'Got no user token' });
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('admin', 'updateVersionActive');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
mLogger.start();
|
||||
const { version, versionData } = JSON.parse(req.body);
|
||||
if (version && versionData) {
|
||||
delete versionData.version;
|
||||
if (versionData.importantAlert === null || versionData.importantAlert === undefined) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('server')
|
||||
.doc('status')
|
||||
.update({
|
||||
[`${version}.importantUpdate`]: admin.firestore.FieldValue.delete(),
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('FAILED TO DELETE IMPORTANT ALERT', err);
|
||||
res.status(500).send({ message: 'FAILED TO DELETE IMPORTANT ALERT', error: err });
|
||||
});
|
||||
delete versionData.importantAlert;
|
||||
}
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('server')
|
||||
.doc('status')
|
||||
.update({
|
||||
[version]: versionData,
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('FAILED TO UPDATE', err);
|
||||
res.status(500).send({ message: 'FAILED TO UPDATE', error: err });
|
||||
});
|
||||
mLogger.success('UPDATE VERSION ACTIVE STATUS', Object.assign(versionData, versionData));
|
||||
res.status(200).send({ message: 'Updated version active' });
|
||||
} else {
|
||||
mLogger.error('VALUES NOT RECEIVED');
|
||||
res.status(500).send({ message: 'Values not received' });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
const admin = require('firebase-admin');
|
||||
const Logger = require('../Logger');
|
||||
const mLogger = new Logger('admin', 'updateVideoSelectors');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
mLogger.start();
|
||||
const { selectors } = JSON.parse(req.body);
|
||||
if (selectors) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('server')
|
||||
.doc('status')
|
||||
.update({
|
||||
selectors,
|
||||
})
|
||||
.catch((err) => {
|
||||
mLogger.error('FAILED TO UPDATE', err);
|
||||
res.status(500).send({ message: 'FAILED TO UPDATE', error: err });
|
||||
});
|
||||
mLogger.success('UPDATED SELECTORS');
|
||||
res.status(200).send({ message: 'Updated video selectors' });
|
||||
} else {
|
||||
mLogger.error('VALUES NOT RECEIVED');
|
||||
res.status(500).send({ message: 'Values not received' });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user