]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/commitdiff
Superagent is a bit bogus
authorJohannes Zellner <johannes@cloudron.io>
Mon, 8 Oct 2018 14:03:12 +0000 (16:03 +0200)
committerJohannes Zellner <johannes@cloudron.io>
Mon, 8 Oct 2018 14:03:12 +0000 (16:03 +0200)
frontend/js/app.js

index 26791878faa55370ca31b1902019129069ea9040..c1a63a9df6398760e3b1799569bcc033d54cbceb 100644 (file)
@@ -146,11 +146,16 @@ function uploadFiles(files) {
         var formData = new FormData();
         formData.append('file', file);
 
+        var finishedUploadSize = app.uploadStatus.done;
+
         superagent.post('/api/files' + path)
           .query({ access_token: localStorage.accessToken })
           .send(formData)
           .on('progress', function (event) {
-            app.uploadStatus.done += event.loaded;
+            // only handle upload events
+            if (!(event.target instanceof XMLHttpRequestUpload)) return;
+
+            app.uploadStatus.done = finishedUploadSize + event.loaded;
             app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.size * 100);
         }).end(function (error, result) {
             if (result && result.statusCode === 401) return logout();