From 671dfa1c870a62aee6982c604a926ed06e6a037e Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 8 Feb 2023 14:10:34 +0100 Subject: [PATCH] fix: process stops if image preview or thumbnail creation fails --- public/scripts/network.js | 5 +++-- public/scripts/ui.js | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/public/scripts/network.js b/public/scripts/network.js index baaaced..85830d0 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -204,7 +204,7 @@ class Peer { } getResizedImageDataUrl(file, width = undefined, height = undefined, quality = 0.7) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { let image = new Image(); image.src = URL.createObjectURL(file); image.onload = _ => { @@ -233,9 +233,10 @@ class Peer { let dataUrl = canvas.toDataURL("image/jpeg", quality); resolve(dataUrl); } + image.onerror = _ => reject(`Could not create an image thumbnail from type ${file.type}`); }).then(dataUrl => { return dataUrl; - }) + }).catch(e => console.error(e)); } async requestFileTransfer(files) { diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 4f73e5d..af5d3ae 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -516,10 +516,12 @@ class ReceiveFileDialog extends ReceiveDialog { element.src = URL.createObjectURL(file); element.controls = true; element.classList.add('element-preview'); - this.$previewBox.appendChild(element) - element.onload = _ => resolve(true); + element.onload = _ => { + this.$previewBox.appendChild(element); + resolve(true) + }; element.addEventListener('loadeddata', _ => resolve(true)); - element.onerror = _ => reject(`${mime} preview could not be loaded`); + element.onerror = _ => reject(`${mime} preview could not be loaded from type ${file.type}`); } }); }