This commit is contained in:
2026-07-15 18:27:24 -05:00
parent 741b38b4f6
commit 5c69c40453
6 changed files with 3338 additions and 979 deletions

18
main.ts
View File

@@ -19,10 +19,10 @@ import STYLES_CSS from "./web/styles.css" with { type: "text" };
import SAMPLE_DOCUMENTS from "./sample-data/buyers_vision_anonymous.json" with {
type: "json",
};
import PDFJS_LIB_TEXT from "pdfjs-dist/build/pdf.min.mjs" with {
import PDFJS_LIB_TEXT from "pdfjs-dist/legacy/build/pdf.min.mjs" with {
type: "text",
};
import PDFJS_WORKER_TEXT from "pdfjs-dist/build/pdf.worker.min.mjs" with {
import PDFJS_WORKER_TEXT from "pdfjs-dist/legacy/build/pdf.worker.min.mjs" with {
type: "text",
};
@@ -357,7 +357,10 @@ Deno.serve(async (request) => {
// ---- PDF prepare endpoint ----
if (url.pathname === "/api/pdf/prepare" && request.method === "POST") {
try {
const body = await request.json() as { index?: number };
const body = await request.json() as {
index?: number;
requestId?: string;
};
const index = body.index;
const doc = documents[index!];
if (!Number.isInteger(index) || !doc) {
@@ -366,7 +369,8 @@ Deno.serve(async (request) => {
const sourcePath = resolvePdfPath(settings.pdfBaseDirectory, doc);
const relative = doc._letter + "/" + doc.file_name;
console.log(`${PREFIX} PDF prepare requested: ${relative}`);
const reqTag = body.requestId ? `PDF ${body.requestId}` : "PDF";
console.log(`${PREFIX} ${reqTag} prepare requested: ${relative}`);
const startTime = performance.now();
const cacheResult = await cacheOrGetPdf(sourcePath);
@@ -389,7 +393,7 @@ Deno.serve(async (request) => {
const elapsed = Math.round(performance.now() - startTime);
const status = cacheResult.stale ? "refresh" : "hit";
console.log(
`${PREFIX} PDF disk cache ${status} in ${elapsed}ms, token created`,
`${PREFIX} ${reqTag} disk cache ${status} in ${elapsed}ms, token created`,
);
return json({
@@ -449,7 +453,7 @@ Deno.serve(async (request) => {
}
// ---- PDF.js library assets ----
if (url.pathname === "/pdfjs/pdf.min.mjs") {
if (url.pathname === "/pdfjs/legacy/pdf.min.mjs") {
return new Response(PDFJS_LIB_TEXT, {
headers: {
"content-type": "text/javascript; charset=utf-8",
@@ -458,7 +462,7 @@ Deno.serve(async (request) => {
});
}
if (url.pathname === "/pdfjs/pdf.worker.min.mjs") {
if (url.pathname === "/pdfjs/legacy/pdf.worker.min.mjs") {
return new Response(PDFJS_WORKER_TEXT, {
headers: {
"content-type": "text/javascript; charset=utf-8",