erfan-flmngr-server-fixed
Version:
> Node.js Backend for Flmngr file manager
100 lines • 4.04 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServletConfig = void 0;
const fsx = __importStar(require("fs-extra"));
class ServletConfig {
constructor(conf) {
this.m_testConf = {};
this.m_conf = conf;
}
setTestConfig(testConf) {
this.m_testConf = testConf;
}
getParameter(name, defaultValue, doAddTrailingSlash) {
if (name in this.m_testConf)
return this.addTrailingSlash(this.m_testConf[name], doAddTrailingSlash);
else {
let value = this.m_conf[name];
if (value != null)
return this.addTrailingSlash(value, doAddTrailingSlash);
return defaultValue;
}
}
addTrailingSlash(value, doAddTrailingSlash) {
if (value != null && doAddTrailingSlash && (value.length === 0 || value.substring(value.length - 1) !== "/"))
value += "/";
return value;
}
getParameterStr(name, defaultValue) {
return this.getParameter(name, defaultValue, false);
}
getParameterInt(name, defaultValue) {
return this.getParameter(name, defaultValue, false);
}
getParameterBool(name, defaultValue) {
return this.getParameter(name, defaultValue, false);
}
getBaseDir() {
let d = __dirname;
if (d.length === 1)
d = d.substr(1); // "/" case
let dir = this.getParameter("dirFiles", d + "files/", true);
if (!fsx.existsSync(dir))
fsx.mkdirsSync(dir);
return dir;
}
getTmpDir() {
let dir = this.getParameter("dirTmp", this.getBaseDir() + "tmp/", true);
if (!fsx.existsSync(dir))
fsx.mkdirsSync(dir);
return dir;
}
getMaxUploadFileSize() { return this.getParameterInt("maxUploadFileSize", 0); }
getAllowedExtensions() {
let value = this.getParameterStr("allowedExtensions", null);
if (value == null)
return [];
let exts = value.split(",");
for (let i = 0; i < exts.length; i++)
exts[i] = exts[i].toLowerCase();
return exts;
}
getJpegQuality() { return this.getParameterInt("jpegQuality", 95); }
getMaxImageResizeWidth() { return this.getParameterInt("maxImageResizeWidth", 5000); }
getMaxImageResizeHeight() { return this.getParameterInt("maxImageResizeHeight", 5000); }
getCrossDomainUrl() { return this.getParameterStr("crossDomainUrl", null); }
doKeepUploads() { return this.getParameterBool("keepUploads", false); }
isTestAllowed() { return this.getParameterBool("isTestAllowed", false); }
getRelocateFromHosts() {
let hostsStr = this.getParameterStr("relocateFromHosts", "");
let hostsFound = hostsStr.split(",");
let hosts = [];
for (let i = 0; i < hostsFound.length; i++) {
let host = hostsFound[i].trim().toLowerCase();
if (host.length > 0)
hosts.push(host);
}
return hosts;
}
}
exports.ServletConfig = ServletConfig;
//# sourceMappingURL=ServletConfig.js.map