Skip to content

Commit

Permalink
Revert commit (bug fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWTE committed Nov 15, 2023
1 parent c3f95c8 commit 8db5d7c
Showing 1 changed file with 54 additions and 64 deletions.
118 changes: 54 additions & 64 deletions app/file/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,81 +86,71 @@ function UploadFile() {

const MAX_FILE_SIZE = 2.5 * 1024 * 1024 * 1024; // 2.5GB in bytes

const handleFileChange = (event: any) => {
const file = event.target.files[0]; // assuming single file upload
if (file.size > MAX_FILE_SIZE) {
toast.error('File size exceeds the maximum limit of 2.5GB');
return;
}
setFiles([file]);
};

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const target = e.target as typeof e.target & {
bruteforceSafe: { checked: boolean };
password: { value: string };
endToEndEncryption: { checked: boolean };
autoDeletion: { value: string };
const handleFileChange = (event: any) => {
const file = event.target.files[0]; // assuming single file upload
if (file.size > MAX_FILE_SIZE) {
toast.error('File size exceeds the maximum limit of 2.5GB');
return;
}
setFiles([file]);
};



setIsUploading(true);

const bruteforceSafe = target.bruteforceSafe.checked;
const password = target.password.value;
const endToEndEncryption = target.endToEndEncryption.checked;
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const target = e.target as typeof e.target & {
bruteforceSafe: { checked: boolean };
password: { value: string };
endToEndEncryption: { checked: boolean };
autoDeletion: { value: string };
};

const passwordSet = password !== "";
const encrypted_password = passwordSet ? await hashPassword(password) : null;
setIsUploading(true);

const chunkSize = 1024 * 1024 * 5; // 5 MB
const totalChunks = Math.ceil(files[0].size / chunkSize);
const bruteforceSafe = target.bruteforceSafe.checked;
const password = target.password.value;
const endToEndEncryption = target.endToEndEncryption.checked;

for (let i = 0; i < totalChunks; i++) {
const start = i * chunkSize;
const end = Math.min(start + chunkSize, files[0].size);
const chunk = files[0].slice(start, end);
const passwordSet = password !== "";
const encrypted_password = passwordSet ? await hashPassword(password) : null;

const formData = new FormData();
formData.append('file', chunk);
formData.append('bruteforceSafe', bruteforceSafe.toString());
formData.append('password', encrypted_password);
formData.append('endToEndEncryption', endToEndEncryption.toString());
formData.append('autoDeletion', target.autoDeletion.value);
formData.append('chunkIndex', i.toString());
formData.append('totalChunks', totalChunks.toString());
if (files.length > 0) {
const formData = new FormData();
formData.append('file', files[0]);
formData.append('bruteforceSafe', bruteforceSafe.toString());
formData.append('password', encrypted_password);
formData.append('endToEndEncryption', endToEndEncryption.toString());
formData.append('autoDeletion', target.autoDeletion.value);

const config: any = {
onUploadProgress: function (progressEvent: ProgressEvent) {
const chunkPercentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
const globalPercentCompleted = Math.round((start + progressEvent.loaded) * 100 / files[0].size);

if (chunkPercentCompleted === 100 && globalPercentCompleted >= 100) {
toast('Processing your file... This may take a while');
const config = {
onUploadProgress: function(progressEvent: ProgressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
if (percentCompleted === 100) {
toast('Processing your file... This may take a while');
}
setUploadPercentage(percentCompleted);
}
setUploadPercentage(globalPercentCompleted);
}
};

try {
const response = await axios.post(process.env.NEXT_PUBLIC_API_DOMAIN + '/file/upload/chunk', formData, config);
const data = await response.data;
};

if (response.status !== 200) {
toast.error(data.message);
break;
try {
// @ts-ignore Config is not assignable to type AxiosRequestConfig
const response = await axios.post(process.env.NEXT_PUBLIC_API_DOMAIN + '/file/upload', formData, config);

const data = await response.data;
if (response.status === 200) {
setUploadLink(data.link);
setUploadCreated(true);
} else {
toast.error(data.message);
}
} catch (err) {
toast.error('There was an error uploading your file');
}

setUploadLink(data.link);
setUploadCreated(true);

} catch (err) {
toast.error('There was an error uploading your file');
break;
}
}
setIsUploading(false);
};
setIsUploading(false);
};


return (
<>
Expand Down

0 comments on commit 8db5d7c

Please sign in to comment.