Добавлена возможность доступа по паролю

This commit is contained in:
Book Pauk
2022-09-26 17:27:45 +07:00
parent afef0ed04c
commit 0b6b014d5f
12 changed files with 358 additions and 58 deletions

View File

@@ -13,6 +13,9 @@ class WebSocketController {
constructor(wss, config) {
this.config = config;
this.isDevelopment = (config.branch == 'development');
this.accessToken = '';
if (config.accessPassword)
this.accessToken = utils.getBufHash(config.accessPassword, 'sha256', 'hex');
this.workerState = new WorkerState();
this.webWorker = new WebWorker(config);
@@ -59,6 +62,11 @@ class WebSocketController {
//pong for WebSocketConnection
this.send({_rok: 1}, req, ws);
if (this.accessToken && req.accessToken !== this.accessToken) {
await utils.sleep(1000);
throw new Error('need_access_token');
}
switch (req.action) {
case 'test':
await this.test(req, ws); break;