Personal Site
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make sure client types are conformed to in sse

+6 -6
+6 -6
src/pages/now-playing-sse.ts
··· 1 1 import { sdk } from "/components/home/playing/spotify"; 2 + import type { nowPlaying } from "/components/home/playing/spotify/client"; 2 3 3 4 export async function GET() { 4 5 const update = async (): Promise<string> => { 5 6 // extract a subset to reduce size for client 6 7 // not huge savings but tesco yk 7 8 // + reduces chance of leaking extra data to client 8 - const playing = await sdk.player 9 - .getCurrentlyPlayingTrack() 10 - .then((playing) => 9 + const playing = await sdk.player.getCurrentlyPlayingTrack().then( 10 + (playing) => 11 11 // minimise body to make faster and streamline download 12 - !!playing && "album" in playing.item 12 + (!!playing && "album" in playing.item 13 13 ? { 14 14 id: playing.item.id, 15 15 name: playing.item.name, ··· 21 21 href: artist.external_urls.spotify, 22 22 })), 23 23 } 24 - : null, 25 - ); 24 + : null) satisfies nowPlaying, 25 + ); 26 26 27 27 // SSE syntax: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format 28 28 return `event: playing\ndata: ${JSON.stringify(playing)}\n\n`;