From e6dac3d767491eeb036f9de024518e05c034ed5f Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 2 Jul 2024 13:52:00 +0700 Subject: [PATCH] rebuild --- app/srv/api/prod.ts | 78 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/app/srv/api/prod.ts b/app/srv/api/prod.ts index d33caf65..5a590d18 100644 --- a/app/srv/api/prod.ts +++ b/app/srv/api/prod.ts @@ -86,56 +86,54 @@ export const _ = { } return new Response(""); } - case "code": { + case "code": { 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 && - 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())) { - const root = `/code/${site_id}/site/src`; - await ensureLib(root, site_id); - await ensureFiles(root, site_id); - await initFrontEnd(root, site_id); - await new Promise((resolve) => { - const ival = setInterval(async () => { - file = Bun.file(build_path); - const exists = await file.exists(); - if (exists) { - clearInterval(ival); - resolve(); - } - }, 100); - }); + const ts = file.lastModified; + if ( + g.code_index_cache && + g.code_index_cache[site_id] && + g.code_index_cache[site_id][build_path] && + g.code_index_cache[site_id][build_path].content && + g.code_index_cache[site_id][build_path] && + g.code_index_cache[site_id][build_path].ts === ts + ) { + 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, + }, + } + ); } - const ts = file.lastModified; + // if (!(await file.exists())) { + // const root = `/code/${site_id}/site/src`; + // await ensureLib(root, site_id); + // await ensureFiles(root, site_id); + // await initFrontEnd(root, site_id); + // await new Promise((resolve) => { + // const ival = setInterval(async () => { + // file = Bun.file(build_path); + // const exists = await file.exists(); + // if (exists) { + // clearInterval(ival); + // resolve(); + // } + // }, 100); + // }); + // } + if (!g.code_index_cache) g.code_index_cache = {}; if (!g.code_index_cache[site_id]) g.code_index_cache[site_id] = {}; - if ( - !g.code_index_cache[site_id][build_path] || - (g.code_index_cache[site_id][build_path] && - g.code_index_cache[site_id][build_path].ts !== ts) - ) { + if (!g.code_index_cache[site_id][build_path]) { if (!g.code_index_compressing) g.code_index_compressing = new Set();