better handling of image uploads

This commit is contained in:
Andrea Vos 2023-05-31 18:27:20 +02:00
parent 63b207466b
commit 90a9482f2a
6 changed files with 10 additions and 5 deletions

View File

@ -61,8 +61,8 @@
} }
}); });
this.$emit('uploaded', ids); this.$emit('uploaded', ids);
} catch { } catch (e) {
this.errorMessage = 'error.generic'; this.errorMessage = e?.response?.data?.error || 'error.invalidImage';
} }
this.uploading = false; this.uploading = false;
}, },

View File

@ -1052,6 +1052,7 @@ images:
error: error:
generic: 'Something went wrong, please try again…' 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: captcha:
reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.' reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.'

View File

@ -1209,6 +1209,7 @@ images:
error: error:
generic: 'Something went wrong, please try again…' 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: captcha:
reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.' reason: 'Please prove you''re not a bot to mitigate spam and DDoS attacks.'

View File

@ -123,5 +123,6 @@ module.exports = [
'mode.reducedItems', 'mode.reducedItems',
'user.socialLookup', 'user.socialLookup',
'user.socialLookupWhy', 'user.socialLookupWhy',
'api.source' 'api.source',
'error.invalidImage',
]; ];

View File

@ -1801,6 +1801,7 @@ images:
error: error:
generic: 'Coś poszło nie tak, spróbuj ponownie…' 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: captcha:
reason: 'Prosimy o udowodnienie, że nie jesteś botem, by chronić się przed spamem i DDoS-ami' reason: 'Prosimy o udowodnienie, że nie jesteś botem, by chronić się przed spamem i DDoS-ami'

View File

@ -59,10 +59,11 @@ router.post('/images/upload', multer({limits: {fileSize: 10 * 1024 * 1024}}).any
const ids = []; const ids = [];
for (let file of req.files) { for (let file of req.files) {
const id = ulid(); const id = ulid();
let image;
try { try {
const image = await loadImage(await sharp(file.buffer).png().toBuffer()); image = await loadImage(await sharp(file.buffer).png().toBuffer());
} catch { } catch {
return res.status(400).json({error: 'File type not supported'}); return res.status(400).json({error: 'error.invalidImage'});
} }
for (let s in sizes) { for (let s in sizes) {