2018-02-02 18:22:32 +00:00
|
|
|
/* global MAXFILESIZE */
|
2018-07-26 05:26:11 +00:00
|
|
|
import Archive from './archive';
|
|
|
|
import { bytes } from './utils';
|
2018-02-02 18:22:32 +00:00
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
export default function(state, emitter) {
|
|
|
|
emitter.on('DOMContentLoaded', () => {
|
|
|
|
document.body.addEventListener('dragover', event => {
|
|
|
|
if (state.route === '/') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
document.body.addEventListener('drop', event => {
|
2018-01-31 23:47:34 +00:00
|
|
|
if (state.route === '/' && !state.uploading) {
|
2017-08-24 21:54:02 +00:00
|
|
|
event.preventDefault();
|
2018-02-19 22:29:13 +00:00
|
|
|
document
|
|
|
|
.querySelector('.uploadArea')
|
|
|
|
.classList.remove('uploadArea--dragging');
|
2017-08-24 21:54:02 +00:00
|
|
|
const target = event.dataTransfer;
|
|
|
|
if (target.files.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-26 05:26:11 +00:00
|
|
|
const file = new Archive(target.files);
|
|
|
|
|
2018-02-02 18:22:32 +00:00
|
|
|
if (file.size === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (file.size > MAXFILESIZE) {
|
2018-03-02 05:36:45 +00:00
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
alert(state.translate('fileTooBig', { size: bytes(MAXFILESIZE) }));
|
2018-02-02 18:22:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
emitter.emit('upload', { file, type: 'drop' });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|