From aa436feae745cfd51786b17d6dc6c2b038d08a96 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 28 Nov 2022 15:15:55 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=83=D0=BF=D0=B0=20=D0=B2=20=D1=80=D0=B5=D0=B6=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=20"=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D0=B0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/RemoteLib.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/core/RemoteLib.js b/server/core/RemoteLib.js index 0ab0c8e..2a8d2a4 100644 --- a/server/core/RemoteLib.js +++ b/server/core/RemoteLib.js @@ -16,8 +16,6 @@ class RemoteLib { this.config = config; this.wsc = new WebSocketConnection(config.remoteLib.url, 10, 30, {rejectUnauthorized: false}); - if (config.remoteLib.accessPassword) - this.accessToken = utils.getBufHash(config.remoteLib.accessPassword, 'sha256', 'hex'); this.remoteHost = config.remoteLib.url.replace(/^ws:\/\//, 'http://').replace(/^wss:\/\//, 'https://'); @@ -31,7 +29,7 @@ class RemoteLib { return instance; } - async wsRequest(query) { + async wsRequest(query, recurse = false) { if (this.accessToken) query.accessToken = this.accessToken; @@ -40,6 +38,11 @@ class RemoteLib { 120 ); + if (!recurse && response && response.error == 'need_access_token' && this.config.remoteLib.accessPassword) { + this.accessToken = utils.getBufHash(this.config.remoteLib.accessPassword + response.salt, 'sha256', 'hex'); + return await this.wsRequest(query, true); + } + if (response.error) throw new Error(response.error);