62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.file_get = exports.file_exists = exports.file_allowed = exports.File = void 0;
|
|
var node_fs_1 = require("node:fs");
|
|
var Webserver_1 = require("./Webserver");
|
|
var Mapping = /** @class */ (function () {
|
|
function Mapping() {
|
|
}
|
|
return Mapping;
|
|
}());
|
|
var mappings = [
|
|
{ ending: 'html', encoding: 'text/html' },
|
|
{ ending: 'js', encoding: 'text/javascript' },
|
|
{ ending: 'css', encoding: 'text/css' },
|
|
{ ending: 'json', encoding: 'application/json' },
|
|
{ ending: 'ico', encoding: 'image/x-icon' },
|
|
{ ending: 'svg', encoding: 'image/svg+xml' },
|
|
{ ending: 'txt', encoding: 'text/plain' },
|
|
];
|
|
var File = /** @class */ (function () {
|
|
function File(type, content) {
|
|
this.content = content;
|
|
this.type = type;
|
|
}
|
|
return File;
|
|
}());
|
|
exports.File = File;
|
|
function file_allowed(url) {
|
|
var allowed = false;
|
|
var m = url.match('\\.\\.');
|
|
if (m == null) {
|
|
allowed = true;
|
|
}
|
|
return allowed;
|
|
}
|
|
exports.file_allowed = file_allowed;
|
|
function file_exists(url) {
|
|
if (url == '/') {
|
|
url = Webserver_1.index_alias;
|
|
}
|
|
return (0, node_fs_1.existsSync)(Webserver_1.www_folder + url);
|
|
}
|
|
exports.file_exists = file_exists;
|
|
function file_get(url) {
|
|
if (url == '/') {
|
|
url = Webserver_1.index_alias;
|
|
}
|
|
return new File(get_type(url), (0, node_fs_1.readFileSync)(Webserver_1.www_folder + url));
|
|
}
|
|
exports.file_get = file_get;
|
|
function get_type(url) {
|
|
if (url == '/') {
|
|
url = Webserver_1.index_alias;
|
|
}
|
|
var type = 'application/octet-stream';
|
|
var m = mappings.find(function (e) { return e.ending == url.split('.').pop(); });
|
|
if (m != undefined) {
|
|
type = m.encoding;
|
|
}
|
|
return type;
|
|
}
|