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

This commit is contained in:
Book Pauk
2022-11-24 20:37:35 +07:00
parent fd29532cf1
commit 74d8cd3f94
3 changed files with 23 additions and 1 deletions

View File

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

View File

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

View File

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