Переглянути джерело

Добавлен basic-auth для opds

Book Pauk 2 роки тому
батько
коміт
74d8cd3f94
3 змінених файлів з 23 додано та 1 видалено
  1. 6 0
      server/config/base.js
  2. 1 0
      server/config/index.js
  3. 16 1
      server/core/opds/index.js

+ 6 - 0
server/config/base.js

@@ -45,5 +45,11 @@ module.exports = {
         host: '0.0.0.0',
         port: '22380',
     },
+    //opds: false,
+    opds: {
+        enabled: true,
+        user: '',
+        password: '',
+    },
 };
 

+ 1 - 0
server/config/index.js

@@ -20,6 +20,7 @@ const propsToSave = [
     'allowRemoteLib',
     'remoteLib',
     'server',
+    'opds',
 ];
 
 let instance = null;

+ 16 - 1
server/core/opds/index.js

@@ -1,3 +1,5 @@
+const basicAuth = require('express-basic-auth');
+
 const RootPage = require('./RootPage');
 const AuthorPage = require('./AuthorPage');
 const SeriesPage = require('./SeriesPage');
@@ -9,6 +11,9 @@ const OpensearchPage = require('./OpensearchPage');
 const SearchPage = require('./SearchPage');
 
 module.exports = function(app, config) {
+    if (!config.opds || !config.opds.enabled)
+        return;
+    
     const opdsRoot = '/opds';
     config.opdsRoot = opdsRoot;
 
@@ -62,6 +67,16 @@ module.exports = function(app, config) {
         }
     };
 
-    app.get([opdsRoot, `${opdsRoot}/*`], opds);
+    const opdsPaths = [opdsRoot, `${opdsRoot}/*`];
+    if (config.opds.password) {
+        if (!config.opds.user)
+            throw new Error('User must not be empty if password set');
+
+        app.use(opdsPaths, basicAuth({
+            users: {[config.opds.user]: config.opds.password},
+            challenge: true,
+        }));
+    }
+    app.get(opdsPaths, opds);
 };