From e4afa162d0eae10b65f23b95402e1659b6a05c8d Mon Sep 17 00:00:00 2001 From: RXRD <118821868+RiXelanya@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:37:20 +0700 Subject: [PATCH] fix: raw data download (#937) * fix * fix * Update TestResult.vue --- src/common/lib/pinata-proxy.js | 37 +++++++++++++------ .../Customer/Home/MyTest/TestResult.vue | 10 ++--- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/common/lib/pinata-proxy.js b/src/common/lib/pinata-proxy.js index eb3373cf..1fc16a43 100644 --- a/src/common/lib/pinata-proxy.js +++ b/src/common/lib/pinata-proxy.js @@ -92,17 +92,32 @@ export const decryptFile = (obj, pair) => { else return decryptedFile } -export const downloadDocumentFile = (data, fileName, type) => { - try { - const blob = new Blob([data], { type }); - const a = document.createElement("a"); - - a.download = fileName; - a.href = window.URL.createObjectURL(blob); - a.dataset.downloadurl = ["text/json", a.download, a.href].join(":"); - a.click() - } catch (error) { - console.error(error) +export const downloadDocumentFile = (data, fileName, type, array=false) => { + if (array === true) { + try { + const blob = new Blob(data, { type }); + const a = document.createElement("a"); + + a.download = fileName; + a.href = window.URL.createObjectURL(blob); + a.dataset.downloadurl = ["text/json", a.download, a.href].join(":"); + a.click() + } catch (error) { + console.error(error) + } + } + else { + try { + const blob = new Blob([data], { type }); + const a = document.createElement("a"); + + a.download = fileName; + a.href = window.URL.createObjectURL(blob); + a.dataset.downloadurl = ["text/json", a.download, a.href].join(":"); + a.click() + } catch (error) { + console.error(error) + } } } diff --git a/src/views/Dashboard/Customer/Home/MyTest/TestResult.vue b/src/views/Dashboard/Customer/Home/MyTest/TestResult.vue index 145d8633..f5c54201 100644 --- a/src/views/Dashboard/Customer/Home/MyTest/TestResult.vue +++ b/src/views/Dashboard/Customer/Home/MyTest/TestResult.vue @@ -109,7 +109,7 @@ import CryptoJS from "crypto-js" import { queryDnaTestResults } from "@debionetwork/polkadot-provider" import { queryLabById } from "@debionetwork/polkadot-provider" import { generalDebounce } from "@/common/lib/utils" -import { downloadFile, decryptFile, downloadDocumentFile, getIpfsMetaData, downloadDocumentTestFile } from "@/common/lib/pinata-proxy" +import { downloadFile, decryptFile, downloadDocumentFile, getIpfsMetaData } from "@/common/lib/pinata-proxy" import { queryOrderDetailByOrderID, queryServiceById } from "@debionetwork/polkadot-provider" import { u8aToHex } from "@polkadot/util" import { submitRatingOrder, getRatingByOrderId } from "@/common/lib/api" @@ -294,7 +294,7 @@ export default { name = rows } } - await downloadDocumentTestFile(fileChunks, name[0].metadata.name, fileType) + await downloadDocumentFile(fileChunks, name[0].metadata.name, fileType, true) } else { @@ -327,15 +327,13 @@ export default { const { type, data } = await downloadFile(links[i], true) const decryptedFile = decryptFile([data], pair, type) fileType = type - fileChunks = [...fileChunks, ...(decryptedFile ? decryptedFile : [])] + fileChunks = fileChunks.concat(decryptedFile) if (i === 0) { name = rows } } - const unit8arrays = new Uint8Array(fileChunks) - this.resultLoading = false - await downloadDocumentFile(unit8arrays, name[0].metadata.name, fileType) + await downloadDocumentFile(fileChunks, name[0].metadata.name, fileType, true) } else {