@zjlab-fe/data-hub-ui 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,7 +60,7 @@ import { useUploadEngine } from '../context/use-upload-engine.js';
60
60
  */
61
61
  function useUpload() {
62
62
  const { state, dispatch, config } = useUploadContext();
63
- const { startUpload, pauseUpload, resumeUpload, cancelUpload } = useUploadEngine();
63
+ const { startUpload, pauseUpload, resumeUpload, cancelUpload, retryUpload } = useUploadEngine();
64
64
  // ─────────────────────────────────────────────────────────────────────────────
65
65
  // FILE OPERATIONS
66
66
  // ─────────────────────────────────────────────────────────────────────────────
@@ -172,6 +172,18 @@ function useUpload() {
172
172
  * @param id - File ID to cancel
173
173
  */
174
174
  const cancel = useCallback((id) => cancelUpload(id), [cancelUpload]);
175
+ /**
176
+ * Retry a failed upload (smart retry with full retry fallback).
177
+ *
178
+ * @param id - File ID to retry
179
+ */
180
+ const retry = useCallback((id) => __awaiter(this, void 0, void 0, function* () {
181
+ const file = state.files.find((f) => f.id === id);
182
+ if (file && file.status === UploadStatus.FAILED) {
183
+ return retryUpload(id);
184
+ }
185
+ return { success: false, retryType: 'smart' };
186
+ }), [state.files, retryUpload]);
175
187
  // ─────────────────────────────────────────────────────────────────────────────
176
188
  // MUTEX FLAGS - Prevent concurrent batch operations
177
189
  // ─────────────────────────────────────────────────────────────────────────────
@@ -280,6 +292,7 @@ function useUpload() {
280
292
  pause,
281
293
  resume,
282
294
  cancel,
295
+ retry,
283
296
  getFileById,
284
297
  });
285
298
  });
@@ -297,6 +310,7 @@ function useUpload() {
297
310
  pause,
298
311
  resume,
299
312
  cancel,
313
+ retry,
300
314
  /** Get a specific file by ID */
301
315
  getFileById,
302
316
  /** Files waiting to be uploaded */
@@ -39,5 +39,47 @@ function resetInterruptedChunks(chunks) {
39
39
  return chunk;
40
40
  });
41
41
  }
42
+ /**
43
+ * Get chunks that failed and need to be retried.
44
+ * Returns only FAILED chunks, preserves COMPLETED chunks.
45
+ */
46
+ function getFailedChunks(file) {
47
+ const failedPartNums = [];
48
+ let completedCount = 0;
49
+ for (const chunk of file.chunks) {
50
+ if (chunk.status === ChunkStatus.COMPLETED) {
51
+ completedCount++;
52
+ }
53
+ else if (chunk.status === ChunkStatus.FAILED && chunk.partNum !== undefined) {
54
+ failedPartNums.push(chunk.partNum);
55
+ }
56
+ }
57
+ return {
58
+ failedPartNums,
59
+ failedCount: failedPartNums.length,
60
+ completedCount,
61
+ hasFailed: failedPartNums.length > 0,
62
+ };
63
+ }
64
+ /**
65
+ * Reset only failed chunks to pending state.
66
+ * Preserves completed chunks for efficient retry.
67
+ * Returns updated chunks array.
68
+ */
69
+ function resetFailedChunks(chunks) {
70
+ return chunks.map((chunk) => {
71
+ if (chunk.status === ChunkStatus.FAILED) {
72
+ return Object.assign(Object.assign({}, chunk), { status: ChunkStatus.PENDING, progress: 0, error: undefined });
73
+ }
74
+ return chunk;
75
+ });
76
+ }
77
+ /**
78
+ * Reset all chunks to pending state (for full retry).
79
+ * Used when smart retry fails or server state is lost.
80
+ */
81
+ function resetAllChunks(chunks) {
82
+ return chunks.map((chunk) => (Object.assign(Object.assign({}, chunk), { status: ChunkStatus.PENDING, progress: 0, error: undefined })));
83
+ }
42
84
 
43
- export { getChunksForResume, resetInterruptedChunks };
85
+ export { getChunksForResume, getFailedChunks, resetAllChunks, resetFailedChunks, resetInterruptedChunks };
package/es/index.js CHANGED
@@ -9,6 +9,7 @@ export { Uploader as FileUploader } from './components/file-uploader/components/
9
9
  export { UploaderDropZone } from './components/file-uploader/components/uploader-drop-zone.js';
10
10
  export { UploaderFileListLayout } from './components/file-uploader/components/uploader-file-list.js';
11
11
  export { UploaderFileItem } from './components/file-uploader/components/uploader-file-item.js';
12
+ export { UploaderProgressBar } from './components/file-uploader/components/uploader-progress-bar.js';
12
13
  export { useUpload } from './components/file-uploader/hooks/use-upload.js';
13
14
  export { UploadStatus } from './components/file-uploader/constants.js';
14
15
  export { default as FilePreview } from './components/file-preview/index.js';