Fix #843: Upload image on paste
This commit is contained in:
parent
480a06c426
commit
608112d56c
2 changed files with 26 additions and 0 deletions
24
app/pasteManager.js
Normal file
24
app/pasteManager.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* global MAXFILESIZE */
|
||||
import { bytes } from './utils';
|
||||
|
||||
export default function(state, emitter) {
|
||||
window.addEventListener('paste', event => {
|
||||
if (state.route !== '/' || state.uploading) return;
|
||||
|
||||
for (const item of event.clipboardData.items) {
|
||||
if (!item.type.includes('image')) continue;
|
||||
|
||||
const file = item.getAsFile();
|
||||
|
||||
if (!file) continue; // Sometimes null
|
||||
|
||||
if (file.size > MAXFILESIZE) {
|
||||
// eslint-disable-next-line no-alert
|
||||
alert(state.translate('fileTooBig', { size: bytes(MAXFILESIZE) }));
|
||||
continue;
|
||||
}
|
||||
|
||||
emitter.emit('upload', { file, type: 'paste' });
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue