Moving things off of CDNs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3698 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-12-22 13:51:49 +00:00
parent 9faa4c9ca6
commit ba87f9acaa
10 changed files with 12109 additions and 11 deletions

View File

@ -336,7 +336,7 @@ async function speedScopeHandler(request, response, uri) {
}
}
function sendData(response, data) {
function sendData(response, data, type) {
if (data) {
if (startsWithBytes(data, [0xff, 0xd8, 0xff, 0xdb]) ||
startsWithBytes(data, [0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01]) ||
@ -352,7 +352,7 @@ function sendData(response, data) {
response.writeHead(200, {"Content-Type": "image/gif", "Content-Length": data.byteLength});
response.end(data);
} else {
response.writeHead(200, {"Content-Type": "text/javascript; charset=utf-8", "Content-Length": data.byteLength});
response.writeHead(200, {"Content-Type": type || "text/javascript; charset=utf-8", "Content-Length": data.byteLength});
response.end(data);
}
} else {
@ -371,6 +371,14 @@ async function getBlobOrContent(id) {
}
}
function guessType(path) {
const k_extension_to_type = {
'css': 'text/css',
};
var extension = path.split('.').pop();
return k_extension_to_type[extension];
}
async function blobHandler(request, response, blobId, uri) {
var found = false;
if (!found) {
@ -429,6 +437,7 @@ async function blobHandler(request, response, blobId, uri) {
response.end("/" + newBlobId);
} else {
var data;
var type;
if (match = /^\/\~(\w+)\/(\w+)$/.exec(blobId)) {
var db = new Database(match[1]);
var id = await db.get('path:' + match[2]);
@ -437,6 +446,7 @@ async function blobHandler(request, response, blobId, uri) {
var app = JSON.parse(data);
data = app.files[uri.substring(1)];
data = await getBlobOrContent(data);
type = guessType(uri);
}
} else {
data = utf8Decode(await getBlobOrContent(blobId));
@ -444,7 +454,7 @@ async function blobHandler(request, response, blobId, uri) {
data = app.files[uri.substring(1)];
data = await getBlobOrContent(data);
}
sendData(response, data);
sendData(response, data, type);
}
}
}