14 lines
559 B
TypeScript
14 lines
559 B
TypeScript
import type { PageServerLoad } from './$types'
|
|
import { getLyricsProcessed, getSongUrl, checkLyricsProcessed } from "$lib/server/songs.ts"
|
|
import { redirect } from '@sveltejs/kit'
|
|
|
|
export const load: PageServerLoad = async ({ params, url }) => {
|
|
const songId = +params.id
|
|
const hasLrc = await checkLyricsProcessed(songId)
|
|
|
|
if (!hasLrc) throw redirect(302, `/song/${songId}`)
|
|
|
|
const lrc = await getLyricsProcessed(songId)!
|
|
const audioUrl = url.searchParams.get('music') === 'true' ? await getSongUrl(songId) : undefined
|
|
return { lrc, audioUrl }
|
|
} |