Build media URLs from public bucket config

This commit is contained in:
lucast committed 2026-09-29 16:22:22 +02:00
1 parent 19e84d774c
commit 069ef37825
8 files changed
+12 -16

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ const data = await Promise.allSettled(
v-for="album in item.albums" v-for="album in item.albums"
:key="album._id" :key="album._id"
:name="album.name" :name="album.name"
:file="`${BACKEND_SERVE}${album.file}`" :file="GET_FILE(album.file)"
:artists="album.artists" :artists="album.artists"
:_id="album._id" :_id="album._id"
/> />
-1
View File
@@ -14,7 +14,6 @@ const tableRows: Row[] = [
name: "file", name: "file",
displayName: "Cover", displayName: "Cover",
type: "image", type: "image",
prefix: `${BACKEND_SERVE}`,
}, },
{ {
name: "name", name: "name",
-1
View File
@@ -14,7 +14,6 @@ const tableRows: Row[] = [
name: "file", name: "file",
displayName: "Cover", displayName: "Cover",
type: "image", type: "image",
prefix: `${BACKEND_SERVE}`,
}, },
{ {
name: "name", name: "name",
-2
View File
@@ -14,8 +14,6 @@ const tableRows: Row[] = [
name: "fileDir", name: "fileDir",
displayName: "Audio File", displayName: "Audio File",
type: "audio", type: "audio",
prefix: `${BACKEND_SERVE}`,
suffix: "/high.m4a",
}, },
{ {
name: "name", name: "name",
+1 -1
View File
@@ -90,7 +90,7 @@ const { playAlbum, playShuffledAlbum, playAlbumAtIndex } = usePlayer()
v-for="album in albumsData" v-for="album in albumsData"
:key="album._id" :key="album._id"
:name="album.name" :name="album.name"
:file="`${BACKEND_SERVE}${album.file}`" :file="GET_FILE(album.file)"
:artists="album.artists" :artists="album.artists"
:_id="album._id" :_id="album._id"
/> />
+3 -2
View File
@@ -1,6 +1,7 @@
import { Howl } from "howler" import { Howl } from "howler"
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
const mediaBaseUrl = useRuntimeConfig().public.mediaBaseUrl
const { close: closeFullscreen } = useFullscreen() const { close: closeFullscreen } = useFullscreen()
const VOLUME_STORAGE_KEY = "music-v2-player-volume" const VOLUME_STORAGE_KEY = "music-v2-player-volume"
const DEFAULT_VOLUME = 0.5 const DEFAULT_VOLUME = 0.5
@@ -84,7 +85,7 @@ export default defineNuxtPlugin((nuxtApp) => {
album: currentSong.value.album.name, album: currentSong.value.album.name,
artwork: [ artwork: [
{ {
src: GET_FILE(currentSong.value.album.file), src: GET_FILE(currentSong.value.album.file, mediaBaseUrl),
sizes: "512x512", sizes: "512x512",
}, },
], ],
@@ -183,7 +184,7 @@ export default defineNuxtPlugin((nuxtApp) => {
if (!song) throw new Error("Song not provided") if (!song) throw new Error("Song not provided")
const newSound = new Howl({ const newSound = new Howl({
src: [GET_AUDIO_FILE(song.fileDir)], src: [GET_AUDIO_FILE(song.fileDir, mediaBaseUrl)],
html5: false, html5: false,
autoplay: false, autoplay: false,
volume: storedVolume.value, volume: storedVolume.value,
+2 -4
View File
@@ -4,8 +4,6 @@ export type Row = {
class?: string class?: string
width?: string width?: string
type?: "image" | "audio" type?: "image" | "audio"
prefix?: string
suffix?: string
displayName?: string displayName?: string
} }
@@ -37,12 +35,12 @@ const { rows, data } = defineProps<TableProps>()
<slot :name="row.name" :item="item" :index="i"> <slot :name="row.name" :item="item" :index="i">
<nuxt-img <nuxt-img
v-if="row.type == 'image'" v-if="row.type == 'image'"
:src="`${row.prefix}${item[row.name]}`" :src="GET_FILE(item[row.name])"
/> />
<audio <audio
v-else-if="row.type == 'audio'" v-else-if="row.type == 'audio'"
controls controls
:src="`${row.prefix}${item[row.name]}${row.suffix}`" :src="GET_AUDIO_FILE(item[row.name])"
/> />
<p v-else>{{ item[row.name] }}</p> <p v-else>{{ item[row.name] }}</p>
</slot> </slot>
+5 -4
View File
@@ -1,6 +1,7 @@
export const BACKEND_SERVE = "/static/" export const GET_FILE = (file: string, baseUrl = useRuntimeConfig().public.mediaBaseUrl) => {
return `${String(baseUrl).replace(/\/+$/, "")}/${file.replace(/^\/+/, "")}`
}
export const GET_FILE = (file: string) => `${BACKEND_SERVE}${file}` export const GET_AUDIO_FILE = (file: string, baseUrl?: string) => {
export const GET_AUDIO_FILE = (file: string) => { return GET_FILE(`${file}/high.m4a`, baseUrl)
return `${GET_FILE(file)}/high.m4a`
} }