Compare commits

...

8 commits

Author SHA1 Message Date
Muhsin Keloth
3644c4bdc8
Merge branch 'develop' into feat/paste-image 2022-10-20 13:07:11 +05:30
David Kubeš
edf0b98624
Merge branch 'chatwoot:develop' into feat/paste-image 2022-10-18 23:05:07 +02:00
Muhsin Keloth
713876e283
Merge branch 'develop' into feat/paste-image 2022-10-18 13:13:58 +05:30
David Kubeš
989e05544f feat: Prevent pasting file name + fix comparing string and number 2022-10-17 15:36:30 +02:00
Muhsin Keloth
6f0eef5bd4
Merge branch 'develop' into feat/paste-image 2022-10-17 13:56:46 +05:30
Muhsin Keloth
9b561ad2a7
Merge branch 'develop' into feat/paste-image 2022-10-14 10:06:00 +05:30
David Kubeš
696444bf57
Merge branch 'chatwoot:develop' into feat/paste-image 2022-10-14 01:37:25 +02:00
David Kubeš
7132e9a2cd feat: Add ability to paste file/image from clipboard 2022-10-14 01:35:52 +02:00
3 changed files with 19 additions and 6 deletions

View file

@ -11,11 +11,7 @@ export const formatBytes = (bytes, decimals = 2) => {
};
export const fileSizeInMegaBytes = bytes => {
if (bytes === 0) {
return 0;
}
const sizeInMB = (bytes / (1024 * 1024)).toFixed(2);
return sizeInMB;
return bytes / (1024 * 1024);
};
export const checkFileSizeLimit = (file, maximumUploadLimit) => {

View file

@ -24,7 +24,7 @@ describe('#File Helpers', () => {
expect(fileSizeInMegaBytes(0)).toBe(0);
});
it('should return 19.07 if 20000000 is passed', () => {
expect(fileSizeInMegaBytes(20000000)).toBe('19.07');
expect(fileSizeInMegaBytes(20000000)).toBeCloseTo(19.07, 2);
});
});
describe('checkFileSizeLimit', () => {

View file

@ -1,5 +1,6 @@
<template>
<file-upload
ref="upload"
:size="4096 * 2048"
:accept="allowedFileTypes"
:data="{
@ -48,7 +49,23 @@ export default {
return ALLOWED_FILE_TYPES;
},
},
mounted() {
document.addEventListener('paste', this.handleClipboardPaste);
},
destroyed() {
document.removeEventListener('paste', this.handleClipboardPaste);
},
methods: {
handleClipboardPaste(e) {
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
items.forEach(item => {
if (item.kind === 'file') {
e.preventDefault();
const file = item.getAsFile();
this.$refs.upload.add(file);
}
});
},
getFileType(fileType) {
return fileType.includes('image') ? 'image' : 'file';
},