[mirotalk] - rollback

This commit is contained in:
Miroslav Pejic
2022-01-30 12:31:00 +01:00
parent f44657e7d7
commit 1d98f9c3f9
2 changed files with 12 additions and 33 deletions
+12 -5
View File
@@ -77,6 +77,7 @@ const ngrok = require('ngrok');
const yamlJS = require('yamljs');
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = yamlJS.load(path.join(__dirname + '/../api/swagger.yaml'));
const { v4: uuidV4 } = require('uuid');
const apiBasePath = '/api/v1'; // api endpoint path
const api_docs = host + apiBasePath + '/docs'; // api docs
@@ -88,7 +89,6 @@ const turnUrls = process.env.TURN_URLS;
const turnUsername = process.env.TURN_USERNAME;
const turnCredential = process.env.TURN_PASSWORD;
const ServerApi = require('./ServerApi');
const Logger = require('./Logger');
const log = new Logger('server');
@@ -190,10 +190,8 @@ app.use(apiBasePath + '/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)
// request meeting room endpoint
app.post([apiBasePath + '/meeting'], (req, res) => {
// check if user was authorized for the api call
let host = req.headers.host;
let authorization = req.headers.authorization;
const api = new ServerApi(host, authorization, api_key_secret);
if (!api.isAuthorized()) {
if (authorization != api_key_secret) {
log.debug('MiroTalk get meeting - Unauthorized', {
header: req.headers,
body: req.body,
@@ -201,7 +199,8 @@ app.post([apiBasePath + '/meeting'], (req, res) => {
return res.status(403).json({ error: 'Unauthorized!' });
}
// setup meeting URL
let meetingURL = api.getMeetingURL();
let host = req.headers.host;
let meetingURL = getMeetingURL(host);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ meeting: meetingURL }));
@@ -213,6 +212,14 @@ app.post([apiBasePath + '/meeting'], (req, res) => {
});
});
/**
* Request meeting room endpoint
* @returns entrypoint / Room URL for your meeting.
*/
function getMeetingURL(host) {
return 'http' + (host.includes('localhost') ? '' : 's') + '://' + host + '/join/' + uuidV4();
}
// end of MiroTalk API v1
// not match any of page before, so 404 not found
-28
View File
@@ -1,28 +0,0 @@
'use strict';
const { v4: uuidV4 } = require('uuid');
module.exports = class ServerApi {
constructor(host, authorization, api_key_secret) {
this._host = host;
this._authorization = authorization;
this._api_key_secret = api_key_secret;
}
/**
* Check if user is authorized
* @returns true/false
*/
isAuthorized() {
if (this._authorization != this._api_key_secret) return false;
return true;
}
/**
* Request meeting room endpoint
* @returns entrypoint / Room URL for your meeting.
*/
getMeetingURL() {
return 'http' + (this._host.includes('localhost') ? '' : 's') + '://' + this._host + '/join/' + uuidV4();
}
};