Merge pull request #846 from pd4d10/patch-1
Fix #843: Upload image on paste
This commit is contained in:
commit
fb3747785b
@ -4,6 +4,7 @@ import app from './routes';
|
|||||||
import locale from '../common/locales';
|
import locale from '../common/locales';
|
||||||
import fileManager from './fileManager';
|
import fileManager from './fileManager';
|
||||||
import dragManager from './dragManager';
|
import dragManager from './dragManager';
|
||||||
|
import pasteManager from './pasteManager';
|
||||||
import { canHasSend } from './utils';
|
import { canHasSend } from './utils';
|
||||||
import storage from './storage';
|
import storage from './storage';
|
||||||
import metrics from './metrics';
|
import metrics from './metrics';
|
||||||
@ -48,5 +49,6 @@ app.use(metrics);
|
|||||||
app.use(fileManager);
|
app.use(fileManager);
|
||||||
app.use(dragManager);
|
app.use(dragManager);
|
||||||
app.use(experiments);
|
app.use(experiments);
|
||||||
|
app.use(pasteManager);
|
||||||
|
|
||||||
app.mount('body');
|
app.mount('body');
|
||||||
|
25
app/pasteManager.js
Normal file
25
app/pasteManager.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* 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' });
|
||||||
|
return; // return here since only one file is allowed to be uploaded at a time
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user