fix(theming): display error messages on image upload and delete previous image only after validation

Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
Cristian Scheid 2026-02-02 14:16:18 -03:00
parent 4d6959da27
commit 0a5f75e719
2 changed files with 11 additions and 2 deletions

View file

@ -221,8 +221,6 @@ class ImageManager {
}
public function updateImage(string $key, string $tmpFile): string {
$this->delete($key);
try {
$folder = $this->getRootFolder()->getFolder('images');
} catch (NotFoundException $e) {
@ -236,6 +234,8 @@ class ImageManager {
throw new \Exception('Unsupported image type: ' . $detectedMimeType);
}
$this->delete($key);
if ($key === 'background') {
if ($this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) {
try {

View file

@ -76,8 +76,17 @@ async function onChange() {
})
mime.value = file.type
emit('updated')
} catch (error: any) {
if (error?.response?.status === 422) {
const serverMessage = error.response.data?.data?.message
showError(serverMessage || t('theming', 'Failed to upload image'))
} else {
showError(t('theming', 'Failed to upload image'))
}
} finally {
isSaving.value = false
// Reset input to allow re-selecting the same file and show validation errors on every attempt
inputElement.value!.value = ''
}
}