From 405a12ef07c7ede1bba964bc1f8e45621cd38913 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 02:39:52 +0000 Subject: [PATCH 1/4] Initial plan From 5499150395ea1e0eb921e8e4ad08cbc15a80e9fc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 02:46:24 +0000 Subject: [PATCH 2/4] fix: add pdfjs at compatibility polyfill Agent-Logs-Url: https://github.com/kekingcn/kkFileView/sessions/287f0212-d368-4b59-ae70-0374fb3fe76f Co-authored-by: klboke <18591662+klboke@users.noreply.github.com> --- .../static/pdfjs/build/pdf.worker.mjs | 3 +- .../static/pdfjs/web/compatibility.mjs | 42 +++++++++++++++++++ .../resources/static/pdfjs/web/viewer.html | 1 + .../keking/PdfViewerCompatibilityTests.java | 32 ++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 server/src/main/resources/static/pdfjs/web/compatibility.mjs create mode 100644 server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java diff --git a/server/src/main/resources/static/pdfjs/build/pdf.worker.mjs b/server/src/main/resources/static/pdfjs/build/pdf.worker.mjs index 34462b0c..af9a06bb 100644 --- a/server/src/main/resources/static/pdfjs/build/pdf.worker.mjs +++ b/server/src/main/resources/static/pdfjs/build/pdf.worker.mjs @@ -24,6 +24,7 @@ * pdfjsVersion = 5.4.530 * pdfjsBuild = 50cc4adac */ +import "../web/compatibility.mjs"; /******/ var __webpack_modules__ = ({ /***/ 34: @@ -66999,4 +67000,4 @@ globalThis.pdfjsWorker = { export { WorkerMessageHandler }; -//# sourceMappingURL=pdf.worker.mjs.map \ No newline at end of file +//# sourceMappingURL=pdf.worker.mjs.map diff --git a/server/src/main/resources/static/pdfjs/web/compatibility.mjs b/server/src/main/resources/static/pdfjs/web/compatibility.mjs new file mode 100644 index 00000000..794fc716 --- /dev/null +++ b/server/src/main/resources/static/pdfjs/web/compatibility.mjs @@ -0,0 +1,42 @@ +const atTargets = [ + Array, + String, + Int8Array, + Uint8Array, + Uint8ClampedArray, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + globalThis.BigInt64Array, + globalThis.BigUint64Array, +]; + +function installAtPolyfill(target) { + if (!target?.prototype || typeof target.prototype.at === "function") { + return; + } + Object.defineProperty(target.prototype, "at", { + value(index) { + const length = this.length >>> 0; + let relativeIndex = Number(index) || 0; + if (!Number.isFinite(relativeIndex)) { + relativeIndex = 0; + } + relativeIndex = relativeIndex < 0 ? Math.ceil(relativeIndex) : Math.floor(relativeIndex); + const resolvedIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex; + if (resolvedIndex < 0 || resolvedIndex >= length) { + return undefined; + } + return this[resolvedIndex]; + }, + writable: true, + configurable: true, + }); +} + +for (const target of atTargets) { + installAtPolyfill(target); +} diff --git a/server/src/main/resources/static/pdfjs/web/viewer.html b/server/src/main/resources/static/pdfjs/web/viewer.html index 6a4ba5d1..629bb858 100644 --- a/server/src/main/resources/static/pdfjs/web/viewer.html +++ b/server/src/main/resources/static/pdfjs/web/viewer.html @@ -29,6 +29,7 @@ See https://github.com/adobe-type-tools/cmap-resources + diff --git a/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java b/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java new file mode 100644 index 00000000..84f92633 --- /dev/null +++ b/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java @@ -0,0 +1,32 @@ +package cn.keking; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +public class PdfViewerCompatibilityTests { + + @Test + void shouldLoadCompatibilityModuleBeforePdfJs() throws IOException { + String viewerHtml = readResource("/static/pdfjs/web/viewer.html"); + + assert viewerHtml.contains(""); + assert viewerHtml.indexOf("compatibility.mjs") < viewerHtml.indexOf("../build/pdf.mjs"); + } + + @Test + void shouldLoadCompatibilityModuleInPdfWorker() throws IOException { + String workerScript = readResource("/static/pdfjs/build/pdf.worker.mjs"); + + assert workerScript.contains("import \"../web/compatibility.mjs\";"); + } + + private String readResource(String resourcePath) throws IOException { + try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) { + assert inputStream != null; + return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + } + } +} From 530304b832e1cbe70e74ecab176684cf41e943ba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 02:48:24 +0000 Subject: [PATCH 3/4] test: use junit assertions for pdf viewer compatibility Agent-Logs-Url: https://github.com/kekingcn/kkFileView/sessions/287f0212-d368-4b59-ae70-0374fb3fe76f Co-authored-by: klboke <18591662+klboke@users.noreply.github.com> --- .../java/cn/keking/PdfViewerCompatibilityTests.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java b/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java index 84f92633..0f9c9c5f 100644 --- a/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java +++ b/server/src/test/java/cn/keking/PdfViewerCompatibilityTests.java @@ -6,26 +6,29 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class PdfViewerCompatibilityTests { @Test void shouldLoadCompatibilityModuleBeforePdfJs() throws IOException { String viewerHtml = readResource("/static/pdfjs/web/viewer.html"); - assert viewerHtml.contains(""); - assert viewerHtml.indexOf("compatibility.mjs") < viewerHtml.indexOf("../build/pdf.mjs"); + assertTrue(viewerHtml.contains("")); + assertTrue(viewerHtml.indexOf("compatibility.mjs") < viewerHtml.indexOf("../build/pdf.mjs")); } @Test void shouldLoadCompatibilityModuleInPdfWorker() throws IOException { String workerScript = readResource("/static/pdfjs/build/pdf.worker.mjs"); - assert workerScript.contains("import \"../web/compatibility.mjs\";"); + assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";")); } private String readResource(String resourcePath) throws IOException { try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) { - assert inputStream != null; + assertNotNull(inputStream); return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); } } From 3fbf0156e251f6800b8f9c94ebace1bd3791264d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 02:50:17 +0000 Subject: [PATCH 4/4] fix: refine pdfjs at compatibility polyfill Agent-Logs-Url: https://github.com/kekingcn/kkFileView/sessions/287f0212-d368-4b59-ae70-0374fb3fe76f Co-authored-by: klboke <18591662+klboke@users.noreply.github.com> --- .../src/main/resources/static/pdfjs/web/compatibility.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/resources/static/pdfjs/web/compatibility.mjs b/server/src/main/resources/static/pdfjs/web/compatibility.mjs index 794fc716..2d222949 100644 --- a/server/src/main/resources/static/pdfjs/web/compatibility.mjs +++ b/server/src/main/resources/static/pdfjs/web/compatibility.mjs @@ -21,11 +21,11 @@ function installAtPolyfill(target) { Object.defineProperty(target.prototype, "at", { value(index) { const length = this.length >>> 0; - let relativeIndex = Number(index) || 0; - if (!Number.isFinite(relativeIndex)) { + let relativeIndex = Number(index); + if (Number.isNaN(relativeIndex)) { relativeIndex = 0; } - relativeIndex = relativeIndex < 0 ? Math.ceil(relativeIndex) : Math.floor(relativeIndex); + relativeIndex = Math.trunc(relativeIndex); const resolvedIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex; if (resolvedIndex < 0 || resolvedIndex >= length) { return undefined;