Added progress to upload

This commit is contained in:
Vito0912 2025-09-27 17:00:57 +02:00
parent e040396b20
commit 9ce6de3100
No known key found for this signature in database
GPG key ID: A0F767011D6093A2
3 changed files with 83 additions and 5 deletions

View file

@ -297,6 +297,15 @@ export default {
ref.setUploadStatus(status)
}
},
updateItemCardProgress(index, progress) {
var ref = this.$refs[`itemCard-${index}`]
if (ref && ref.length) ref = ref[0]
if (!ref) {
console.error('Book card ref not found', index, this.$refs)
} else {
ref.setUploadProgress(progress)
}
},
async uploadItem(item) {
var form = new FormData()
form.set('title', item.title)
@ -312,8 +321,20 @@ export default {
form.set(`${index++}`, file)
})
const config = {
onUploadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const progress = {
loaded: progressEvent.loaded,
total: progressEvent.total
}
this.updateItemCardProgress(item.index, progress)
}
}
}
return this.$axios
.$post('/api/upload', form)
.$post('/api/upload', form, config)
.then(() => true)
.catch((error) => {
console.error('Failed to upload item', error)