feat: Prevent pasting file name + fix comparing string and number

This commit is contained in:
David Kubeš 2022-10-17 15:36:30 +02:00
parent 6f0eef5bd4
commit 989e05544f
3 changed files with 3 additions and 6 deletions

View file

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

View file

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

View file

@ -60,6 +60,7 @@ export default {
const items = (e.clipboardData || e.originalEvent.clipboardData).items; const items = (e.clipboardData || e.originalEvent.clipboardData).items;
items.forEach(item => { items.forEach(item => {
if (item.kind === 'file') { if (item.kind === 'file') {
e.preventDefault();
const file = item.getAsFile(); const file = item.getAsFile();
this.$refs.upload.add(file); this.$refs.upload.add(file);
} }