2023-04-14 01:03:39 +02:00
|
|
|
<template>
|
|
|
|
<tr>
|
|
|
|
<td class="px-4">
|
|
|
|
{{ showFullPath ? file.metadata.path : file.metadata.relPath }}
|
|
|
|
</td>
|
2023-04-16 01:09:49 +02:00
|
|
|
<td>
|
2023-04-14 01:03:39 +02:00
|
|
|
{{ $bytesPretty(file.metadata.size) }}
|
|
|
|
</td>
|
|
|
|
<td class="text-xs">
|
|
|
|
<div class="flex items-center">
|
|
|
|
<p>{{ file.fileType }}</p>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td v-if="contextMenuItems.length" class="text-center">
|
2023-06-07 22:48:23 +02:00
|
|
|
<ui-context-menu-dropdown :items="contextMenuItems" :menu-width="110" @action="contextMenuAction" />
|
2023-04-14 01:03:39 +02:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
libraryItemId: String,
|
|
|
|
showFullPath: Boolean,
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
2023-04-16 01:09:49 +02:00
|
|
|
},
|
|
|
|
inModal: Boolean
|
2023-04-14 01:03:39 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
userToken() {
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
},
|
|
|
|
userCanDownload() {
|
|
|
|
return this.$store.getters['user/getUserCanDownload']
|
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
|
|
|
},
|
2023-04-16 01:09:49 +02:00
|
|
|
userIsAdmin() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
|
|
|
},
|
2023-04-14 01:03:39 +02:00
|
|
|
downloadUrl() {
|
2023-05-28 19:34:22 +02:00
|
|
|
return `${process.env.serverUrl}/api/items/${this.libraryItemId}/file/${this.file.ino}/download?token=${this.userToken}`
|
2023-04-14 01:03:39 +02:00
|
|
|
},
|
|
|
|
contextMenuItems() {
|
|
|
|
const items = []
|
|
|
|
if (this.userCanDownload) {
|
|
|
|
items.push({
|
|
|
|
text: this.$strings.LabelDownload,
|
|
|
|
action: 'download'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.userCanDelete) {
|
|
|
|
items.push({
|
|
|
|
text: this.$strings.ButtonDelete,
|
|
|
|
action: 'delete'
|
|
|
|
})
|
|
|
|
}
|
2023-04-16 01:09:49 +02:00
|
|
|
// Currently not showing this option in the Files tab modal
|
|
|
|
if (this.userIsAdmin && this.file.audioFile && !this.inModal) {
|
|
|
|
items.push({
|
|
|
|
text: this.$strings.LabelMoreInfo,
|
|
|
|
action: 'more'
|
|
|
|
})
|
|
|
|
}
|
2023-04-14 01:03:39 +02:00
|
|
|
return items
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-05-30 00:38:38 +02:00
|
|
|
contextMenuAction({ action }) {
|
2023-04-14 01:03:39 +02:00
|
|
|
if (action === 'delete') {
|
|
|
|
this.deleteLibraryFile()
|
|
|
|
} else if (action === 'download') {
|
|
|
|
this.downloadLibraryFile()
|
2023-04-16 01:09:49 +02:00
|
|
|
} else if (action === 'more') {
|
|
|
|
this.$emit('showMore', this.file.audioFile)
|
2023-04-14 01:03:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
deleteLibraryFile() {
|
|
|
|
const payload = {
|
|
|
|
message: 'This will delete the file from your file system. Are you sure?',
|
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/items/${this.libraryItemId}/file/${this.file.ino}`)
|
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('File deleted')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to delete file', error)
|
|
|
|
this.$toast.error('Failed to delete file')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
|
|
|
downloadLibraryFile() {
|
2023-05-28 22:10:34 +02:00
|
|
|
this.$downloadFile(this.downloadUrl, this.file.metadata.filename)
|
2023-04-14 01:03:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|