Skip to content

Commit

Permalink
fix: Download Genetic Analysis Report (#905)
Browse files Browse the repository at this point in the history
* Update Result.vue

* Update Result.vue
  • Loading branch information
RiXelanya authored Oct 10, 2023
1 parent 7be90a3 commit 3c90fe6
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/views/Dashboard/Customer/Home/GeneticData/Result.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
queryGeneticAnalysisOrderById,
queryGeneticAnalystServicesByHashId
} from "@debionetwork/polkadot-provider"
import { downloadFile, decryptFile } from "@/common/lib/pinata-proxy"
import { downloadFile, decryptFile, downloadDocumentFile } from "@/common/lib/pinata-proxy"
import { chevronLeftIcon } from "@debionetwork/ui-icons"
Expand Down Expand Up @@ -122,16 +122,29 @@ export default {
},
async parseResult(recordLink) {
let fileChunks = []
let fileType
const computeFileName = "Result"
try {
this.isLoading = true
const pair = { publicKey: this.publicKey, secretKey: this.secretKey }
const { type, data } = await downloadFile(recordLink, true)
const decryptedFile = decryptFile(data, pair, type)
const fileBlob = window.URL.createObjectURL(new Blob([decryptedFile], { type }))
this.result = fileBlob
this.isLoading = true
if (/^\[/.test(recordLink)) {
const links = JSON.parse(recordLink)
for (let i = 0; i < links.length; i++) {
const { type, data } = await downloadFile(links[i], true)
const decryptedFile = decryptFile([data], pair, type)
fileType = type
fileChunks = [...fileChunks, ...(decryptedFile ? decryptedFile : [])]
}
}
else {
const { type, data } = await downloadFile(recordLink, true)
const decryptedFile = decryptFile([data], pair, type)
fileType = type
fileChunks = [...fileChunks, ...(decryptedFile ? decryptedFile : [])]
}
const unit8arrays = new Uint8Array(fileChunks)
await downloadDocumentFile(unit8arrays, computeFileName, fileType)
} catch {
this.message = "Oh no! Something went wrong. Please try again later"
} finally {
Expand Down

0 comments on commit 3c90fe6

Please sign in to comment.