From e9e13596cd25ac0aee3d3924ea05b2b4dc430e23 Mon Sep 17 00:00:00 2001 From: Alvin Dimas Satria Date: Tue, 20 Jun 2023 16:21:36 +0700 Subject: [PATCH 1/3] fix: add .txt file and adjust max size to 200mb --- .../ProcessOrder/ProcessSpecimen/index.vue | 267 ++++++------------ 1 file changed, 90 insertions(+), 177 deletions(-) diff --git a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue index 5309ec2e..a03e6c3d 100644 --- a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue +++ b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue @@ -1,51 +1,31 @@ - {{hasReportError[0]}} - + {{ hasReportError[0] }} +
- + Submit Result
- - - + + + @@ -315,11 +228,11 @@ export default { } }), - async mounted(){ + async mounted() { await this.getFee() const testResult = await queryDnaTestResults(this.api, this.specimenNumber) - if(testResult) this.setUploadFields(testResult) + if (testResult) this.setUploadFields(testResult) this.submitted = this.isSubmitted }, @@ -336,11 +249,11 @@ export default { lastEventData: (state) => state.substrate.lastEventData }), - disableRejectButton(){ + disableRejectButton() { return this.genomeSucceed && this.reportSucceed }, - disableSendButton(){ + disableSendButton() { return !this.disableRejectButton }, @@ -366,9 +279,9 @@ export default { genomeFileRules() { return [ - value => !value || value.type == "text/x-vcard" || value.type == "text/vcard" || value.type == "text/directory" || "The files uploaded are not in the supported file formats (VCF)", - value => !value || value.size < 2000000 || "The total file size uploaded exceeds the maximum file size allowed (2MB)" - ] + value => !value || (value.type == "text/x-vcard" || value.type == "text/vcard" || value.type == "text/directory" || value.type == "text/plain") || "The files uploaded are not in the supported file formats (VCF or TXT)", + value => !value || value.size < 200000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)" + ]; }, reportFileRules() { return [ @@ -390,19 +303,19 @@ export default { async lastEventData(e) { const dataEvent = JSON.parse(e.data.toString()) if (dataEvent[0].sellerId === this.pair.address) { - if (e.method === "OrderFulfilled" && dataEvent[0].orderFlow === "StakingRequestService" ){ + if (e.method === "OrderFulfilled" && dataEvent[0].orderFlow === "StakingRequestService") { await this.finalizeOrder(dataEvent[0].id) } } } }, - methods:{ + methods: { initialData() { this.identity = Kilt.Identity.buildFromMnemonic(this.mnemonic.toString(CryptoJS.enc.Utf8)) }, - async setUploadFields(testResult){ + async setUploadFields(testResult) { const { resultLink, reportLink } = testResult const metadata = async (cid, documentType) => { this.loading[documentType] = true @@ -412,14 +325,14 @@ export default { return rows[0].metadata.name } - if(resultLink){ + if (resultLink) { const genomeFile = { fileName: await metadata(resultLink.split("/").pop(), "genome"), ipfsPath: resultLink } this.files.genome.push(genomeFile) } - if(reportLink){ + if (reportLink) { const reportFile = { fileName: await metadata(reportLink.split("/").pop(), "report"), ipfsPath: reportLink @@ -441,7 +354,7 @@ export default { this.fee = this.web3.utils.fromWei(String(fee.partialFee), "ether") }, - async submitTestResultDocument(callback = () => {}) { + async submitTestResultDocument(callback = () => { }) { try { await submitTestResult( this.api, @@ -488,7 +401,7 @@ export default { this.confirmationDialog = true }, - + async resultReady() { this.isProcessing = true await this.dispatch( @@ -533,7 +446,7 @@ export default { const file = fileInputRef file.fileType = fileType // attach fileType to file, because fileType is not accessible in fr.onload scope const fr = new FileReader() - fr.onload = async function() { + fr.onload = async function () { try { // Encrypt const encrypted = await context.encrypt({ @@ -564,7 +477,7 @@ export default { context.loading[file.fileType] = false // Emit finish - if(file.fileType == "genome") { + if (file.fileType == "genome") { context.genomeSucceed = true context.genomeUploadSucceedDialog = true context.$emit("uploadGenome") @@ -573,7 +486,7 @@ export default { context.loading[file.fileType] = false }) } - if(file.fileType == "report") { + if (file.fileType == "report") { context.reportSucceed = true context.reportUploadSucceedDialog = true context.$emit("uploadReport") @@ -605,7 +518,7 @@ export default { cryptWorker.workerEncrypt.postMessage({ pair, text }) // Access this object in e.data in worker cryptWorker.workerEncrypt.onmessage = event => { // The first returned data is the chunksAmount - if(event.data.chunksAmount) { + if (event.data.chunksAmount) { chunksAmount = event.data.chunksAmount return } @@ -613,7 +526,7 @@ export default { arrChunks.push(event.data) this.encryptProgress[fileType] = arrChunks.length / chunksAmount * 100 - if (arrChunks.length == chunksAmount ) { + if (arrChunks.length == chunksAmount) { resolve({ fileName: fileName, chunks: arrChunks, @@ -634,7 +547,7 @@ export default { async upload({ encryptedFileChunks, fileName, documentType, type, fileSize }) { this.loadingStatus[documentType] = "Uploading" const data = JSON.stringify(encryptedFileChunks) - const blob = new Blob([ data ], { type }) + const blob = new Blob([data], { type }) const result = await uploadFile({ title: fileName, @@ -713,7 +626,7 @@ export default { From 2c2f7e2669ec5731873cd5d3dfda456eea5132c3 Mon Sep 17 00:00:00 2001 From: Alvin Dimas Satria Date: Fri, 7 Jul 2023 07:38:19 +0700 Subject: [PATCH 2/3] fix/uploadVCF: change logic of uploading file --- .../ProcessOrder/ProcessSpecimen/index.vue | 157 ++++++++++-------- 1 file changed, 85 insertions(+), 72 deletions(-) diff --git a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue index a03e6c3d..86ad9497 100644 --- a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue +++ b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue @@ -280,7 +280,7 @@ export default { genomeFileRules() { return [ value => !value || (value.type == "text/x-vcard" || value.type == "text/vcard" || value.type == "text/directory" || value.type == "text/plain") || "The files uploaded are not in the supported file formats (VCF or TXT)", - value => !value || value.size < 200000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)" + value => !value || value.size < 211000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)" ]; }, reportFileRules() { @@ -425,27 +425,37 @@ export default { }, addFileUploadEventListener(fileInputRef, fileType) { - this.hasGenomeError = [] - this.hasReportError = [] + this.hasGenomeError = []; + this.hasReportError = []; - if (fileType === "genome") this.genomeFileRules.forEach(rule => { - const resultRule = rule.call(this, fileInputRef) + if (fileType === "genome") { + this.genomeFileRules.forEach(rule => { + const resultRule = rule.call(this, fileInputRef); - if (typeof resultRule === "string") this.hasGenomeError.push(resultRule) - }) - if (fileType === "report") this.reportFileRules.forEach(rule => { - const resultRule = rule.call(this, fileInputRef) + if (typeof resultRule === "string") { + this.hasGenomeError.push(resultRule); + } + }); + } + if (fileType === "report") { + this.reportFileRules.forEach(rule => { + const resultRule = rule.call(this, fileInputRef); - if (typeof resultRule === "string") this.hasReportError.push(resultRule) - }); - const context = this + if (typeof resultRule === "string") { + this.hasReportError.push(resultRule); + } + }); + } - if (this.hasGenomeError.length && fileType === "genome" || this.hasReportError.length && fileType === "report") return + if ((this.hasGenomeError.length && fileType === "genome") || (this.hasReportError.length && fileType === "report")) { + return; + } - context.loading[fileType] = true - const file = fileInputRef - file.fileType = fileType // attach fileType to file, because fileType is not accessible in fr.onload scope - const fr = new FileReader() + const context = this; + context.loading[fileType] = true; + const file = fileInputRef; + file.fileType = fileType; + const fr = new FileReader(); fr.onload = async function () { try { // Encrypt @@ -454,9 +464,9 @@ export default { fileType: file.fileType, fileName: file.name, fileSize: file.size - }) + }); - const { chunks, fileName: encFileName, fileType: encFileType, fileSize } = encrypted + const { chunks, fileName: encFileName, fileType: encFileType, fileSize } = encrypted; // Upload const uploaded = await context.upload({ encryptedFileChunks: chunks, @@ -464,104 +474,107 @@ export default { documentType: encFileType, type: file.type, fileSize - }) - - // files is array, but currently only support storing 1 file for each type - + }); if (context.files[fileType].length > 0) { - context.files[fileType][0] = { fileName: file.name, fileType, ipfsPath: uploaded } + context.files[fileType][0] = { fileName: file.name, fileType, ipfsPath: uploaded }; } else { - context.files[fileType].push({ fileName: file.name, fileType, ipfsPath: uploaded }) + context.files[fileType].push({ fileName: file.name, fileType, ipfsPath: uploaded }); } - context.loading[file.fileType] = false + context.loading[file.fileType] = false; // Emit finish - if (file.fileType == "genome") { - context.genomeSucceed = true - context.genomeUploadSucceedDialog = true - context.$emit("uploadGenome") + if (file.fileType === "genome") { + context.genomeSucceed = true; + context.genomeUploadSucceedDialog = true; + context.$emit("uploadGenome"); context.submitTestResultDocument(() => { - context.loading[file.fileType] = false - }) + context.loading[file.fileType] = false; + }); } - if (file.fileType == "report") { - context.reportSucceed = true - context.reportUploadSucceedDialog = true - context.$emit("uploadReport") + if (file.fileType === "report") { + context.reportSucceed = true; + context.reportUploadSucceedDialog = true; + context.$emit("uploadReport"); context.submitTestResultDocument(() => { - context.loading[file.fileType] = false - }) + context.loading[file.fileType] = false; + }); } } catch (err) { - console.error(err) + console.error(err); } - } - fr.readAsArrayBuffer(file) + }; + fr.readAsArrayBuffer(file); }, encrypt({ text, fileType, fileName }) { - const context = this - this.loadingStatus[fileType] = "Encrypting" + const context = this; + this.loadingStatus[fileType] = "Encrypting"; return new Promise((resolve, reject) => { try { const pair = { secretKey: u8aToHex(context.identity.boxKeyPair.secretKey), - publicKey: context.publicKey // Customer's box publicKey - } + publicKey: context.publicKey + }; - const arrChunks = [] - let chunksAmount - cryptWorker.workerEncrypt.postMessage({ pair, text }) // Access this object in e.data in worker + const arrChunks = []; + let chunksAmount; + cryptWorker.workerEncrypt.postMessage({ pair, text }); cryptWorker.workerEncrypt.onmessage = event => { - // The first returned data is the chunksAmount if (event.data.chunksAmount) { - chunksAmount = event.data.chunksAmount - return + chunksAmount = event.data.chunksAmount; + return; } - arrChunks.push(event.data) - this.encryptProgress[fileType] = arrChunks.length / chunksAmount * 100 + arrChunks.push(event.data); + this.encryptProgress[fileType] = (arrChunks.length / chunksAmount) * 100; - if (arrChunks.length == chunksAmount) { + if (arrChunks.length === chunksAmount) { resolve({ fileName: fileName, chunks: arrChunks, fileType: fileType - }) - // Cleanup - this.encryptProgress[fileType] = 0 - this.loadingStatus[fileType] = "" + }); + this.encryptProgress[fileType] = 0; + this.loadingStatus[fileType] = ""; } - } - + }; } catch (err) { - reject(new Error(err.message)) + reject(new Error(err.message)); } - }) + }); }, - async upload({ encryptedFileChunks, fileName, documentType, type, fileSize }) { - this.loadingStatus[documentType] = "Uploading" - const data = JSON.stringify(encryptedFileChunks) - const blob = new Blob([data], { type }) + async upload({ encryptedFileChunks, fileName, documentType, type }) { + this.loadingStatus[documentType] = "Uploading"; + const blob = new Blob(encryptedFileChunks, { type }); + + if (blob.size > 200 * 1024 * 1024) { + throw new Error("File size exceeds the maximum allowed limit of 200MB."); + } + + const formData = new FormData(); + formData.append("file", blob); + formData.append("type", type) + formData.append("size", blob.size) + formData.append("title", fileName) const result = await uploadFile({ title: fileName, type: type, - size: fileSize, + size: blob.size, file: blob - }) + }); - const link = getFileUrl(result.IpfsHash) + const link = getFileUrl(result.IpfsHash); - this.uploadProgress[documentType] = 0 - this.loadingStatus[documentType] = "" + this.uploadProgress[documentType] = 0; + this.loadingStatus[documentType] = ""; - return link + return link; }, onEditClick(fileType) { From 8570ba4bf17a51ed4466ea926624351493e15273 Mon Sep 17 00:00:00 2001 From: Alvin Dimas Satria Date: Mon, 17 Jul 2023 09:22:38 +0700 Subject: [PATCH 3/3] fix: upload pdf report on lab --- .../Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue index 86ad9497..3cda1863 100644 --- a/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue +++ b/src/views/Dashboard/Lab/OrderHistory/ProcessOrder/ProcessSpecimen/index.vue @@ -286,7 +286,7 @@ export default { reportFileRules() { return [ value => !value || value.type == "application/pdf" || "The files uploaded are not in the supported file formats (PDF)", - value => !value || value.size < 2000000 || "The total file size uploaded exceeds the maximum file size allowed (2MB)" + value => !value || value.size < 211000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)" ] } },