diff --git a/src/components/common/FileDetailModal.vue b/src/components/common/FileDetailModal.vue index 8d1f5b9..878624a 100644 --- a/src/components/common/FileDetailModal.vue +++ b/src/components/common/FileDetailModal.vue @@ -1,110 +1,26 @@ - - diff --git a/src/composables/useSendFlow.ts b/src/composables/useSendFlow.ts index d3dad78..281021f 100644 --- a/src/composables/useSendFlow.ts +++ b/src/composables/useSendFlow.ts @@ -27,6 +27,8 @@ export function useSendFlow() { const expirationMethod = ref(config.value.expireStyle[0] || 'day') const expirationValue = ref('1') const uploadProgress = ref(0) + const uploadedBytes = ref(0) + const totalBytes = ref(0) const showDrawer = ref(false) const selectedRecord = ref(null) const isSubmitting = ref(false) @@ -62,7 +64,9 @@ export function useSendFlow() { notify: (message, type) => alertStore.showAlert(message, type), translate: t, onProgress: (progress) => { - uploadProgress.value = progress + uploadProgress.value = progress.percentage + uploadedBytes.value = progress.loaded + totalBytes.value = progress.total }, onFinalizing: () => { isFinalizing.value = true }, onHashCalculated: (hash) => { @@ -285,6 +289,8 @@ export function useSendFlow() { alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error') } finally { uploadProgress.value = 0 + uploadedBytes.value = 0 + totalBytes.value = 0 isSubmitting.value = false isFinalizing.value = false } @@ -319,6 +325,8 @@ export function useSendFlow() { expirationMethod, expirationValue, uploadProgress, + uploadedBytes, + totalBytes, showDrawer, selectedRecord, isSubmitting, diff --git a/src/composables/useSendSubmit.ts b/src/composables/useSendSubmit.ts index 442778b..59a59ba 100644 --- a/src/composables/useSendSubmit.ts +++ b/src/composables/useSendSubmit.ts @@ -12,7 +12,7 @@ type UseSendSubmitOptions = { getMaxFileSize: () => number notify: (message: string, type: AlertType) => void translate: Translate - onProgress: (progress: number) => void + onProgress: (progress: UploadProgress) => void onFinalizing: () => void onHashCalculated: (hash: string) => void } @@ -49,7 +49,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) { onHashCalculated: options.onHashCalculated, onFinalizing: options.onFinalizing, onProgress: (progress: UploadProgress) => { - options.onProgress(progress.percentage) + options.onProgress(progress) }, messages: { initFailed: options.translate('send.messages.initChunkUploadFailed'), @@ -68,7 +68,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) { expireValue, expireStyle: expireStyle as ExpireStyle, onProgress: (progress) => { - options.onProgress(progress.percentage) + options.onProgress(progress) } }) diff --git a/src/services/upload-strategy.ts b/src/services/upload-strategy.ts index 2345dfa..d19004e 100644 --- a/src/services/upload-strategy.ts +++ b/src/services/upload-strategy.ts @@ -3,7 +3,7 @@ import { waitForUploadCompletion, isTransientCompletionError } from './upload-co import type { ApiResponse, ChunkUploadInitResponse, FileUploadResponse, UploadProgress } from '@/types' import { calculateFileHash } from '@/utils/file-processing' -const CHUNK_SIZE = 5 * 1024 * 1024 +export const CHUNK_SIZE = 100 * 1024 * 1024 type ChunkedUploadOptions = { expireValue: number @@ -26,6 +26,7 @@ const pendingCompletion = new WeakMap> { const session = pendingCompletion.get(file)! + options.onProgress?.({loaded:file.size,total:file.size,percentage:99}) options.onFinalizing?.() try { const response = await waitForUploadCompletion(() => FileService.completeChunkUpload(session.uploadId, { @@ -55,7 +56,6 @@ export const uploadChunkedFile = async ( const fileHash = await calculateFileHash(file) options.onHashCalculated?.(fileHash) - const chunks = Math.ceil(file.size / CHUNK_SIZE) const initResponse = await FileService.initChunkUpload({ file_name: file.name, file_size: file.size, @@ -77,13 +77,16 @@ export const uploadChunkedFile = async ( throw new Error(options.messages?.initFailed || 'Init chunk upload failed') } + const chunkSize = initDetail.chunk_size || CHUNK_SIZE + const chunks = Math.ceil(file.size / chunkSize) const uploadedChunks = new Set(initDetail.uploaded_chunks || []) + options.onProgress?.({loaded:calculateCompletedBytes(uploadedChunks,chunkSize,file.size),total:file.size,percentage:0}) for (let index = 0; index < chunks; index++) { if (uploadedChunks.has(index)) { continue } - const start = index * CHUNK_SIZE + const start = index * chunkSize const end = Math.min(start + CHUNK_SIZE, file.size) const chunk = file.slice(start, end) const chunkResponse = await FileService.uploadChunk( @@ -91,7 +94,7 @@ export const uploadChunkedFile = async ( index, new Blob([chunk], { type: file.type }), (progress) => { - const completedBytes = calculateCompletedBytes(uploadedChunks, CHUNK_SIZE, file.size) + const completedBytes = calculateCompletedBytes(uploadedChunks, chunkSize, file.size) const percentage = Math.round(((completedBytes + progress.loaded) * 100) / file.size) options.onProgress?.({ loaded: completedBytes + progress.loaded, diff --git a/src/types/file.ts b/src/types/file.ts index ddc4fd5..2743f62 100644 --- a/src/types/file.ts +++ b/src/types/file.ts @@ -481,6 +481,8 @@ export interface ChunkUploadInitRequest { } export interface ChunkUploadInitResponse { + chunk_size?: number + total_chunks?: number code?: string name?: string upload_id?: string