Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upload in lab #740

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading