This commit is contained in:
Rizky 2024-07-02 10:02:52 +07:00
parent 52db89e05b
commit 078f89dcb4
1 changed files with 61 additions and 79 deletions

View File

@ -43,30 +43,6 @@ export const _ = {
const path = dir.data(`/code/${site_id}/site/typings.d.ts`);
const file = Bun.file(path);
if (await file.exists()) {
// const glob = new Glob("type_def*");
// for await (const item of glob.scan(
// dir.data(`/code/${site_id}/site`)
// )) {
// const stamp = parseInt(item.split(".")[1]);
// if (file.lastModified !== stamp) {
// await removeAsync(dir.data(`/code/${site_id}/site/${item}`));
// } else {
// return new Response(
// Bun.gzipSync(
// await Bun.file(
// dir.data(`/code/${site_id}/site/${item}`)
// ).arrayBuffer()
// ),
// {
// headers: {
// "content-type": "application/json",
// "content-encoding": "gzip",
// },
// }
// );
// }
// }
try {
const res = JSON.stringify(await parseTypeDef(path));
await Bun.write(
@ -114,6 +90,24 @@ export const _ = {
const arr = pathname.split("/").slice(2);
const codepath = arr.join("/");
const build_path = code.path(site_id, "site", "build", codepath);
if (
g.code_index_cache[site_id] &&
g.code_index_cache[site_id][build_path] &&
g.code_index_cache[site_id][build_path].content
) {
return new Response(
g.code_index_cache[site_id][build_path].content,
{
headers: {
"content-encoding": "br",
"content-type": g.code_index_cache[site_id][build_path].type,
},
}
);
}
try {
let file = Bun.file(build_path);
if (!(await file.exists())) {
@ -141,7 +135,8 @@ export const _ = {
(g.code_index_cache[site_id][build_path] &&
g.code_index_cache[site_id][build_path].ts !== ts)
) {
if (!g.code_index_compressing) g.code_index_compressing = new Set();
if (!g.code_index_compressing)
g.code_index_compressing = new Set();
const key = `${site_id}-${build_path}`;
if (!g.code_index_compressing.has(key)) {
@ -162,22 +157,6 @@ export const _ = {
}
}
if (
g.code_index_cache[site_id] &&
g.code_index_cache[site_id][build_path] &&
g.code_index_cache[site_id][build_path].content
) {
return new Response(
g.code_index_cache[site_id][build_path].content,
{
headers: {
"content-encoding": "br",
"content-type": g.code_index_cache[site_id][build_path].type,
},
}
);
}
return new Response(
await gzipAsync(new Uint8Array(await file.arrayBuffer())),
{
@ -187,6 +166,9 @@ export const _ = {
},
}
);
} catch (e) {
return new Response("");
}
}
case "route": {
if (!g.route_cache) g.route_cache = {};