diff --git a/components/ImageUploader.vue b/components/ImageUploader.vue index c62f66ba8..337edfcfd 100644 --- a/components/ImageUploader.vue +++ b/components/ImageUploader.vue @@ -61,8 +61,8 @@ } }); this.$emit('uploaded', ids); - } catch { - this.errorMessage = 'error.generic'; + } catch (e) { + this.errorMessage = e?.response?.data?.error || 'error.invalidImage'; } this.uploading = false; }, diff --git a/locale/_base/translations.suml b/locale/_base/translations.suml index 24caa5f86..6a7eafed7 100644 --- a/locale/_base/translations.suml +++ b/locale/_base/translations.suml @@ -1052,6 +1052,7 @@ images: error: generic: 'Something went wrong, please try again…' + invalidImage: 'This file does''t seem right. Make sure it''s a valid image under 10 MB.' captcha: reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.' diff --git a/locale/en/translations.suml b/locale/en/translations.suml index 4980cebc4..6871ac282 100644 --- a/locale/en/translations.suml +++ b/locale/en/translations.suml @@ -1209,6 +1209,7 @@ images: error: generic: 'Something went wrong, please try again…' + invalidImage: 'This file does''t seem right. Make sure it''s a valid image under 10 MB.' captcha: reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.' diff --git a/locale/expectedTranslations.js b/locale/expectedTranslations.js index 204ae359d..94133bb83 100644 --- a/locale/expectedTranslations.js +++ b/locale/expectedTranslations.js @@ -123,5 +123,6 @@ module.exports = [ 'mode.reducedItems', 'user.socialLookup', 'user.socialLookupWhy', - 'api.source' + 'api.source', + 'error.invalidImage', ]; diff --git a/locale/pl/translations.suml b/locale/pl/translations.suml index eb7853893..e2651d430 100644 --- a/locale/pl/translations.suml +++ b/locale/pl/translations.suml @@ -1801,6 +1801,7 @@ images: error: generic: 'Coś poszło nie tak, spróbuj ponownie…' + invalidImage: 'Nieobsługiwany format pliku. Upewnij się, że wgrywasz poprawny obrazek nie cięższy niż 10 MB.' captcha: reason: 'Prosimy o udowodnienie, że nie jesteś botem, by chronić się przed spamem i DDoS-ami' diff --git a/server/routes/images.js b/server/routes/images.js index 138baec30..8a4f95f33 100644 --- a/server/routes/images.js +++ b/server/routes/images.js @@ -59,10 +59,11 @@ router.post('/images/upload', multer({limits: {fileSize: 10 * 1024 * 1024}}).any const ids = []; for (let file of req.files) { const id = ulid(); + let image; try { - const image = await loadImage(await sharp(file.buffer).png().toBuffer()); + image = await loadImage(await sharp(file.buffer).png().toBuffer()); } catch { - return res.status(400).json({error: 'File type not supported'}); + return res.status(400).json({error: 'error.invalidImage'}); } for (let s in sizes) {