Преглед изворни кода

Merge pull request #443 from transloadit/fix/restore-paused

tus: Restore correctly from paused state
Artur Paikin пре 7 година
родитељ
комит
932c3116f9
1 измењених фајлова са 15 додато и 3 уклоњено
  1. 15 3
      src/plugins/Tus.js

+ 15 - 3
src/plugins/Tus.js

@@ -171,7 +171,11 @@ module.exports = class Tus extends Plugin {
       })
       })
 
 
       this.onPause(file.id, (isPaused) => {
       this.onPause(file.id, (isPaused) => {
-        isPaused ? upload.abort() : upload.start()
+        if (isPaused) {
+          upload.abort()
+        } else {
+          upload.start()
+        }
       })
       })
 
 
       this.onPauseAll(file.id, () => {
       this.onPauseAll(file.id, () => {
@@ -189,8 +193,12 @@ module.exports = class Tus extends Plugin {
         upload.start()
         upload.start()
       })
       })
 
 
-      upload.start()
-      this.core.emit('core:upload-started', file.id, upload)
+      if (!file.isPaused) {
+        upload.start()
+      }
+      if (!file.isRestored) {
+        this.core.emit('core:upload-started', file.id, upload)
+      }
     })
     })
   }
   }
 
 
@@ -275,6 +283,10 @@ module.exports = class Tus extends Plugin {
       socket.send('resume', {})
       socket.send('resume', {})
     })
     })
 
 
+    if (file.isPaused) {
+      socket.send('pause', {})
+    }
+
     socket.on('progress', (progressData) => emitSocketProgress(this, progressData, file))
     socket.on('progress', (progressData) => emitSocketProgress(this, progressData, file))
 
 
     socket.on('success', (data) => {
     socket.on('success', (data) => {