From 4957ef5552bb8e4896def2a1fb696c85078bc79a Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Wed, 17 Jan 2018 11:02:12 +0100 Subject: [PATCH] restart timeout --- res/static/res/script/compiled/home.js | 24 ++++++++++----------- res/static/res/typescript/lib/uploader.ts | 26 +++++++++++------------ 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/res/static/res/script/compiled/home.js b/res/static/res/script/compiled/home.js index 446b15e..7cf8f52 100644 --- a/res/static/res/script/compiled/home.js +++ b/res/static/res/script/compiled/home.js @@ -116,7 +116,7 @@ var UploadManager = /** @class */ (function () { } else { for (var i = 0; i < this.uploadThreads.length; i++) { - this.uploadThreads[i].startIfInactive(); + setTimeout(this.uploadThreads[i].start(), 0); } } }; @@ -137,6 +137,11 @@ var UploadWorker = /** @class */ (function () { this.manager = manager; } UploadWorker.prototype.start = function () { + if (!this.uploading) { + this.newFile(); + } + }; + UploadWorker.prototype.newFile = function () { var file = this.manager.grabFile(); if (file === undefined) { this.uploading = false; @@ -147,11 +152,6 @@ var UploadWorker = /** @class */ (function () { this.tries = 0; this.upload(file); }; - UploadWorker.prototype.startIfInactive = function () { - if (!this.uploading) { - this.start(); - } - }; UploadWorker.prototype.upload = function (file) { console.debug("Starting upload of " + file.file.name); var formData = new FormData(); @@ -177,23 +177,21 @@ var UploadWorker = /** @class */ (function () { }, success: function (data) { file.onFinished(data.id); - console.log("Done: " + data.id); that.setHistoryCookie(data.id); - that.start(); // Continue uploading on this thread + console.log("Done: " + data.id); + that.newFile(); // Continue uploading on this thread }, error: function (xhr, status, error) { - console.log(status); - console.log(error); + console.log("status: " + status + " error: " + error); if (that.tries === 3) { alert("Upload failed: " + status); - that.uploading = false; file.onFailure(status, error); - that.start(); // Try to continue + setTimeout(that.newFile(), 2000); // Try to continue return; // Upload failed } // Try again that.tries++; - that.upload(file); + setTimeout(that.upload(file), that.tries * 3000); } }); }; diff --git a/res/static/res/typescript/lib/uploader.ts b/res/static/res/typescript/lib/uploader.ts index 94d36cd..fdb9ba4 100644 --- a/res/static/res/typescript/lib/uploader.ts +++ b/res/static/res/typescript/lib/uploader.ts @@ -21,7 +21,7 @@ class UploadManager { setTimeout(thread.start(), 0) // Start a new upload thread } else { for (var i = 0; i < this.uploadThreads.length; i++) { - this.uploadThreads[i].startIfInactive() + setTimeout(this.uploadThreads[i].start(), 0) } } } @@ -42,8 +42,13 @@ class UploadWorker { constructor(manager: UploadManager) { this.manager = manager } + public start(){ + if (!this.uploading) { + this.newFile() + } + } - public start() { + private newFile() { var file = this.manager.grabFile() if (file === undefined) { this.uploading = false @@ -55,11 +60,6 @@ class UploadWorker { this.tries = 0 this.upload(file) } - public startIfInactive(){ - if (!this.uploading) { - this.start() - } - } private upload(file: FileUpload){ console.debug("Starting upload of " + file.file.name) @@ -89,27 +89,25 @@ class UploadWorker { }, success: function (data) { file.onFinished(data.id) - console.log("Done: " + data.id) that.setHistoryCookie(data.id) + console.log("Done: " + data.id) - that.start() // Continue uploading on this thread + that.newFile() // Continue uploading on this thread }, error: function (xhr, status, error){ - console.log(status) - console.log(error) + console.log("status: "+status+" error: "+error) if (that.tries === 3) { alert("Upload failed: " + status); - that.uploading = false file.onFailure(status, error) - that.start() // Try to continue + setTimeout(that.newFile(), 2000) // Try to continue return; // Upload failed } // Try again that.tries++ - that.upload(file) + setTimeout(that.upload(file), that.tries*3000) } }); }