This commit is contained in:
afrokick 2019-04-01 14:45:37 +03:00
parent 7e2b854f09
commit d559ae50c6
2 changed files with 8 additions and 32 deletions

View File

@ -1,10 +1,15 @@
const config = require('../../../../config');
const realm = require('../../../services/realm'); const realm = require('../../../services/realm');
module.exports = (req, res, next) => { module.exports = (req, res, next) => {
const { id, token } = req.params; const { id, token, key } = req.params;
const sendAuthError = () => res.sendStatus(401); const sendAuthError = () => res.sendStatus(401);
if (key !== config.get('key')) {
return sendAuthError();
}
if (!id) { if (!id) {
return next(); return next();
} }

View File

@ -8,14 +8,9 @@ const randomId = () => {
return (Math.random().toString(36) + '0000000000000000000').substr(2, 16); return (Math.random().toString(36) + '0000000000000000000').substr(2, 16);
}; };
const generateClientId = (key) => { const generateClientId = () => {
let clientId = randomId(); let clientId = randomId();
const realm = realmsCache.getRealmByKey(key);
if (!realm) {
return clientId;
}
while (realm.getClientById(clientId)) { while (realm.getClientById(clientId)) {
clientId = randomId(); clientId = randomId();
} }
@ -25,10 +20,8 @@ const generateClientId = (key) => {
// Retrieve guaranteed random ID. // Retrieve guaranteed random ID.
app.get('/id', (req, res, next) => { app.get('/id', (req, res, next) => {
const { key } = req.params;
res.contentType = 'text/html'; res.contentType = 'text/html';
res.send(generateClientId(key)); res.send(generateClientId());
}); });
// Get a list of all peers for a key, enabled by the `allowDiscovery` flag. // Get a list of all peers for a key, enabled by the `allowDiscovery` flag.
@ -41,25 +34,3 @@ app.get('/peers', (req, res, next) => {
res.sendStatus(401); res.sendStatus(401);
}); });
// Server sets up HTTP streaming when you get post an ID.
// app.post('/:id/:token/id', (req, res, next) => {
// var id = req.params.id;
// var token = req.params.token;
// var key = req.params.key;
// var ip = req.connection.remoteAddress;
// if (!self._clients[key] || !self._clients[key][id]) {
// self._checkKey(key, ip, function (err) {
// if (!err && !self._clients[key][id]) {
// self._clients[key][id] = { token: token, ip: ip };
// self._ips[ip]++;
// self._startStreaming(res, key, id, token, true);
// } else {
// res.send(JSON.stringify({ type: 'HTTP-ERROR' }));
// }
// });
// } else {
// self._startStreaming(res, key, id, token);
// }
// });