Handle (default) case of web server being disabled in file areas/web link generation
This commit is contained in:
parent
701f3c9728
commit
6406d32165
|
@ -37,4 +37,5 @@ exports.ErrorReasons = {
|
|||
InvalidNextMenu : 'BADNEXT',
|
||||
NoPreviousMenu : 'NOPREV',
|
||||
NoConditionMatch : 'NOCONDMATCH',
|
||||
NotEnabled : 'NOTENABLED',
|
||||
};
|
|
@ -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);
|
||||
|
@ -47,13 +52,16 @@ class FileAreaWebAccess {
|
|||
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');
|
||||
|
|
|
@ -53,12 +53,12 @@ exports.getModule = class WebServerModule extends ServerModule {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.enableHttp = Config.contentServers.web.http.enabled || true;
|
||||
this.enableHttp = Config.contentServers.web.http.enabled || false;
|
||||
this.enableHttps = Config.contentServers.web.https.enabled || false;
|
||||
|
||||
this.routes = {};
|
||||
|
||||
if(Config.contentServers.web.staticRoot) {
|
||||
if(this.isEnabled() && Config.contentServers.web.staticRoot) {
|
||||
this.addRoute({
|
||||
method : 'GET',
|
||||
path : '/static/.*$',
|
||||
|
@ -67,6 +67,10 @@ exports.getModule = class WebServerModule extends ServerModule {
|
|||
}
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
return this.enableHttp || this.enableHttps;
|
||||
}
|
||||
|
||||
createServer() {
|
||||
if(this.enableHttp) {
|
||||
this.httpServer = http.createServer( (req, resp) => this.routeRequest(req, resp) );
|
||||
|
|
|
@ -11,6 +11,7 @@ const stringFormat = require('../core/string_format.js');
|
|||
const createCleanAnsi = require('../core/string_util.js').createCleanAnsi;
|
||||
const FileArea = require('../core/file_base_area.js');
|
||||
const Errors = require('../core/enig_error.js').Errors;
|
||||
const ErrNotEnabled = require('../core/enig_error.js').ErrorReasons.NotEnabled;
|
||||
const ArchiveUtil = require('../core/archive_util.js');
|
||||
const Config = require('../core/config.js').config;
|
||||
const DownloadQueue = require('../core/download_queue.js');
|
||||
|
@ -256,8 +257,12 @@ exports.getModule = class FileAreaList extends MenuModule {
|
|||
|
||||
FileAreaWeb.getExistingTempDownloadServeItem(this.client, this.currentFileEntry, (err, serveItem) => {
|
||||
if(err) {
|
||||
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
||||
entryInfo.webDlExpire = '';
|
||||
if(ErrNotEnabled === err.reasonCode) {
|
||||
entryInfo.webDlExpire = config.webDlLinkNoWebserver || 'Web server is not enabled';
|
||||
} else {
|
||||
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
||||
}
|
||||
} else {
|
||||
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
||||
|
||||
|
|
Loading…
Reference in New Issue