Skip to content

Commit

Permalink
fix: run file validation on drag-n-drop and capture events (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchez authored Nov 14, 2023
1 parent 9d16ffa commit 605aae6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cloud_storage/public/js/components/FileUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ export default {
},
dropfiles(e) {
this.is_dragging = false
this.add_files(e.dataTransfer.files)
for (const file of e.dataTransfer.files) {
this.add_file(file)
}
},
browse_files() {
this.$refs.file_input.click()
Expand Down Expand Up @@ -303,15 +305,19 @@ export default {
// - rename file
// - add version as latest
file.failed = true
file.error_message = __('A file already exists with this name. You can either rename this file to create a new record or continue to upload a new version to the existing file.')
file.error_message = __(
'A file already exists with this name. You can either rename this file to create a new record or continue to upload a new version to the existing file.'
)
} else if (content_exists) {
// new/existing file name, existing hash: show name of existing file instead
file.failed = true
if (filename_exists) {
file.error_message = __('This file already exists with the same name.')
} else if (matched_files.length > 0) {
file.error_message = `This file already exists with the name '${matched_files[0]}'. ` + __('You can continue with this name or exit.')
file.error_message =
`This file already exists with the name '${matched_files[0]}'. ` +
__('You can continue with this name or exit.')
} else {
file.error_message = __('A file with the same content already exists.')
}
Expand Down Expand Up @@ -660,7 +666,7 @@ export default {
capture.submit(data_urls => {
data_urls.forEach(data_url => {
let filename = `capture_${frappe.datetime.now_datetime().replaceAll(/[: -]/g, '_')}.png`
this.url_to_file(data_url, filename, 'image/png').then(file => this.add_files([file]))
this.url_to_file(data_url, filename, 'image/png').then(file => this.add_file(file))
})
})
},
Expand Down

0 comments on commit 605aae6

Please sign in to comment.