From 3d73a49386abb5aec59d6db510b60962ddb3e5c0 Mon Sep 17 00:00:00 2001 From: William Chong Date: Tue, 25 Jun 2024 12:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Transfer=20arraybuffer=20d?= =?UTF-8?q?irectly=20in=20pdf=20reader=20postMessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/reader/pdf.vue | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/pages/reader/pdf.vue b/src/pages/reader/pdf.vue index 52b651873..3d393a253 100644 --- a/src/pages/reader/pdf.vue +++ b/src/pages/reader/pdf.vue @@ -32,7 +32,7 @@ export default { return { isLoading: false, isIframeReady: false, - base64FileData: null, + fileData: null, }; }, computed: { @@ -60,18 +60,20 @@ export default { if (event.origin !== this.iframeOrigin) return; if (event.data === 'ready') { this.isIframeReady = true; - if (this.base64FileData) { + if (this.fileData) { + const buffer = this.fileData; this.$refs.pdfIframe?.contentWindow?.postMessage( - JSON.stringify({ - action: 'openBase64File', + { + action: 'openArrayBufferFile', data: { - data: this.base64FileData, + data: buffer, name: this.nftName, }, - }), - this.iframeOrigin + }, + this.iframeOrigin, + [buffer] ); - this.base64FileData = null; + this.fileData = null; } } }, @@ -79,19 +81,20 @@ export default { try { this.isLoading = true; const buffer = await this.getFileBuffer('reader-pdf'); - this.base64FileData = Buffer.from(buffer).toString('base64'); if (this.isIframeReady) { this.$refs.pdfIframe?.contentWindow?.postMessage( - JSON.stringify({ - action: 'openBase64File', + { + action: 'openArrayBufferFile', data: { - data: this.base64FileData, + data: buffer, name: this.nftName, }, - }), - this.iframeOrigin + }, + this.iframeOrigin, + [buffer] ); - this.base64FileData = null; + } else { + this.fileData = buffer; } this.isLoading = false; } catch (err) {