Skip to content

Commit

Permalink
fix: upload in lab (#740)
Browse files Browse the repository at this point in the history
* fix: add 10 MB tolerance on report size

* fix: upload in lab
  • Loading branch information
RiXelanya authored Oct 18, 2023
1 parent 2dc178f commit 175b257
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ 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 < 211000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)"
value => !value || value.size < 220200960 || "The total file size uploaded exceeds the maximum file size allowed (200MB)"
];
},
reportFileRules() {
return [
value => !value || value.type == "application/pdf" || "The files uploaded are not in the supported file formats (PDF)",
value => !value || value.size < 211000000 || "The total file size uploaded exceeds the maximum file size allowed (200MB)"
value => !value || value.size < 220200960 || "The total file size uploaded exceeds the maximum file size allowed (200MB)"
]
}
},
Expand Down Expand Up @@ -546,27 +546,38 @@ export default {
});
},
async upload({ encryptedFileChunks, fileName, documentType, type }) {
async upload({ encryptedFileChunks, fileName, documentType, type, fileSize }) {
this.loadingStatus[documentType] = "Uploading";
const blob = new Blob(encryptedFileChunks, { type });
let links = [] ;
if (blob.size > 200 * 1024 * 1024) {
throw new Error("File size exceeds the maximum allowed limit of 200MB.");
}
try {
for (let i = 0; i < this.totalChunks; i++) {
let data = [`{"seed":${encryptedFileChunks[i].seed},"data":{"nonce":[${encryptedFileChunks[i].data.nonce}],"box":[${encryptedFileChunks[i].data.box}]}}`]
const blob = new Blob(data, { type: type });
try {
const result = await uploadFile({
title: fileName,
type: type,
size: fileSize,
file: blob
});
const result = await uploadFile({
title: fileName,
type: type,
size: blob.size,
file: blob
});
links.push(getFileUrl(result.IpfsHash));
} catch (error) {
console.error("Error on chunk upload", error);
}
}
const link = getFileUrl(result.IpfsHash);
} catch (e) {
console.error("Error on upload", e);
}
this.uploadProgress[documentType] = 0;
this.loadingStatus[documentType] = "";
return link;
return JSON.stringify(links);
},
onEditClick(fileType) {
Expand Down
2 changes: 1 addition & 1 deletion src/web-workers/crypt-worker/encrypt-worker-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ onmessage = function (e) {
(async () => {
const fileBlob = new Blob([e.data.text], { type: e.data.typeFr });
console.log(fileBlob);
const chunkSize = 5 * 1000 * 1024; // 5mb chunk size
const chunkSize = 5 * 1024 * 1024; // 5mb chunk size
const chunksAmount = Math.ceil(fileBlob.size / chunkSize);
postMessage({ chunksAmount })

Expand Down
2 changes: 1 addition & 1 deletion src/web-workers/crypt-worker/encrypt-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ onmessage = function(e) {

(async () => {
const fileBlob = new Blob([ e.data.text ], {type: 'text/plain'});
const chunkSize = 5 * 1000 * 1024; // 5mb chunk size
const chunkSize = 5 * 1024 * 1024; // 5mb chunk size
const chunksAmount = Math.ceil(fileBlob.size / chunkSize);
postMessage({chunksAmount})

Expand Down

0 comments on commit 175b257

Please sign in to comment.