Skip to content

Commit

Permalink
better way to deal with resumable.js files
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Sep 13, 2024
1 parent 9704580 commit b509523
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/helpers/hooks/useResumableFilesUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Resumable from 'resumablejs';
import ResumableFile = Resumable.ResumableFile;

import { store } from '../../store';
import sendAPIRequest from '../api/plugNmeetAPI';

export interface IUseResumableFilesUpload {
allowedFileTypes: Array<string>;
Expand Down Expand Up @@ -52,7 +53,6 @@ const useResumableFilesUpload = ({
Authorization: session.token,
},
fileType: allowedFileTypes,
simultaneousUploads: 1,
fileTypeErrorCallback(file) {
toast(t('notifications.file-type-not-allow', { filetype: file.type }), {
type: 'error',
Expand All @@ -76,10 +76,19 @@ const useResumableFilesUpload = ({
}
});

r.on('fileSuccess', function (file: ResumableFile, message: string) {
const res = JSON.parse(message);
setIsUploading(false);
r.on('fileSuccess', async (file: ResumableFile) => {
// file was uploaded successfully
// now we'll send merge request
const mergeReq = {
roomSid: session.currentRoom.sid,
roomId: session.currentRoom.roomId,
resumableIdentifier: file.uniqueIdentifier,
resumableFilename: file.fileName,
ResumableTotalChunks: file.chunks.length,
};
const res = await sendAPIRequest('/uploadedFileMerge', mergeReq, true);

setIsUploading(false);
setTimeout(() => {
toast.dismiss(toastId.current ?? '');
}, 300);
Expand All @@ -90,6 +99,10 @@ const useResumableFilesUpload = ({
fileName: res.fileName,
fileExtension: res.fileExtension,
});
} else {
toast(t(res.msg), {
type: 'error',
});
}
});

Expand Down

0 comments on commit b509523

Please sign in to comment.