mirror of
https://github.com/zadam/trilium.git
synced 2026-01-10 08:34:25 +01:00
chore(pdfjs): address requested changes
This commit is contained in:
parent
20c2652013
commit
fb4e912ed0
@ -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() {
|
||||
|
||||
@ -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>`
|
||||
);
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user