Add proper error handling for damaged images
authorAlexander Ebert <ebert@woltlab.com>
Tue, 3 Dec 2024 15:14:14 +0000 (16:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 3 Dec 2024 15:14:14 +0000 (16:14 +0100)
ts/WoltLabSuite/Core/Component/File/Upload.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js
wcfsetup/install/files/lib/system/event/listener/PreloadPhrasesCollectingListener.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index e43ccb5c4d8c052e9a6c69656c6068504d1a0732..476a94d6f92417451ce7173fe7c5478b163a0787 100644 (file)
@@ -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<CkeditorDropEvent>) => {
index 1dad3ed9be972b794c56caed558c4ab705980427..fc70bf44f20d9e0695a8fa3eb52e04bc6f00e3c8 100644 (file)
@@ -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) => {
index 6bced647c05f3a51a7a25f0c9c98d2d471185a4a..13c7e60ae605302733b0a0ba2ddec53f8dfc9ad3 100644 (file)
@@ -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');
index 96f20489744caf9192a546323ca9cae9563086b7..13e4b84f09398428fae71a015a67df4570ebd8f1 100644 (file)
@@ -5562,6 +5562,7 @@ Benachrichtigungen auf <a href="{link isHtmlEmail=true}{/link}">{PAGE_TITLE|phra
                <item name="wcf.upload.error.reachedRemainingLimit"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} zu viele Dateien ausgewählt. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} nur noch {#$maxFiles} weitere Datei{if $maxFiles != 1}en{/if} hochladen.]]></item>
                <item name="wcf.upload.error.uploadFailed"><![CDATA[Beim Hochladen der Datei ist ein unbekannter Fehler aufgetreten.]]></item>
                
+               <item name="wcf.upload.error.damagedImageFile"><![CDATA[Die Grafikdatei „{$filename}“ ist beschädigt.]]></item>
                <item name="wcf.upload.error.fileExtensionNotPermitted"><![CDATA[Der Dateityp von „{$filename}“ ist unzulässig.]]></item>
                <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[Die Datei ist zu groß.]]></item>
                <item name="wcf.upload.error.maximumCountReached"><![CDATA[Es {plural value=$maximumCount 1='darf nur eine Datei' other='dürfen nur # Dateien'} hochgeladen werden.]]></item>
index e9dad53624f0ea44d25960d0b0fe6660a4288877..770ce9fd83273162226248a63884963f345d63a7 100644 (file)
@@ -5564,6 +5564,7 @@ your notifications on <a href="{link isHtmlEmail=true}{/link}">{PAGE_TITLE|phras
                <item name="wcf.upload.error.reachedRemainingLimit"><![CDATA[You have selected too many files. You can only upload {#$maxFiles} more file{if $maxFiles != 1}s{/if}.]]></item>
                <item name="wcf.upload.error.uploadFailed"><![CDATA[An unknown error occurred during the upload.]]></item>
 
+               <item name="wcf.upload.error.damagedImageFile"><![CDATA[The graphics file “{$filename}” is damaged.]]></item>
                <item name="wcf.upload.error.fileExtensionNotPermitted"><![CDATA[The file type of “{$filename}” is not permitted.]]></item>
                <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[The file is too large.]]></item>
                <item name="wcf.upload.error.maximumCountReached"><![CDATA[{plural value=$maximumCount 1='Only one file' other='Only up to # files'} may be uploaded.]]></item>