Skip to content

Commit 10c5a2c

Browse files
fix(AB-700): Uploaded PDF doesn't render or freezes page
1 parent 25745de commit 10c5a2c

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/ui/src/components/core/embed/CorePDF.vue

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import WdsIcon from "@/wds/WdsIcon.vue";
5858
import { validatorArrayOfString } from "@/constants/validators";
5959
import type { PDFSrc } from "@tato30/vue-pdf";
6060
import { dataURLToArrayBuffer } from "@/utils/base64";
61+
import type { EncodedFile } from "@/composables/useFilesEncoder/useFilesEncoder";
62+
import { isPlainObject } from "@/utils/object";
6163
6264
const description = "A component to embed PDF documents.";
6365
@@ -133,10 +135,47 @@ const loading = ref(false);
133135
const pagesLoaded = ref(0);
134136
const highlightsList = ref([]);
135137
138+
function isEncodedFile(input: unknown): input is EncodedFile {
139+
return (
140+
isPlainObject(input) &&
141+
"name" in input &&
142+
"type" in input &&
143+
"data" in input &&
144+
typeof input.data === "string" &&
145+
input.data.startsWith("data:")
146+
);
147+
}
148+
149+
function extractDataURLFromSource(source: unknown): string | undefined {
150+
if (typeof source !== "string" || !source.trim()) {
151+
return undefined;
152+
}
153+
154+
// Try to parse as JSON array (file upload format)
155+
try {
156+
const parsed = JSON.parse(source);
157+
if (Array.isArray(parsed) && parsed.length > 0) {
158+
const firstFile = parsed[0];
159+
if (isEncodedFile(firstFile)) {
160+
return firstFile.data;
161+
}
162+
}
163+
} catch {
164+
// Not valid JSON or not in expected format, continue to use source directly
165+
}
166+
167+
// Return source as-is (could be a direct URL or data URL)
168+
return source;
169+
}
170+
136171
const pdfData = computed(() => {
137172
if (!fields.source?.value) return undefined;
173+
174+
const dataURL = extractDataURLFromSource(fields.source.value);
175+
if (!dataURL) return undefined;
176+
138177
try {
139-
return dataURLToArrayBuffer(fields.source.value);
178+
return dataURLToArrayBuffer(dataURL);
140179
} catch {
141180
return undefined;
142181
}

0 commit comments

Comments
 (0)