From 2524cfd82359be25ee237c093e149b2a0657b9a6 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sat, 22 Nov 2025 20:53:48 +0800 Subject: [PATCH] [+] Return source-separated url --- src/lib/server/songs.ts | 13 +++++++++++-- src/routes/song/[id]/play/+page.svelte | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/server/songs.ts b/src/lib/server/songs.ts index 6096224..5c79631 100644 --- a/src/lib/server/songs.ts +++ b/src/lib/server/songs.ts @@ -104,7 +104,16 @@ export const getSongUrl = async (id: number | string) => { const level = 'exhigh' const filePath = path.join(CACHE_DIR, `${id}/${level}.mp3`) const publicUrl = `/audio/${id}/${level}.mp3` - if (await fs.exists(filePath)) return publicUrl + const vocalsPath = path.join(CACHE_DIR, `${id}/vocals.opus`) + const instrumentalPath = path.join(CACHE_DIR, `${id}/instrumental.opus`) + + if (await fs.exists(filePath)) { + return { + url: publicUrl, + vocalsUrl: (await fs.exists(vocalsPath)) ? `/audio/${id}/vocals.opus` : null, + instrumentalUrl: (await fs.exists(instrumentalPath)) ? `/audio/${id}/instrumental.opus` : null + } + } // Check netease api status if (await checkNetease() === null) throw error(500, '服务器的网易云账号坏掉了 :(') @@ -125,7 +134,7 @@ export const getSongUrl = async (id: number | string) => { await fs.writeFile(filePath, Buffer.from(buffer)) console.log(`Song ${id} cached to ${filePath}`) - return publicUrl + return { url: publicUrl } } // ///////////////////////////////////////////////////////////////////////////// diff --git a/src/routes/song/[id]/play/+page.svelte b/src/routes/song/[id]/play/+page.svelte index 6ebc949..d29ed6a 100644 --- a/src/routes/song/[id]/play/+page.svelte +++ b/src/routes/song/[id]/play/+page.svelte @@ -80,7 +80,7 @@ hiddenInput.addEventListener('blur', onBlur) if (data.audioUrl) { - musicControl = new MusicControl(data.audioUrl) + musicControl = new MusicControl(data.audioUrl.url) musicControl.setLyrics(deduplicatedLyrics) musicControl.start() }