From 22306e1576cc80943b8d913aed0287d82d912499 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 3 Dec 2024 16:14:14 +0100 Subject: [PATCH] Add proper error handling for damaged images --- ts/WoltLabSuite/Core/Component/File/Upload.ts | 10 +++++++--- .../js/WoltLabSuite/Core/Component/File/Upload.js | 6 +++++- .../PreloadPhrasesCollectingListener.class.php | 1 + wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/File/Upload.ts b/ts/WoltLabSuite/Core/Component/File/Upload.ts index e43ccb5c4d..476a94d6f9 100644 --- a/ts/WoltLabSuite/Core/Component/File/Upload.ts +++ b/ts/WoltLabSuite/Core/Component/File/Upload.ts @@ -268,9 +268,13 @@ export function setup(): void { return; } - void resizeImage(element, file).then((resizedFile) => { - void upload(element, resizedFile); - }); + void resizeImage(element, file) + .then((resizedFile) => { + void upload(element, resizedFile); + }) + .catch(() => { + innerError(element, getPhrase("wcf.upload.error.damagedImageFile", { filename: file.name })); + }); }); element.addEventListener("ckeditorDrop", (event: CustomEvent) => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js index 1dad3ed9be..fc70bf44f2 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js @@ -183,8 +183,12 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "Wol else if (!validateFileSize(element, file)) { return; } - void resizeImage(element, file).then((resizedFile) => { + void resizeImage(element, file) + .then((resizedFile) => { void upload(element, resizedFile); + }) + .catch(() => { + (0, Util_1.innerError)(element, (0, Language_1.getPhrase)("wcf.upload.error.damagedImageFile", { filename: file.name })); }); }); element.addEventListener("ckeditorDrop", (event) => { diff --git a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php index 6bced647c0..13c7e60ae6 100644 --- a/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php @@ -150,6 +150,7 @@ final class PreloadPhrasesCollectingListener $event->preload('wcf.style.changeStyle'); + $event->preload('wcf.upload.error.damagedImageFile'); $event->preload('wcf.upload.error.fileExtensionNotPermitted'); $event->preload('wcf.upload.error.fileSizeTooLarge'); $event->preload('wcf.upload.error.maximumCountReached'); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 96f2048974..13e4b84f09 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -5562,6 +5562,7 @@ Benachrichtigungen auf {PAGE_TITLE|phra + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index e9dad53624..770ce9fd83 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -5564,6 +5564,7 @@ your notifications on {PAGE_TITLE|phras + -- 2.20.1