From a5a2173dc2ba7277325beed937fc6fd82961e641 Mon Sep 17 00:00:00 2001 From: Luiz Filho Date: Sat, 30 Jan 2021 15:18:36 -0300 Subject: [PATCH] prevent send chunks when it is finished (#34) Co-authored-by: Luiz Filho --- src/upchunk.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/upchunk.ts b/src/upchunk.ts index b2be73b..08f7401 100644 --- a/src/upchunk.ts +++ b/src/upchunk.ts @@ -48,6 +48,7 @@ export class UpChunk { private attemptCount: number; private offline: boolean; private paused: boolean; + private success: boolean; private currentXhr?: XMLHttpRequest; private reader: FileReader; @@ -69,6 +70,7 @@ export class UpChunk { this.attemptCount = 0; this.offline = false; this.paused = false; + this.success = false; this.reader = new FileReader(); this.eventTarget = new EventTarget(); @@ -289,7 +291,7 @@ export class UpChunk { * handle errors & retries and dispatch events */ private sendChunks() { - if (this.paused || this.offline) { + if (this.paused || this.offline || this.success) { return; } @@ -311,6 +313,7 @@ export class UpChunk { if (this.chunkCount < this.totalChunks) { this.sendChunks(); } else { + this.success = true; this.dispatch('success'); }