From b41db78745de0796e747a8ee34e6c0fe8c5b44d1 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 26 Oct 2024 14:46:12 +0200 Subject: [PATCH] [#181] Add paste ability for files to textarea closes #181 Signed-off-by: Knut Ahlers --- src/components/create.vue | 56 ++++++++++++++++--- src/components/fileDisplay.vue | 90 +++++++++++++++++++++++++++++++ src/components/growarea.vue | 25 +++++++++ src/components/secret-display.vue | 55 ++++--------------- src/style.scss | 4 ++ 5 files changed, 178 insertions(+), 52 deletions(-) create mode 100644 src/components/fileDisplay.vue diff --git a/src/components/create.vue b/src/components/create.vue index 335e0a7..e54f7b0 100644 --- a/src/components/create.vue +++ b/src/components/create.vue @@ -36,6 +36,7 @@ v-model="secret" class="form-control" :rows="2" + @pasteFile="handlePasteFile" />
{{ $t('text-max-filesize', { maxSize: bytesToHuman(maxFileSize) }) }} @@ -67,6 +68,14 @@ > {{ $t('text-max-filesize-exceeded', { curSize: bytesToHuman(fileSize), maxSize: bytesToHuman(maxFileSize) }) }}
+

@@ -88,17 +67,16 @@ import appClipboardButton from './clipboard-button.vue' import appCrypto from '../crypto.js' import appQrButton from './qr-button.vue' -import { bytesToHuman } from '../helpers' +import FilesDisplay from './fileDisplay.vue' import GrowArea from './growarea.vue' import OTSMeta from '../ots-meta' export default { - components: { GrowArea, appClipboardButton, appQrButton }, + components: { FilesDisplay, GrowArea, appClipboardButton, appQrButton }, data() { return { files: [], - hasDownloaded: {}, popover: null, secret: null, secretContentBlobURL: null, @@ -107,25 +85,6 @@ export default { }, methods: { - bytesToHuman, - - fasFileType(type) { - return [ - 'fas', - 'fa-fw', - 'me-2', - ...[ - { icon: ['fa-file-pdf'], match: /application\/pdf/ }, - { icon: ['fa-file-audio'], match: /^audio\// }, - { icon: ['fa-file-image'], match: /^image\// }, - { icon: ['fa-file-lines'], match: /^text\// }, - { icon: ['fa-file-video'], match: /^video\// }, - { icon: ['fa-file-zipper'], match: /^application\/(gzip|x-tar|zip)$/ }, - { icon: ['fa-file-circle-question'], match: /.*/ }, - ].filter(el => el.match.test(type))[0].icon, - ].join(' ') - }, - // requestSecret requests the encrypted secret from the backend requestSecret() { this.secretLoading = true @@ -161,7 +120,13 @@ export default { file.arrayBuffer() .then(ab => { const blobURL = window.URL.createObjectURL(new Blob([ab], { type: file.type })) - this.files.push({ name: file.name, size: ab.byteLength, type: file.type, url: blobURL }) + this.files.push({ + id: window.crypto.randomUUID(), + name: file.name, + size: ab.byteLength, + type: file.type, + url: blobURL, + }) }) }) this.secretLoading = false diff --git a/src/style.scss b/src/style.scss index 794e1f5..11a4be3 100644 --- a/src/style.scss +++ b/src/style.scss @@ -8,4 +8,8 @@ $web-font-path: ''; textarea { font-family: monospace !important; } + + .cursor-pointer { + cursor: pointer; + } } \ No newline at end of file