staticDirectoryHandler => C.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4835 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-10 03:14:02 +00:00
parent 14de3dd9e5
commit 6801758cb3
2 changed files with 44 additions and 49 deletions

View File

@ -556,36 +556,6 @@ function startsWithBytes(data, bytes) {
}
}
async function staticDirectoryHandler(request, response, directory, uri) {
let filename = uri || 'index.html';
if (filename.indexOf('..') != -1) {
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": "File not found".length});
response.end("File not found");
return;
}
try {
let stat = await File.stat(directory + filename);
let id = `${stat.mtime}_${stat.size}`;
if (request.headers['if-none-match'] === '"' + id + '"') {
response.writeHead(304, {'Content-Length': '0'});
response.end();
} else {
let data = await File.readFile(directory + filename);
response.writeHead(200, {
'Content-Type': k_mime_types[filename.split('.').pop()] || 'text/plain',
'Content-Length': data.byteLength,
'etag': '"' + id + '"',
});
response.end(data);
}
} catch {
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": "File not found".length});
response.end("File not found");
}
}
async function wellKnownHandler(request, response, path) {
let data = await File.readFile("data/global/.well-known/" + path);
if (data) {
@ -968,12 +938,6 @@ loadSettings().then(function() {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^\/([&\%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^\/lit\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/lit/', match[1]);
} else if (match = /^\/codemirror\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/codemirror/', match[1]);
} else if (match = /^\/speedscope\/([\.\w-/]*)$/.exec(request.uri)) {
return staticDirectoryHandler(request, response, 'deps/speedscope/', match[1]);
} else if (match = /^(.*)(\/(?:save|delete)?)$/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]);
} else if ((match = /^\/.well-known\/(.*)/.exec(request.uri)) && request.uri.indexOf("..") == -1) {