added fileTooBig alert to drop handler. fixes #578

This commit is contained in:
Danny Coates 2018-02-02 10:22:32 -08:00
parent 1366f0b68e
commit 3de760db12
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 13 additions and 1 deletions

View File

@ -1,3 +1,6 @@
/* global MAXFILESIZE */
const { bytes } = require('./utils');
export default function(state, emitter) { export default function(state, emitter) {
emitter.on('DOMContentLoaded', () => { emitter.on('DOMContentLoaded', () => {
document.body.addEventListener('dragover', event => { document.body.addEventListener('dragover', event => {
@ -13,10 +16,19 @@ export default function(state, emitter) {
if (target.files.length === 0) { if (target.files.length === 0) {
return; return;
} }
if (target.files.length > 1 || target.files[0].size === 0) { if (target.files.length > 1) {
return alert(state.translate('uploadPageMultipleFilesAlert')); return alert(state.translate('uploadPageMultipleFilesAlert'));
} }
const file = target.files[0]; const file = target.files[0];
if (file.size === 0) {
return;
}
if (file.size > MAXFILESIZE) {
window.alert(
state.translate('fileTooBig', { size: bytes(MAXFILESIZE) })
);
return;
}
emitter.emit('upload', { file, type: 'drop' }); emitter.emit('upload', { file, type: 'drop' });
} }
}); });