refactor: ♻️ move filename from url on utils
Some checks failed
repod / release (push) Waiting to run
repod / xml (push) Successful in 14s
repod / php (push) Successful in 1m5s
repod / nodejs (push) Has been cancelled

This commit is contained in:
Michel Roux 2024-08-17 14:17:24 +02:00
parent 66b59c52fa
commit a2c3b389ba
3 changed files with 18 additions and 16 deletions

View File

@ -10,11 +10,16 @@
</template> </template>
{{ title }} {{ title }}
</NcButton> </NcButton>
<NcButton v-if="url" :download="filename" :href="url" target="_blank"> <NcButton
v-if="url"
:download="filenameFromUrl(url)"
:href="url"
target="_blank">
<template #icon> <template #icon>
<DownloadIcon :size="20" /> <DownloadIcon :size="20" />
</template> </template>
{{ t('repod', 'Download') }} {{ size ? `(${episodeFileSize})` : '' }} {{ t('repod', 'Download') }}
{{ size ? `(${humanFileSize(size)})` : '' }}
</NcButton> </NcButton>
</div> </div>
</div> </div>
@ -25,6 +30,7 @@ import { NcAvatar, NcButton } from '@nextcloud/vue'
import DownloadIcon from 'vue-material-design-icons/Download.vue' import DownloadIcon from 'vue-material-design-icons/Download.vue'
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue' import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
import SafeHtml from './SafeHtml.vue' import SafeHtml from './SafeHtml.vue'
import { filenameFromUrl } from '../../utils/url.js'
import { humanFileSize } from '../../utils/size.js' import { humanFileSize } from '../../utils/size.js'
export default { export default {
@ -66,14 +72,9 @@ export default {
required: true, required: true,
}, },
}, },
computed: { methods: {
episodeFileSize() { filenameFromUrl,
return humanFileSize(this.size) humanFileSize,
},
filename() {
const url = new URL(this.url)
return url.pathname.split('/').pop()
},
}, },
} }
</script> </script>

View File

@ -70,7 +70,7 @@
</NcActionLink> </NcActionLink>
<NcActionLink <NcActionLink
v-if="episode.url" v-if="episode.url"
:download="filename(episode)" :download="filenameFromUrl(episode.url)"
:href="episode.url" :href="episode.url"
:name="t('repod', 'Download')" :name="t('repod', 'Download')"
target="_blank" target="_blank"
@ -123,6 +123,7 @@ import {
NcModal, NcModal,
NcProgressBar, NcProgressBar,
} from '@nextcloud/vue' } from '@nextcloud/vue'
import { decodeUrl, filenameFromUrl } from '../../utils/url.js'
import { import {
durationToSeconds, durationToSeconds,
formatEpisodeTimestamp, formatEpisodeTimestamp,
@ -138,7 +139,6 @@ import PlaylistPlayIcon from 'vue-material-design-icons/PlaylistPlay.vue'
import PlaylistRemoveIcon from 'vue-material-design-icons/PlaylistRemove.vue' import PlaylistRemoveIcon from 'vue-material-design-icons/PlaylistRemove.vue'
import StopIcon from 'vue-material-design-icons/Stop.vue' import StopIcon from 'vue-material-design-icons/Stop.vue'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import { decodeUrl } from '../../utils/url.js'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import { showError } from '../../utils/toast.js' import { showError } from '../../utils/toast.js'
import { usePlayer } from '../../store/player.js' import { usePlayer } from '../../store/player.js'
@ -224,10 +224,7 @@ export default {
}, },
methods: { methods: {
...mapActions(usePlayer, ['load']), ...mapActions(usePlayer, ['load']),
filename(episode) { filenameFromUrl,
const url = new URL(episode.url)
return url.pathname.split('/').pop()
},
formatLocaleDate, formatLocaleDate,
hasEnded(episode) { hasEnded(episode) {
return ( return (

View File

@ -1,3 +1,7 @@
export const encodeUrl = (url) => encodeURIComponent(btoa(url)) export const encodeUrl = (url) => encodeURIComponent(btoa(url))
export const decodeUrl = (url) => atob(decodeURIComponent(url)) export const decodeUrl = (url) => atob(decodeURIComponent(url))
export const toUrl = (url) => `/${encodeUrl(url)}` export const toUrl = (url) => `/${encodeUrl(url)}`
export const filenameFromUrl = (str) => {
const url = new URL(str)
return url.pathname.split('/').pop()
}