Просмотр исходного кода

transloadit: Fix crash when no files are being uploaded

Renée Kooi 7 лет назад
Родитель
Сommit
ffb36428f3
2 измененных файлов с 20 добавлено и 0 удалено
  1. 4 0
      src/plugins/Transloadit/index.js
  2. 16 0
      test/unit/Transloadit.spec.js

+ 4 - 0
src/plugins/Transloadit/index.js

@@ -282,6 +282,10 @@ module.exports = class Transloadit extends Plugin {
     // A file ID that is part of this assembly...
     const fileID = fileIDs[0]
 
+    if (!fileID) {
+      return Promise.resolve()
+    }
+
     // If we don't have to wait for encoding metadata or results, we can close
     // the socket immediately and finish the upload.
     if (!this.shouldWait()) {

+ 16 - 0
test/unit/Transloadit.spec.js

@@ -149,3 +149,19 @@ test('Transloadit: Should merge files with same parameters into one assembly', (
     })
   }, t.fail)
 })
+
+test('Does not create an assembly if no files are being uploaded', (t) => {
+  t.plan(0)
+
+  const uppy = new Core()
+  uppy.use(Transloadit, {
+    getAssemblyOptions () {
+      t.fail('should not create assembly')
+    }
+  })
+  uppy.run()
+
+  uppy.upload().then(() => {
+    t.end()
+  }).catch(t.fail)
+})