Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Implement single file upload on "paste" action #9140

Merged
merged 8 commits into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-upload-file-on-paste
@@ -0,0 +1,6 @@
Enhancement: Upload file on paste

We've implemented the possibility to upload a single file in the clipboard from anywhere via paste.

https://github.com/owncloud/web/pull/9140
https://github.com/owncloud/web/issues/9047
18 changes: 18 additions & 0 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Expand Up @@ -240,15 +240,33 @@ export default defineComponent({
return unref(currentFolder)?.canUpload({ user: store.getters.user })
})

const handlePasteFileEvent = (event) => {
// Ignore file in clipboard if there are already files from owncloud in the clipboard
if (store.state.Files.clipboardResources.length || !unref(canUpload)) {
return
}
// Browsers only allow single files to be pasted for security reasons
const items = (event.clipboardData || event.originalEvent.clipboardData).items
const fileItem = [...items].find((i) => i.kind === 'file')
if (!fileItem) {
return
}
const file = fileItem.getAsFile()
instance.onFilesSelected([file])
event.preventDefault()
}

onMounted(() => {
filesSelectedSub = uppyService.subscribe('filesSelected', instance.onFilesSelected)
uploadCompletedSub = uppyService.subscribe('uploadCompleted', instance.onUploadComplete)
document.addEventListener('paste', handlePasteFileEvent)
})

onBeforeUnmount(() => {
uppyService.unsubscribe('filesSelected', filesSelectedSub)
uppyService.unsubscribe('uploadCompleted', uploadCompletedSub)
uppyService.removeDropTarget()
document.removeEventListener('paste', handlePasteFileEvent)
})

watch(
Expand Down