瀏覽代碼

@uppy/transloadit: fix multiple upload batches & run again (#5478)

* @uppy/transloadit: fix multiple upload batchs & run again

* Remove console.log
Merlijn Vos 7 月之前
父節點
當前提交
20291e19e8
共有 2 個文件被更改,包括 13 次插入7 次删除
  1. 5 0
      packages/@uppy/core/src/Uppy.ts
  2. 8 7
      packages/@uppy/transloadit/src/index.ts

+ 5 - 0
packages/@uppy/core/src/Uppy.ts

@@ -639,6 +639,11 @@ export class Uppy<
           ...files[fileID].progress,
           ...defaultProgress,
         },
+        // @ts-expect-error these typed are inserted
+        // into the namespace in their respective packages
+        // but core isn't ware of those
+        tus: undefined,
+        transloadit: undefined,
       }
     })
 

+ 8 - 7
packages/@uppy/transloadit/src/index.ts

@@ -696,12 +696,13 @@ export default class Transloadit<
       this.assembly = new Assembly(previousAssembly, this.#rateLimitedQueue)
       this.assembly.status = previousAssembly
       this.setPluginState({ files, results })
+      return files
     }
 
     // Set up the Assembly instances and AssemblyWatchers for existing Assemblies.
-    const restoreAssemblies = () => {
+    const restoreAssemblies = (ids: string[]) => {
       this.#createAssemblyWatcher(previousAssembly.assembly_id)
-      this.#connectAssembly(this.assembly!)
+      this.#connectAssembly(this.assembly!, ids)
     }
 
     // Force-update Assembly to check for missed events.
@@ -711,8 +712,8 @@ export default class Transloadit<
 
     // Restore all Assembly state.
     this.restored = (async () => {
-      restoreState()
-      restoreAssemblies()
+      const files = restoreState()
+      restoreAssemblies(Object.keys(files))
       await updateAssembly()
       this.restored = null
     })()
@@ -722,7 +723,7 @@ export default class Transloadit<
     })
   }
 
-  #connectAssembly(assembly: Assembly) {
+  #connectAssembly(assembly: Assembly, ids: UppyFile<M, B>['id'][]) {
     const { status } = assembly
     const id = status.assembly_id
     this.assembly = assembly
@@ -754,7 +755,7 @@ export default class Transloadit<
           // per-file progress as well. We cannot use this here or otherwise progress from
           // imported files would not be counted towards the total progress because imported
           // files are not registered with Uppy.
-          for (const file of this.uppy.getFiles()) {
+          for (const file of this.uppy.getFilesByIds(ids)) {
             this.uppy.emit('postprocess-progress', file, {
               mode: 'determinate',
               value: details.progress_combined / 100,
@@ -816,7 +817,7 @@ export default class Transloadit<
         this.uppy.emit('preprocess-complete', file)
       })
       this.#createAssemblyWatcher(assembly.status.assembly_id)
-      this.#connectAssembly(assembly)
+      this.#connectAssembly(assembly, fileIDs)
     } catch (err) {
       fileIDs.forEach((fileID) => {
         const file = this.uppy.getFile(fileID)