|
@@ -35,29 +35,53 @@ export default class Tus10 extends Plugin {
|
|
|
})
|
|
|
|
|
|
|
|
|
- const upload = new tus.Upload(file, {
|
|
|
- endpoint: this.opts.endpoint,
|
|
|
- onError: error => {
|
|
|
- return Promise.reject('Failed because: ' + error)
|
|
|
- },
|
|
|
- onProgress: (bytesUploaded, bytesTotal) => {
|
|
|
- let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
|
|
|
- percentage = Math.round(percentage)
|
|
|
-
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const upload = new tus.Upload(file, {
|
|
|
+ endpoint: this.opts.endpoint,
|
|
|
+ onError: error => {
|
|
|
+ reject('Failed because: ' + error)
|
|
|
+ },
|
|
|
+ onProgress: (bytesUploaded, bytesTotal) => {
|
|
|
+ let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
|
|
|
+ percentage = Math.round(percentage)
|
|
|
|
|
|
-
|
|
|
- this.core.emitter.emit('progress', {
|
|
|
- plugin: this,
|
|
|
- percentage: percentage
|
|
|
- })
|
|
|
- },
|
|
|
- onSuccess: () => {
|
|
|
- this.core.log(`Download ${upload.file.name} from ${upload.url}`)
|
|
|
- return Promise.resolve(upload)
|
|
|
- }
|
|
|
+
|
|
|
+ this.core.emitter.emit('progress', {
|
|
|
+ plugin: this,
|
|
|
+ percentage: percentage
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onSuccess: () => {
|
|
|
+ this.core.log(`Download ${upload.file.name} from ${upload.url}`)
|
|
|
+ resolve(upload)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ upload.start()
|
|
|
})
|
|
|
-
|
|
|
- return upload.start()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|