feat: add download size on modal download button
All checks were successful
repod / xml (push) Successful in 35s
repod / php (push) Successful in 1m0s
repod / nodejs (push) Successful in 2m25s
repod / release (push) Has been skipped

This commit is contained in:
Michel Roux 2024-01-14 00:19:53 +01:00
parent 822bf92a47
commit 47e44bdaf5
4 changed files with 15 additions and 2 deletions

View File

@ -40,6 +40,7 @@
:image="modalEpisode.image" :image="modalEpisode.image"
:link="modalEpisode.link" :link="modalEpisode.link"
:name="modalEpisode.name" :name="modalEpisode.name"
:size="modalEpisode.size"
:title="title" :title="title"
:url="modalEpisode.url" /> :url="modalEpisode.url" />
</NcModal> </NcModal>

View File

@ -22,7 +22,7 @@
<template #icon> <template #icon>
<Download :size="20" /> <Download :size="20" />
</template> </template>
{{ t('repod', 'Download') }} {{ t('repod', 'Download') }} {{ size ? `(${humanFileSize(size)})` : '' }}
</NcButton> </NcButton>
</div> </div>
</div> </div>
@ -32,6 +32,7 @@
import { NcAvatar, NcButton } from '@nextcloud/vue' import { NcAvatar, NcButton } from '@nextcloud/vue'
import Download from 'vue-material-design-icons/Download.vue' import Download from 'vue-material-design-icons/Download.vue'
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue' import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
import { humanFileSize } from '../../utils/size.js'
export default { export default {
name: 'Modal', name: 'Modal',
@ -66,6 +67,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
size: {
type: Number,
default: null,
},
}, },
computed: { computed: {
strippedDescription() { strippedDescription() {
@ -75,6 +80,9 @@ export default {
return strippedDescription.replace(/\n/g, '<br>') return strippedDescription.replace(/\n/g, '<br>')
}, },
}, },
methods: {
humanFileSize,
},
} }
</script> </script>

View File

@ -1,5 +1,4 @@
// https://stackoverflow.com/a/53486112 // https://stackoverflow.com/a/53486112
export const debounce = (fn, delay) => { export const debounce = (fn, delay) => {
let timeoutID = null let timeoutID = null
return function() { return function() {

5
src/utils/size.js Normal file
View File

@ -0,0 +1,5 @@
// https://stackoverflow.com/a/20732091
export const humanFileSize = (size) => {
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024))
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]
}