chore(pdfjs): address requested changes

This commit is contained in:
Elian Doran 2026-01-04 21:08:39 +02:00
parent 20c2652013
commit fb4e912ed0
No known key found for this signature in database
3 changed files with 11 additions and 5 deletions

View File

@ -24,11 +24,17 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
getData() {
if (!iframeRef.current?.contentWindow) return undefined;
return new Promise<Blob>((resolve) => {
return new Promise<Blob>((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("Timeout while waiting for blob response"));
}, 10_000);
const onMessageReceived = (event: PdfMessageEvent) => {
if (event.data.type !== "pdfjs-viewer-blob") return;
if (event.data.noteId !== note.noteId || event.data.ntxId !== noteContext.ntxId) return;
const blob = new Blob([event.data.data as Uint8Array<ArrayBuffer>], { type: note.mime });
clearTimeout(timeout);
window.removeEventListener("message", onMessageReceived);
resolve(blob);
};
@ -36,7 +42,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
window.addEventListener("message", onMessageReceived);
iframeRef.current?.contentWindow?.postMessage({
type: "trilium-request-blob",
});
}, window.location.origin);
});
},
onContentChange() {

View File

@ -4,7 +4,7 @@ import { build as esbuild } from "esbuild";
import { LOCALES } from "@triliumnext/commons";
import { watch } from "chokidar";
import { readFileSync, writeFileSync } from "fs";
import packageJson from "../package.json" with { type: "json "};
import packageJson from "../package.json" with { type: "json " };
const build = new BuildHelper("packages/pdfjs-viewer");
const watchMode = process.argv.includes("--watch");
@ -71,7 +71,7 @@ function patchCacheBuster(htmlFilePath: string) {
`<link rel="stylesheet" href="custom.css" />`,
`<link rel="stylesheet" href="custom.css?v=${version}" />`);
html = html.replace(
`<script src="custom.mjs" type="module"></script>` ,
`<script src="custom.mjs" type="module"></script>`,
`<script src="custom.mjs?v=${version}" type="module"></script>`
);

View File

@ -82,7 +82,7 @@ function manageSave() {
data,
ntxId: window.TRILIUM_NTX_ID,
noteId: window.TRILIUM_NOTE_ID
} satisfies PdfDocumentBlobResultMessage, window.location.origin)
} satisfies PdfDocumentBlobResultMessage, window.location.origin);
}
});