mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-25 20:18:25 +02:00
Handle (default) case of web server being disabled in file areas/web link generation
This commit is contained in:
parent
701f3c9728
commit
6406d32165
4 changed files with 40 additions and 10 deletions
|
@ -8,6 +8,7 @@ const getISOTimestampString = require('./database.js').getISOTimestampString;
|
|||
const FileEntry = require('./file_entry.js');
|
||||
const getServer = require('./listening_server.js').getServer;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||
|
||||
// deps
|
||||
const hashids = require('hashids');
|
||||
|
@ -27,6 +28,10 @@ const WEB_SERVER_PACKAGE_NAME = 'codes.l33t.enigma.web.server';
|
|||
*
|
||||
*/
|
||||
|
||||
function notEnabledError() {
|
||||
return Errors.General('Web server is not enabled', ErrNotEnabled);
|
||||
}
|
||||
|
||||
class FileAreaWebAccess {
|
||||
constructor() {
|
||||
this.hashids = new hashids(Config.general.boardName);
|
||||
|
@ -46,14 +51,17 @@ class FileAreaWebAccess {
|
|||
if(!self.webServer) {
|
||||
return callback(Errors.DoesNotExist(`Server with package name "${WEB_SERVER_PACKAGE_NAME}" does not exist`));
|
||||
}
|
||||
|
||||
const routeAdded = self.webServer.instance.addRoute({
|
||||
method : 'GET',
|
||||
path : Config.fileBase.web.routePath,
|
||||
handler : self.routeWebRequestForFile.bind(self),
|
||||
});
|
||||
|
||||
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
||||
if(self.isEnabled()) {
|
||||
const routeAdded = self.webServer.instance.addRoute({
|
||||
method : 'GET',
|
||||
path : Config.fileBase.web.routePath,
|
||||
handler : self.routeWebRequestForFile.bind(self),
|
||||
});
|
||||
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
||||
} else {
|
||||
return callback(null); // not enabled, but no error
|
||||
}
|
||||
}
|
||||
],
|
||||
err => {
|
||||
|
@ -66,6 +74,10 @@ class FileAreaWebAccess {
|
|||
return cb(null);
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
return this.webServer.instance.isEnabled();
|
||||
}
|
||||
|
||||
load(cb) {
|
||||
//
|
||||
// Load entries, register expiration timers
|
||||
|
@ -187,6 +199,10 @@ class FileAreaWebAccess {
|
|||
}
|
||||
|
||||
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
||||
if(!this.isEnabled()) {
|
||||
return cb(notEnabledError());
|
||||
}
|
||||
|
||||
const hashId = this.getHashId(client, fileEntry);
|
||||
this.loadServedHashId(hashId, (err, servedItem) => {
|
||||
if(err) {
|
||||
|
@ -200,6 +216,10 @@ class FileAreaWebAccess {
|
|||
}
|
||||
|
||||
createAndServeTempDownload(client, fileEntry, options, cb) {
|
||||
if(!this.isEnabled()) {
|
||||
return cb(notEnabledError());
|
||||
}
|
||||
|
||||
const hashId = this.getHashId(client, fileEntry);
|
||||
const url = this.buildTempDownloadLink(client, fileEntry, hashId);
|
||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue