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',
|
InvalidNextMenu : 'BADNEXT',
|
||||||
NoPreviousMenu : 'NOPREV',
|
NoPreviousMenu : 'NOPREV',
|
||||||
NoConditionMatch : 'NOCONDMATCH',
|
NoConditionMatch : 'NOCONDMATCH',
|
||||||
|
NotEnabled : 'NOTENABLED',
|
||||||
};
|
};
|
|
@ -8,6 +8,7 @@ const getISOTimestampString = require('./database.js').getISOTimestampString;
|
||||||
const FileEntry = require('./file_entry.js');
|
const FileEntry = require('./file_entry.js');
|
||||||
const getServer = require('./listening_server.js').getServer;
|
const getServer = require('./listening_server.js').getServer;
|
||||||
const Errors = require('./enig_error.js').Errors;
|
const Errors = require('./enig_error.js').Errors;
|
||||||
|
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const hashids = require('hashids');
|
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 {
|
class FileAreaWebAccess {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.hashids = new hashids(Config.general.boardName);
|
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`));
|
return callback(Errors.DoesNotExist(`Server with package name "${WEB_SERVER_PACKAGE_NAME}" does not exist`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(self.isEnabled()) {
|
||||||
const routeAdded = self.webServer.instance.addRoute({
|
const routeAdded = self.webServer.instance.addRoute({
|
||||||
method : 'GET',
|
method : 'GET',
|
||||||
path : Config.fileBase.web.routePath,
|
path : Config.fileBase.web.routePath,
|
||||||
handler : self.routeWebRequestForFile.bind(self),
|
handler : self.routeWebRequestForFile.bind(self),
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
return callback(routeAdded ? null : Errors.General('Failed adding route'));
|
||||||
|
} else {
|
||||||
|
return callback(null); // not enabled, but no error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
err => {
|
err => {
|
||||||
|
@ -66,6 +74,10 @@ class FileAreaWebAccess {
|
||||||
return cb(null);
|
return cb(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return this.webServer.instance.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
load(cb) {
|
load(cb) {
|
||||||
//
|
//
|
||||||
// Load entries, register expiration timers
|
// Load entries, register expiration timers
|
||||||
|
@ -187,6 +199,10 @@ class FileAreaWebAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
getExistingTempDownloadServeItem(client, fileEntry, cb) {
|
||||||
|
if(!this.isEnabled()) {
|
||||||
|
return cb(notEnabledError());
|
||||||
|
}
|
||||||
|
|
||||||
const hashId = this.getHashId(client, fileEntry);
|
const hashId = this.getHashId(client, fileEntry);
|
||||||
this.loadServedHashId(hashId, (err, servedItem) => {
|
this.loadServedHashId(hashId, (err, servedItem) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
@ -200,6 +216,10 @@ class FileAreaWebAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
createAndServeTempDownload(client, fileEntry, options, cb) {
|
createAndServeTempDownload(client, fileEntry, options, cb) {
|
||||||
|
if(!this.isEnabled()) {
|
||||||
|
return cb(notEnabledError());
|
||||||
|
}
|
||||||
|
|
||||||
const hashId = this.getHashId(client, fileEntry);
|
const hashId = this.getHashId(client, fileEntry);
|
||||||
const url = this.buildTempDownloadLink(client, fileEntry, hashId);
|
const url = this.buildTempDownloadLink(client, fileEntry, hashId);
|
||||||
options.expireTime = options.expireTime || moment().add(2, 'days');
|
options.expireTime = options.expireTime || moment().add(2, 'days');
|
||||||
|
|
|
@ -53,12 +53,12 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
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.enableHttps = Config.contentServers.web.https.enabled || false;
|
||||||
|
|
||||||
this.routes = {};
|
this.routes = {};
|
||||||
|
|
||||||
if(Config.contentServers.web.staticRoot) {
|
if(this.isEnabled() && Config.contentServers.web.staticRoot) {
|
||||||
this.addRoute({
|
this.addRoute({
|
||||||
method : 'GET',
|
method : 'GET',
|
||||||
path : '/static/.*$',
|
path : '/static/.*$',
|
||||||
|
@ -67,6 +67,10 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return this.enableHttp || this.enableHttps;
|
||||||
|
}
|
||||||
|
|
||||||
createServer() {
|
createServer() {
|
||||||
if(this.enableHttp) {
|
if(this.enableHttp) {
|
||||||
this.httpServer = http.createServer( (req, resp) => this.routeRequest(req, resp) );
|
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 createCleanAnsi = require('../core/string_util.js').createCleanAnsi;
|
||||||
const FileArea = require('../core/file_base_area.js');
|
const FileArea = require('../core/file_base_area.js');
|
||||||
const Errors = require('../core/enig_error.js').Errors;
|
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 ArchiveUtil = require('../core/archive_util.js');
|
||||||
const Config = require('../core/config.js').config;
|
const Config = require('../core/config.js').config;
|
||||||
const DownloadQueue = require('../core/download_queue.js');
|
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) => {
|
FileAreaWeb.getExistingTempDownloadServeItem(this.client, this.currentFileEntry, (err, serveItem) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
|
||||||
entryInfo.webDlExpire = '';
|
entryInfo.webDlExpire = '';
|
||||||
|
if(ErrNotEnabled === err.reasonCode) {
|
||||||
|
entryInfo.webDlExpire = config.webDlLinkNoWebserver || 'Web server is not enabled';
|
||||||
|
} else {
|
||||||
|
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue