fix: process stops if image preview or thumbnail creation fails
This commit is contained in:
parent
a0ba46caf4
commit
671dfa1c87
2 changed files with 8 additions and 5 deletions
|
@ -204,7 +204,7 @@ class Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
getResizedImageDataUrl(file, width = undefined, height = undefined, quality = 0.7) {
|
getResizedImageDataUrl(file, width = undefined, height = undefined, quality = 0.7) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
let image = new Image();
|
let image = new Image();
|
||||||
image.src = URL.createObjectURL(file);
|
image.src = URL.createObjectURL(file);
|
||||||
image.onload = _ => {
|
image.onload = _ => {
|
||||||
|
@ -233,9 +233,10 @@ class Peer {
|
||||||
let dataUrl = canvas.toDataURL("image/jpeg", quality);
|
let dataUrl = canvas.toDataURL("image/jpeg", quality);
|
||||||
resolve(dataUrl);
|
resolve(dataUrl);
|
||||||
}
|
}
|
||||||
|
image.onerror = _ => reject(`Could not create an image thumbnail from type ${file.type}`);
|
||||||
}).then(dataUrl => {
|
}).then(dataUrl => {
|
||||||
return dataUrl;
|
return dataUrl;
|
||||||
})
|
}).catch(e => console.error(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
async requestFileTransfer(files) {
|
async requestFileTransfer(files) {
|
||||||
|
|
|
@ -516,10 +516,12 @@ class ReceiveFileDialog extends ReceiveDialog {
|
||||||
element.src = URL.createObjectURL(file);
|
element.src = URL.createObjectURL(file);
|
||||||
element.controls = true;
|
element.controls = true;
|
||||||
element.classList.add('element-preview');
|
element.classList.add('element-preview');
|
||||||
this.$previewBox.appendChild(element)
|
element.onload = _ => {
|
||||||
element.onload = _ => resolve(true);
|
this.$previewBox.appendChild(element);
|
||||||
|
resolve(true)
|
||||||
|
};
|
||||||
element.addEventListener('loadeddata', _ => 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}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue