From 5bf8049e877aaf83cb96eefb347b4c4d7fb22ad9 Mon Sep 17 00:00:00 2001 From: afterlifepro Date: Sat, 26 Jul 2025 14:55:27 +0100 Subject: [PATCH] Make server sent events follow the new type --- src/pages/now-playing-sse.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/pages/now-playing-sse.ts b/src/pages/now-playing-sse.ts index 91cfffe..9b2c6b1 100644 --- a/src/pages/now-playing-sse.ts +++ b/src/pages/now-playing-sse.ts @@ -1,26 +1,33 @@ -import { spotifyNowPlaying, SpotifyError } from "/components/playing/spotify"; +import { + spotifyNowPlaying, + SpotifyError, + type nowPlaying, +} from "/components/playing/spotify"; export async function GET() { const update = async (): Promise => { // extract a subset to reduce size for client // not huge savings but tesco yk - const playing = await spotifyNowPlaying() + // + reduces chance of leaking extra data to client + const playing: SpotifyError | nowPlaying = await spotifyNowPlaying() .then((playing) => playing ? { - type: "track", - id: playing.id, + type: "track" as const, name: playing.name, + external_urls: { + spotify: playing.external_urls.spotify, + }, album: { - images: playing.album.images.map((x) => ({ - url: x.url, - width: x.width, - height: x.height, - })), + name: playing.album.name, + external_urls: { + spotify: playing.album.external_urls.spotify, + }, + images: [playing.album.images[0]], }, - artists: playing.artists.map((x) => ({ - name: x.name, - id: x.id, + artists: playing.artists.map((artist) => ({ + external_urls: { spotify: artist.external_urls.spotify }, + name: artist.name, })), } : null, @@ -29,7 +36,7 @@ export async function GET() { if (!(err instanceof SpotifyError)) throw new Error("Unhandled exception"); if (err.code === "NO_CONTENT") return null; - + console.error(err.code, err.human, err.details); return err; }); -- 2.51.2