fix
This commit is contained in:
parent
398f9e6926
commit
52db89e05b
|
|
@ -333,12 +333,32 @@ export const _ = {
|
||||||
} else if (pathname === "index.html" || pathname === "_") {
|
} else if (pathname === "index.html" || pathname === "_") {
|
||||||
return index_html;
|
return index_html;
|
||||||
} else {
|
} else {
|
||||||
const res = dir.path(`/app/srv/core/${pathname}`);
|
const src_path = dir.path(`/app/srv/core/${pathname}`);
|
||||||
const file = Bun.file(res);
|
|
||||||
if (!(await file.exists())) {
|
if (!g.main_cache) g.main_cache = {};
|
||||||
return index_html;
|
if (!g.main_cache[src_path]) {
|
||||||
|
if (!g.br) {
|
||||||
|
g.br = await brotliPromise;
|
||||||
|
}
|
||||||
|
const file = Bun.file(src_path);
|
||||||
|
if (await file.exists()) {
|
||||||
|
g.main_cache[src_path] = {
|
||||||
|
content: g.br.compress(
|
||||||
|
new Uint8Array(await Bun.file(src_path).arrayBuffer())
|
||||||
|
),
|
||||||
|
type: mime.getType(src_path) || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new Response(file);
|
if (g.main_cache[src_path]) {
|
||||||
|
return new Response(g.main_cache[src_path].content, {
|
||||||
|
headers: {
|
||||||
|
"content-encoding": "br",
|
||||||
|
"content-type": g.main_cache[src_path].type,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return index_html;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,8 @@ export const g = global as unknown as {
|
||||||
code_index_compressing: Set<string>;
|
code_index_compressing: Set<string>;
|
||||||
code_index_cache: Record<
|
code_index_cache: Record<
|
||||||
string,
|
string,
|
||||||
Record<string, { ts: number; content: any;type: string; }>
|
Record<string, { ts: number; content: any; type: string }>
|
||||||
>;
|
>;
|
||||||
br: BrotliWasmType
|
main_cache: Record<string, { content: any; type: string }>;
|
||||||
|
br: BrotliWasmType;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue