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);