Fix styling and run only two uploads in parallel
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -108,7 +108,7 @@ export default {
|
||||
return
|
||||
}
|
||||
const files = event.dataTransfer.files
|
||||
for (let file of files) {
|
||||
for (const file of files) {
|
||||
this.onLocalAttachmentSelected(file)
|
||||
}
|
||||
event.dataTransfer.value = ''
|
||||
|
||||
@@ -32,14 +32,20 @@
|
||||
@change="handleUploadFile">
|
||||
<div class="attachment-list">
|
||||
<ul>
|
||||
<li v-for="attachment in uploadQueue">
|
||||
{{ attachment.name }}
|
||||
<progress :value="attachment.progress" max="100"></progress>
|
||||
<li v-for="attachment in uploadQueue" :key="attachment.name" class="attachment">
|
||||
<a class="fileicon" :style="mimetypeForAttachment('none')" />
|
||||
<div class="details">
|
||||
<a>
|
||||
<div class="filename">
|
||||
<span class="basename">{{ attachment.name }}</span>
|
||||
</div>
|
||||
<progress :value="attachment.progress" max="100" />
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li v-for="attachment in attachments"
|
||||
:key="attachment.id"
|
||||
class="attachment"
|
||||
style="display: flex;">
|
||||
class="attachment">
|
||||
<a class="fileicon" :style="mimetypeForAttachment(attachment.extendedData.mimetype)" :href="attachmentUrl(attachment)" />
|
||||
<div class="details">
|
||||
<a :href="attachmentUrl(attachment)" target="_blank">
|
||||
@@ -114,7 +120,7 @@ export default {
|
||||
}
|
||||
},
|
||||
attachments() {
|
||||
return this.$store.getters.attachmentsByCard(this.card.id).sort((a, b) => b.id - a.id)
|
||||
return [...this.$store.getters.attachmentsByCard(this.card.id)].sort((a, b) => b.id - a.id)
|
||||
},
|
||||
formattedFileSize() {
|
||||
return (filesize) => formatFileSize(filesize)
|
||||
@@ -141,7 +147,7 @@ export default {
|
||||
methods: {
|
||||
handleUploadFile(event) {
|
||||
const files = event.target.files ?? []
|
||||
for (let file of files) {
|
||||
for (const file of files) {
|
||||
this.onLocalAttachmentSelected(file)
|
||||
}
|
||||
event.target.value = ''
|
||||
@@ -208,6 +214,7 @@ export default {
|
||||
li.attachment {
|
||||
display: flex;
|
||||
padding: 3px;
|
||||
min-height: 44px;
|
||||
|
||||
&.deleted {
|
||||
opacity: .5;
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
*/
|
||||
import { showError } from '@nextcloud/dialogs'
|
||||
import { formatFileSize } from '@nextcloud/files'
|
||||
import PQueue from 'p-queue'
|
||||
|
||||
const queue = new PQueue({ concurrency: 2 })
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -39,29 +42,32 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
this.$set(this.uploadQueue, file.name, { name: file.name, progress: 0})
|
||||
this.$set(this.uploadQueue, file.name, { name: file.name, progress: 0 })
|
||||
const bodyFormData = new FormData()
|
||||
bodyFormData.append('cardId', this.cardId)
|
||||
bodyFormData.append('type', 'deck_file')
|
||||
bodyFormData.append('file', file)
|
||||
try {
|
||||
await this.$store.dispatch('createAttachment', { cardId: this.cardId,
|
||||
formData: bodyFormData,
|
||||
onUploadProgress: (e) => {
|
||||
const percentCompleted = Math.round((e.loaded * 100) / e.total)
|
||||
console.debug(percentCompleted)
|
||||
this.$set(this.uploadQueue[file.name], 'progress', percentCompleted)
|
||||
await queue.add(async() => {
|
||||
try {
|
||||
await this.$store.dispatch('createAttachment', { cardId: this.cardId,
|
||||
formData: bodyFormData,
|
||||
onUploadProgress: (e) => {
|
||||
const percentCompleted = Math.round((e.loaded * 100) / e.total)
|
||||
console.debug(percentCompleted)
|
||||
this.$set(this.uploadQueue[file.name], 'progress', percentCompleted)
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
if (err.response.data.status === 409) {
|
||||
this.overwriteAttachment = err.response.data.data
|
||||
this.modalShow = true
|
||||
} else {
|
||||
showError(err.response.data.message)
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
if (err.response.data.status === 409) {
|
||||
this.overwriteAttachment = err.response.data.data
|
||||
this.modalShow = true
|
||||
} else {
|
||||
showError(err.response.data.message)
|
||||
}
|
||||
}
|
||||
this.$delete(this.uploadQueue, file.name)
|
||||
this.$delete(this.uploadQueue, file.name)
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
overrideAttachment() {
|
||||
|
||||
Reference in New Issue
Block a user