From: Johannes Zellner Date: Mon, 8 Oct 2018 14:03:12 +0000 (+0200) Subject: Superagent is a bit bogus X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=3760489ffc7596a13909907c60d1410d8161b89e;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git Superagent is a bit bogus --- diff --git a/frontend/js/app.js b/frontend/js/app.js index 2679187..c1a63a9 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -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();