isite
Version:
Create High Level Multi-Language Web Site [Fast and Easy]
1,167 lines (1,064 loc) • 70 kB
JavaScript
module.exports = function init(____0) {
____0.on(____0.strings[4], (_) => {
if (!_) {
_0xrrxo.list = _0xrrxo.list.filter((r) => r.name.like('*x-api*'));
}
});
let _0xrrxo = function () {};
_0xrrxo.list = [];
_0xrrxo.endResponse = function (req, res) {
let route = req.route;
if (route.contentError) {
if (____0.options.help) {
res.set('help-error-message', route.contentError);
}
res.end();
return;
}
if (req.route.encript == '123' && req.content) {
req.content = ____0.f1(req.content);
}
if (route.parser.like('*html*') && route.content && route.content.length > 0) {
req.content = ____0.parser(req, res, ____0, route).html(route.content);
} else if (route.parser == 'css' && route.content && route.content.length > 0) {
req.content = ____0.parser(req, res, ____0, route).css(route.content);
} else if (route.parser == 'js' && route.content && route.content.length > 0) {
req.content = ____0.parser(req, res, ____0, route).js(route.content);
} else {
req.content = route.content;
}
if (route.compress) {
req.content = req.content.replace(/\r?\n|\r/g, ' ').replace(/\s+/g, ' ');
}
route.path = route.path || '';
// let hash = req.content ? ____0.x0md50x(req.content) : ____0.x0md50x('');
let last_modified = new Date().toUTCString();
if (route.stat) {
last_modified = new Date(route.stat.mtimeMs).toUTCString();
}
// if (req.headers['if-none-match'] == hash) {
// if (____0.options.help) {
// res.set('help-info-message', 'etag matched');
// }
// // res.status(304).end(null);
// // return;
// }
// res.set('ETag', hash);
if (____0.options.cache.enabled) {
res.set('Last-Modified', last_modified);
}
if (route.headers) {
for (const property in route.headers) {
res.set(property, route.headers[property]);
}
}
if (true) {
if (route.path.endsWith('.css')) {
res.set(____0.strings[7], 'text/css');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.css);
}
} else if (route.path.endsWith('.js')) {
res.set(____0.strings[7], 'application/javascript');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.js);
}
} else if (route.path.endsWith('.html')) {
res.set(____0.strings[7], 'text/html');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.html);
}
} else if (route.path.endsWith('.txt')) {
res.set(____0.strings[7], 'text/plain');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.txt);
}
} else if (route.path.endsWith('.json')) {
res.set(____0.strings[7], 'application/json');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.json);
}
} else if (route.path.endsWith('.xml')) {
res.set(____0.strings[7], 'text/xml');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.xml);
}
} else if (route.path.endsWith('.woff2')) {
res.set(____0.strings[7], 'application/font-woff2');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (route.path.endsWith('.woff')) {
res.set(____0.strings[7], 'application/font-woff');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (route.path.endsWith('.ttf')) {
res.set(____0.strings[7], 'application/font-ttf');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (route.path.endsWith('.otf')) {
res.set(____0.strings[7], 'application/font-otf');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (route.path.endsWith('.eot')) {
res.set(____0.strings[7], 'application/font-eot');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (route.path.endsWith('.gif')) {
res.set(____0.strings[7], 'image/gif');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.png')) {
res.set(____0.strings[7], 'image/png');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.jpg')) {
res.set(____0.strings[7], 'image/jpg');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.jpeg')) {
res.set(____0.strings[7], 'image/jpeg');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.ico')) {
res.set(____0.strings[7], 'image/ico');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.bmp')) {
res.set(____0.strings[7], 'image/bmp');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.webp')) {
res.set(____0.strings[7], 'image/webp');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (route.path.endsWith('.svg')) {
res.set(____0.strings[7], 'image/svg+xml');
if (____0.options.cache.enabled) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
}
}
let response = {
host: req.host,
url: req.url,
filePath: route.path,
content: req.content,
encode: ____0.getFileEncode(route.path),
headers: res.headers,
code: res.code,
};
if (route.shared && !____0.sharedList.some((s) => s.host == req.host && s.filePath == response.filePath && s.url == response.url)) {
____0.sharedList.push(response);
}
if (typeof response.content == 'object') {
res.json(response.content);
} else {
res.end(response.content, response.encode);
}
};
_0xrrxo.defaultCallback = function (req, res) {
let route = req.route;
if (route.contentError) {
res.status(404);
if (____0.options.help) {
res.set('help-info-content', route.contentError);
}
_0xrrxo.endResponse(req, res);
return;
}
if ((response = ____0.sharedList.find((s) => s.host == req.host && s.filePath == route.path && s.url == req.url))) {
res.headers = response.headers;
res.code = response.code;
for (const key in response.headers) {
if (Object.prototype.hasOwnProperty.call(response.headers, key)) {
if (key !== 'x-shared') {
res.set(key, response.headers[key]);
}
}
}
res.set('x-shared', '-host=' + req.host + ' -port=' + ____0.options.port + ' -count=' + req.route.count + ' -time=' + new Date().getTime());
return res.end(response.content, response.encode);
}
if (route.cache && route.content) {
if (____0.options.help) {
res.set('help-info-content', 'From Route Memory');
}
res.status(200);
_0xrrxo.endResponse(req, res);
return;
}
if (!route.path && !route.content) {
if (____0.options.help) {
res.set('help-info-content', 'Route Not Set File Path');
}
res.status(200);
_0xrrxo.endResponse(req, res);
return;
} else if (route.content) {
if (____0.options.help) {
res.set('help-info-content', 'Content From Route init');
}
res.status(200);
_0xrrxo.endResponse(req, res);
}
if (typeof route.path == 'string') {
____0.readFile(route.path, function (err, file) {
if (!err) {
route.content = file.content.toString('utf8');
if (route.encript && route.encript === '123') {
route.content = ____0.f1(route.content);
}
route.stat = file.stat;
if (route.masterPage) {
for (var i = 0; i < ____0.masterPages.length; i++) {
if (route.masterPage == ____0.masterPages[i].name) {
route.content = ____0.readFileSync(____0.masterPages[i].header) + route.content + ____0.readFileSync(____0.masterPages[i].footer);
break;
}
}
}
if (____0.options.help) {
res.set('help-info-content', 'Route Read File');
}
res.status(200);
_0xrrxo.endResponse(req, res);
} else {
if (____0.options.help) {
res.set('help-error', 'Route Error Read File');
}
res.status(404);
route.contentError = err.message;
_0xrrxo.endResponse(req, res);
return;
}
});
} else if (Array.isArray(route.path)) {
____0.readFiles(route.path, function (err, data) {
if (!err) {
if (____0.options.help) {
res.set('help-info-content', 'Route Read Files');
}
route.content = data.toString('utf8');
res.status(200);
route.path = route.path.join('&&');
_0xrrxo.endResponse(req, res);
} else {
if (____0.options.help) {
res.set('help-error', 'Route Error Read Files');
}
res.status(404);
route.contentError = err.message;
_0xrrxo.endResponse(req, res);
return;
}
});
}
};
_0xrrxo.call = function (r, req, res, callback) {
callback =
callback ||
function (req, res) {
____0.log('No CallBack set For : ', r);
res.end();
};
if (typeof r === 'string') {
r = {
name: r,
method: req.method,
};
}
let routeIndex = _0xrrxo.list.findIndex((rr) => (rr.name == r.name || rr.nameRaw == r.name) && rr.method == r.method);
if (routeIndex !== -1) {
req.route = _0xrrxo.list[routeIndex];
req.route.count++;
req.route.callback(req, res);
} else {
callback(req, res);
}
};
_0xrrxo.off = function (r) {
if (!r) {
return;
}
if (typeof r == 'string') {
r = { name: r };
}
if (!r.name.startsWith('/')) {
r.name = '/' + r.name;
}
for (let i = _0xrrxo.list.length; i--; ) {
let oldRoute = _0xrrxo.list[i];
if (r.name && r.method && oldRoute.name.like(r.name) && oldRoute.method.like(r.method)) {
_0xrrxo.list.splice(i, 1);
____0.fsm.off(oldRoute.path);
} else if (r.name && r.method && oldRoute.nameRaw.like(r.name) && oldRoute.method.like(r.method)) {
_0xrrxo.list.splice(i, 1);
____0.fsm.off(oldRoute.path);
} else if (r.name && oldRoute.name.like(r.name)) {
_0xrrxo.list.splice(i, 1);
____0.fsm.off('*' + oldRoute.name.replace('/', '') + '*');
____0.fsm.off(oldRoute.path);
} else if (r.name && oldRoute.nameRaw.like(r.name)) {
_0xrrxo.list.splice(i, 1);
____0.fsm.off('*' + oldRoute.name.replace('/', '') + '*');
____0.fsm.off(oldRoute.path);
} else if (r.method && oldRoute.method.like(r.method)) {
_0xrrxo.list.splice(i, 1);
____0.fsm.off(oldRoute.path);
}
}
};
_0xrrxo.add = function (r, callback) {
if (Array.isArray(r)) {
r.forEach((r2) => {
_0xrrxo.add(r2, callback);
});
return;
}
if (r && r.name && Array.isArray(r.name)) {
r.name.forEach((r2) => {
let r3 = { ...r };
r3.name = r2;
_0xrrxo.onREQUEST(r3, r.callback);
});
return;
}
let route = {};
if (typeof r == 'string') {
route.name = r.toLowerCase();
route.nameRaw = r;
route.public = ____0.options.public || false;
route.method = 'GET';
route.path = null;
route.parser = 'static';
route.parserDir = ____0.dir;
route.count = 0;
route.cache = !0;
route.hide = !1;
route.compress = !1;
route.encript = !1;
route.shared = !1;
route.content = null;
route.headers = null;
route.map = [];
route.callback = callback ?? _0xrrxo.defaultCallback;
if (route.public) {
route.require = {
features: [],
permissions: [],
};
} else {
route.require = ____0.options.require;
route.default = ____0.options.defaults;
}
} else {
route.name = r.name.toLowerCase();
route.nameRaw = r.name;
route.public = r.public ?? (____0.options.public || false);
route.method = r.method || 'GET';
route.path = r.path || null;
route.lang = r.lang || null;
route.content = r.content;
route.headers = r.headers;
route.parser = r.parser || 'static';
route.parserDir = r.parserDir || ____0.dir;
route.masterPage = r.masterPage || null;
route.overwrite = r.overwrite ?? !1;
route.cache = r.cache ?? !0;
route.count = r.count || 0;
route.hide = r.hide ?? !1;
route.compress = r.compress ?? !1;
route.encript = r.encript ?? !1;
route.shared = r.shared ?? !1;
route.map = r.map || [];
route.callback = callback || r.callback || _0xrrxo.defaultCallback;
if (route.public) {
route.require = {
features: [],
permissions: [],
};
} else {
route.require = r.require ?? ____0.options.require;
route.require.features = route.require.features ?? ____0.options.require.features;
route.require.permissions = route.require.permissions ?? ____0.options.require.permissions;
route.default = r.default ?? ____0.options.defaults;
route.default.features = route.default.features ?? ____0.options.defaults.features;
route.default.permissions = route.default.permissions ?? ____0.options.defaults.permissions;
}
}
if (!route.name.startsWith('/')) {
route.name = '/' + route.name;
route.nameRaw = '/' + route.nameRaw;
}
route.name = route.name.replace('//', '/');
route.nameRaw = route.nameRaw.replace('//', '/');
let arr = route.name.split('/');
let arr0 = route.nameRaw.split('/');
for (var i = 0; i < arr.length; i++) {
var s = arr[i];
var s0 = arr0[i];
if (s.startsWith(':')) {
arr[i] = '*';
let name = s.replace(':', '');
let nameRaw = s0.replace(':', '');
route.map.push({
index: i,
name: name,
isLower: !1,
});
if (name !== nameRaw) {
route.map.push({
index: i,
name: nameRaw,
isLower: !0,
});
}
}
}
try {
route.name = arr.join('/');
if (typeof route.path == 'string' && ____0.fs.statSync(route.path).isDirectory()) {
____0.fs.readdirSync(route.path).forEach((file) => {
let r2 = { ...route };
if (route.name.endsWith('/')) {
r2.name = route.name + file;
} else {
r2.name = route.name + '/' + file;
}
r2.path = route.path + '/' + file;
r2.is_dynamic = !0;
_0xrrxo.add(r2);
});
} else {
if (!route.name.startsWith('/')) {
route.name = '/' + route.name;
}
route.name = encodeURI(route.name);
let index = _0xrrxo.list.findIndex((rr) => rr.name == route.name && rr.method == route.method);
if (index === -1) {
_0xrrxo.list.push(route);
} else if (!route.overwrite) {
if (route.name.like('*api/*')) {
____0.log('[ Duplicate API ] ' + route.name);
} else {
____0.log('[ Duplicate Route ] ' + route.name);
}
} else {
_0xrrxo.list[index] = route;
}
}
} catch (err) {
____0.log(err);
return null;
}
};
_0xrrxo.onREQUEST = function (type, r, callback) {
if (Array.isArray(r)) {
r.forEach((r2) => {
_0xrrxo.onREQUEST(type, r2, callback);
});
return;
}
let route = {};
if (typeof r == 'string') {
route = {
name: r,
method: type,
callback: callback || _0xrrxo.defaultCallback,
};
} else {
route = r;
if (Array.isArray(r.name)) {
r.name.forEach((n) => {
let sub_route = { ...route };
sub_route.name = n;
_0xrrxo.onREQUEST(type, sub_route, callback);
});
return;
}
route.callback = route.callback || callback || _0xrrxo.defaultCallback;
}
route.method = type;
_0xrrxo.add(route);
};
_0xrrxo.onGET = function (r, callback) {
_0xrrxo.onREQUEST('GET', r, callback);
};
_0xrrxo.onPOST = function (r, callback) {
_0xrrxo.onREQUEST('POST', r, callback);
};
_0xrrxo.onPUT = function (r, callback) {
_0xrrxo.onREQUEST('PUT', r, callback);
};
_0xrrxo.onDELETE = function (r, callback) {
_0xrrxo.onREQUEST('DELETE', r, callback);
};
_0xrrxo.onTEST = function (r, callback) {
_0xrrxo.onREQUEST('TEST', r, callback);
};
_0xrrxo.onVIEW = function (r, callback) {
_0xrrxo.onREQUEST('VIEW', r, callback);
};
_0xrrxo.onOPTIONS = function (r, callback) {
_0xrrxo.onREQUEST('OPTIONS', r, callback);
};
_0xrrxo.onPATCH = function (r, callback) {
_0xrrxo.onREQUEST('PATCH', r, callback);
};
_0xrrxo.onCOPY = function (r, callback) {
_0xrrxo.onREQUEST('COPY', r, callback);
};
_0xrrxo.onHEAD = function (r, callback) {
_0xrrxo.onREQUEST('HEAD', r, callback);
};
_0xrrxo.onLINK = function (r, callback) {
_0xrrxo.onREQUEST('LINK', r, callback);
};
_0xrrxo.onUNLINK = function (r, callback) {
_0xrrxo.onREQUEST('UNLINK', r, callback);
};
_0xrrxo.onPURGE = function (r, callback) {
_0xrrxo.onREQUEST('PURGE', r, callback);
};
_0xrrxo.onLOCK = function (r, callback) {
_0xrrxo.onREQUEST('LOCK', r, callback);
};
_0xrrxo.onUNLOCK = function (r, callback) {
_0xrrxo.onREQUEST('UNLOCK', r, callback);
};
_0xrrxo.onPROPFIND = function (r, callback) {
_0xrrxo.onREQUEST('PROPFIND', r, callback);
};
_0xrrxo.onALL = _0xrrxo.onANY = function (r, callback) {
_0xrrxo.onREQUEST('*', r, callback);
};
_0xrrxo.handleRoute = async function (req, res, route) {
if (route.language) {
req.session.language = { ...route.language };
}
if (route.lang) {
req.session.language.id = route.lang;
}
if (!route.public) {
if (!route.name.like(____0.strings[15]) && route.require.features.length > 0) {
let ok = !0;
route.require.features.forEach((feature) => {
if (!req.hasFeature(feature)) {
ok = !1;
}
});
if (!ok) {
res.status(401);
if (route.name.contains(____0.strings[16])) {
return res.json({
done: !1,
error: ____0.strings[13],
features: route.require.features,
});
} else
return res.render(
____0.strings[11],
{
features: route.require.features,
html: ` ${____0.strings[13]} : ${route.require.features.join(',')}`,
},
{
parser: ____0.strings[17],
},
);
}
}
if (!route.name.like(____0.strings[15]) && route.require.permissions.length > 0) {
let ok = !0;
route.require.permissions.forEach((permission) => {
if (!____0.security.isUserHasPermissions(req, res, permission)) {
ok = !1;
}
});
if (!ok) {
if (route.name.contains(____0.strings[16])) {
res.status(401);
return res.json({
done: !1,
error: ____0.strings[14],
permissions: route.require.permissions,
});
} else {
if (route.require.permissions.includes('login')) {
return res.redirect(____0.options.security.login_url);
} else {
res.status(401);
return res.render(
____0.strings[12],
{
permissions: route.require.permissions.join(','),
html: `${____0.strings[14]} : ${route.require.permissions.join(',')}`,
},
{
parser: ____0.strings[17],
},
);
}
}
}
}
}
route.callback(req, res);
};
____0.validateServerRequest = async function (req, res, next) {
next(req, res);
};
____0.validateRequest = async function (req, res, next) {
next(req, res);
};
____0.validateRoute = async function (req, res, next) {
next(req, res);
};
____0.validateSession = async function (req, res, next) {
next(req, res);
};
_0xrrxo.handleServer = async function (req, res) {
____0.validateServerRequest(req, res, (req, res) => {
req.host = req.headers['host'] || '';
req.origin = req.headers['origin'] || '';
req.referer = req.headers['referer'] || '';
req.domain = '';
req.subDomain = '';
req.obj = {};
req.query = {};
req.queryRaw = {};
req.data = req.body = {};
req.bodyRaw = '';
req.params = {};
req.paramsRaw = {};
req.features = [];
res.setTimeout(1000 * ____0.options.responseTimeout, () => {
if (req.url.like('*api*')) {
return res.json({
done: false,
error: ____0.strings[19],
});
} else {
res.end(503);
}
});
req.addFeature = function (name) {
req.features.push(name);
};
req.hasFeature = function (name) {
return req.features.some((f) => f.like(name));
};
req.removeFeature = function (name) {
req.features = req.features.filter((f) => !f.like(name));
};
req.getUserFinger = function () {
let userFinger = {
id: null,
email: null,
date: new Date(),
ip: null,
};
if (req && req.session && req.session.user) {
req.session.user.profile = req.session.user.profile || {};
userFinger.id = req.session.user.id;
userFinger.email = req.session.user.email;
userFinger.name = req.session.user.profile.name || userFinger.email;
userFinger.name_ar = req.session.user.profile.name_ar || userFinger.email;
userFinger.name_en = req.session.user.profile.name_en || userFinger.email;
userFinger.ip = req.ip;
} else {
}
return userFinger;
};
req.word = function (name) {
let w = ____0.word(name);
if (!w.hostList) {
return w[req.session.language.id] || name;
} else {
if ((w2 = w.hostList.find((h) => req.host.like(h.name)))) {
return w2[req.session.language.id] || name;
}
}
return w[req.session.language.id] || name;
};
res.code = null;
req.remoteAddress = req.socket?.remoteAddress || '';
req.acceptEncoding = req.headers[____0.strings[5]] ? req.headers[____0.strings[5]] : '';
res.ip = req.ip = req.headers[____0.strings[6]] ? req.headers[____0.strings[6]] : req.remoteAddress?.replace('::ffff:', '');
if (req.ip == '::1') {
req.ip = '127.0.0.1';
}
res.ip2 = req.ip2 = req.socket?.localAddress.replace('::ffff:', '');
res.port = req.port = req.socket?.remotePort;
res.port2 = req.port2 = req.socket?.localPort;
res.cookies = res.cookie = req.cookies = req.cookie = ____0.cookie(req, res, ____0);
req.urlRaw = req.url;
req.urlParserRaw = ____0.url.parse(req.urlRaw, !0);
req.urlParser = ____0.url.parse(req.urlRaw.toLowerCase(), !0);
for (const key in req.urlParser.query) {
req.urlParser.query[key.toLowerCase()] = req.urlParser.query[key];
}
for (const key in req.urlParserRaw.query) {
req.urlParserRaw.query[key.toLowerCase()] = req.urlParserRaw.query[key];
}
res.set = (a, b, c) => {
if (res.writeHeadEnabled === !1 || res.finished === !0 || res.headersSent) {
return res;
}
if (typeof b == 'string') {
if (a == ____0.strings[7] && !b.contains('charset=utf-8')) {
b += '; charset=utf-8';
}
res.headers = res.headers || [];
res.headers[a] = b.toLowerCase();
}
res.setHeader(a, b, c);
return res;
};
res.delete = res.remove = res.removeHeader;
res.writeHead0 = res.writeHead;
res.writeHeadEnabled = !0;
res.writeHead = (code, obj) => {
if (res.writeHeadEnabled === !1 || res.finished === !0) {
return res;
}
res.cookie.write();
res.writeHeadEnabled = !1;
res.writeHead0(code, obj);
return res;
};
res.ending = (time, ...data) => {
if (!time) {
time = 0;
}
setTimeout(function () {
res.end(...data);
}, time);
};
res.end0 = res.end;
res.end = function (arg1, arg2, arg3, arg4) {
if (res.ended) {
return;
}
if (typeof arg1 === 'number') {
res.writeHead(arg1);
return res.end(arg2, arg3, arg4);
} else {
if (res.headers === undefined || res.headers[____0.strings[7]] === undefined) {
res.set(____0.strings[7], 'text/html');
}
if (
arg1 &&
res.headers &&
res.headers[____0.strings[7]] &&
(res.headers[____0.strings[7]].like('*text/css*') ||
res.headers[____0.strings[7]].like('*application/javascript*') ||
res.headers[____0.strings[7]].like('*text/html*') ||
res.headers[____0.strings[7]].like('*text/plain*') ||
res.headers[____0.strings[7]].like('*application/json*'))
) {
if (req.acceptEncoding.like('*gzip*') && typeof arg1 === 'string') {
res.set(____0.strings[8], 'gzip');
res.set('Vary', ____0.strings[5]);
arg1 = ____0.zlib.gzipSync(Buffer.from(arg1));
} else if (req.acceptEncoding.like('*deflate*') && typeof arg1 === 'string') {
res.set(____0.strings[8], 'deflate');
res.set('Vary', ____0.strings[5]);
arg1 = ____0.zlib.deflateSync(Buffer.from(arg1));
} else {
// ____0.log(typeof arg1)
}
}
res.writeHead(res.code || res.statusCode || 200);
arg1 = arg1 || ' ';
res.ended = true;
return res.end0(arg1, arg2, arg3, arg4);
}
};
res.status = (code) => {
if (!res.code) {
res.code = code || 200;
}
return res;
};
res.error = (code) => {
res.status(code || 404).end();
};
res.download2 = (path, name) => {
if (____0.isFileExistsSync(path)) {
var stat = ____0.fileStatSync(path);
if (stat && stat.isFile()) {
res.writeHead(200, {
'Content-Type': ____0.getContentType(path),
'Content-Length': stat.size,
'Content-Disposition': 'attachment; filename=' + (name || ____0.path.basename(path)),
});
var readStream = ____0.fs.createReadStream(path);
readStream.on('end', function () {
readStream.close();
});
res.on(____0.strings[10], function () {
readStream.close();
});
readStream.pipe(res);
} else {
res.error();
}
} else {
res.error();
}
};
res.download = function (path, name) {
if (____0.isFileExistsSync(path)) {
const stat = ____0.fileStatSync(path);
if (stat && stat.isFile()) {
const fileSize = stat.size;
const range = req.headers.range;
if (range) {
const parts = range.replace(/bytes=/, '').split('-');
const start = parseInt(parts[0], 10);
const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;
const chunksize = end - start + 1;
const readStream = ____0.fs.createReadStream(path, {
start,
end,
});
readStream.on('end', function () {
readStream.close();
});
res.on(____0.strings[10], function () {
readStream.close();
});
res.writeHead(206, {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': ____0.getContentType(path),
});
readStream.pipe(res);
} else {
const readStream = ____0.fs.createReadStream(path);
readStream.on('end', function () {
readStream.close();
});
res.on(____0.strings[10], function () {
readStream.close();
});
res.writeHead(200, {
'Content-Length': fileSize,
'Content-Type': ____0.getContentType(path),
'Content-Disposition': 'attachment; filename=' + (name || ____0.path.basename(path)),
});
____0.fs.createReadStream(path).pipe(res);
}
} else {
res.error();
}
} else {
res.error();
}
};
res.html = res.render = function (file, _data = null, options = {}) {
let filePath = '';
if (typeof file === 'object') {
filePath = file.path;
options = { ...options, ...file };
} else {
filePath = file;
}
if ((response = ____0.sharedList.find((s) => s.host == req.host && s.filePath == filePath && s.url == req.url))) {
res.headers = response.headers;
res.code = response.code;
for (const key in response.headers) {
if (Object.prototype.hasOwnProperty.call(response.headers, key)) {
if (key !== 'x-shared') {
res.set(key, response.headers[key]);
}
}
}
res.set('x-shared', '-host=' + req.host + ' -port=' + ____0.options.port + ' -count=' + req.route.count + ' -time=' + new Date().getTime());
return res.end(response.content, response.encode);
}
____0.fsm.getContent(filePath, (content) => {
if (!content) {
if (_data && _data.html) {
return res.status(404).htmlContent(_data.html);
} else {
return res.status(404).end();
}
}
req.content = content;
req.data = { ...req.data, ..._data };
let route = { ...req.route, ...options };
if (route.encript == '123') {
req.content = ____0.f1(req.content);
}
if (route.parser) {
req.content = ____0.parser(req, res, ____0, route).html(req.content);
}
if (route.compress) {
req.content = req.content.replace(/\r?\n|\r/g, ' ').replace(/\s+/g, ' ');
}
res.status(options.code || 200);
if (filePath.endsWith('.css')) {
res.set(____0.strings[7], 'text/css');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.css);
}
} else if (filePath.endsWith('.js')) {
res.set(____0.strings[7], 'application/javascript');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.js);
}
} else if (filePath.endsWith('.html')) {
res.set(____0.strings[7], 'text/html');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.html);
}
} else if (filePath.endsWith('.txt')) {
res.set(____0.strings[7], 'text/plain');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.txt);
}
} else if (filePath.endsWith('.json')) {
res.set(____0.strings[7], 'application/json');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.json);
}
} else if (filePath.endsWith('.xml')) {
res.set(____0.strings[7], 'text/xml');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.xml);
}
} else if (filePath.endsWith('.woff2')) {
res.set(____0.strings[7], 'application/font-woff2');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.woff')) {
res.set(____0.strings[7], 'application/font-woff');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.ttf')) {
res.set(____0.strings[7], 'application/font-ttf');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.svg')) {
res.set(____0.strings[7], 'application/font-svg');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.otf')) {
res.set(____0.strings[7], 'application/font-otf');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.eot')) {
res.set(____0.strings[7], 'application/font-eot');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.fonts);
}
} else if (filePath.endsWith('.gif')) {
res.set(____0.strings[7], 'image/gif');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.png')) {
res.set(____0.strings[7], 'image/png');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.jpg')) {
res.set(____0.strings[7], 'image/jpg');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.jpeg')) {
res.set(____0.strings[7], 'image/jpeg');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.ico')) {
res.set(____0.strings[7], 'image/ico');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.bmp')) {
res.set(____0.strings[7], 'image/bmp');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
} else if (filePath.endsWith('.webp')) {
res.set(____0.strings[7], 'image/webp');
if (____0.options.cache.enabled && route.cache) {
res.set('Cache-Control', 'public, max-age=' + 60 * ____0.options.cache.images);
}
}
let response = {
host: req.host,
url: req.url,
filePath: filePath,
content: req.content,
encode: ____0.getFileEncode(filePath),
headers: res.headers,
code: res.code,
};
if (options.shared && !____0.sharedList.some((s) => s.host == req.host && s.filePath == response.filePath && s.url == response.url)) {
____0.sharedList.push(response);
}
res.end(response.content, response.encode);
});
};
res.txt = (name, _data) => {
____0.fsm.getContent(name, (content) => {
if (!content) {
return res.status(404).end();
}
req.route.content = content;
if (req.route.encript === '123') {
req.route.content = ____0.f1(req.route.content);
}
req.data = { ...req.data, ..._data };
req.route.parser = 'txt';
let out = ____0.parser(req, res, ____0, req.route).txt(req.route.content);
res.set(____0.strings[7], 'text/plain');
res.status(200).end(out);
});
};
res.css = (name, _data) => {
____0.fsm.getContent(name, (content) => {
if (!content) {
return res.status(404).end();
}
req.route.content = content;
if (req.route.encript === '123') {
req.route.content = ____0.f1(req.route.content);
}
req.data = { ...req.data, ..._data };
req.route.parser = 'css';
let out = ____0.parser(req, res, ____0, req.route).css(req.route.content);
res.set(____0.strings[7], 'text/css');
res.status(200).end(out);
});
};
res.js = (name, _data) => {
____0.fsm.getContent(name, (content) => {
if (!content) {
return res.status(404).end();
}
req.route.content = content;
if (req.route.encript === '123') {