Skip to content

Commit

Permalink
fix: raw data download (#937)
Browse files Browse the repository at this point in the history
* fix

* fix

* Update TestResult.vue
  • Loading branch information
RiXelanya authored Dec 18, 2023
1 parent 5d3a9d9 commit e4afa16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
37 changes: 26 additions & 11 deletions src/common/lib/pinata-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/views/Dashboard/Customer/Home/MyTest/TestResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e4afa16

Please sign in to comment.