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"
:link="modalEpisode.link"
:name="modalEpisode.name"
:size="modalEpisode.size"
:title="title"
:url="modalEpisode.url" />
</NcModal>

View File

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

View File

@ -1,5 +1,4 @@
// https://stackoverflow.com/a/53486112
export const debounce = (fn, delay) => {
let timeoutID = null
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]
}