Bläddra i källkod

Поправлен баг ограничения доступа в режиме "Удаленная библиотека"

Book Pauk 2 år sedan
förälder
incheckning
aa436feae7
1 ändrade filer med 6 tillägg och 3 borttagningar
  1. 6 3
      server/core/RemoteLib.js

+ 6 - 3
server/core/RemoteLib.js

@@ -16,8 +16,6 @@ class RemoteLib {
             this.config = config;
             this.config = config;
 
 
             this.wsc = new WebSocketConnection(config.remoteLib.url, 10, 30, {rejectUnauthorized: false});
             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://');
             this.remoteHost = config.remoteLib.url.replace(/^ws:\/\//, 'http://').replace(/^wss:\/\//, 'https://');
 
 
@@ -31,7 +29,7 @@ class RemoteLib {
         return instance;
         return instance;
     }
     }
 
 
-    async wsRequest(query) {
+    async wsRequest(query, recurse = false) {
         if (this.accessToken)
         if (this.accessToken)
             query.accessToken = this.accessToken;
             query.accessToken = this.accessToken;
 
 
@@ -40,6 +38,11 @@ class RemoteLib {
             120
             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)
         if (response.error)
             throw new Error(response.error);
             throw new Error(response.error);