tangled
alpha
login
or
join now
vielle.dev
/
site
0
fork
atom
Personal Site
0
fork
atom
overview
issues
pulls
pipelines
Make server sent events follow the new type
vielle.dev
7 months ago
5bf8049e
0cf6c7d8
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+20
-13
1 changed file
expand all
collapse all
unified
split
src
pages
now-playing-sse.ts
+20
-13
src/pages/now-playing-sse.ts
···
1
1
-
import { spotifyNowPlaying, SpotifyError } from "/components/playing/spotify";
1
1
+
import {
2
2
+
spotifyNowPlaying,
3
3
+
SpotifyError,
4
4
+
type nowPlaying,
5
5
+
} from "/components/playing/spotify";
2
6
3
7
export async function GET() {
4
8
const update = async (): Promise<string> => {
5
9
// extract a subset to reduce size for client
6
10
// not huge savings but tesco yk
7
7
-
const playing = await spotifyNowPlaying()
11
11
+
// + reduces chance of leaking extra data to client
12
12
+
const playing: SpotifyError | nowPlaying = await spotifyNowPlaying()
8
13
.then((playing) =>
9
14
playing
10
15
? {
11
11
-
type: "track",
12
12
-
id: playing.id,
16
16
+
type: "track" as const,
13
17
name: playing.name,
18
18
+
external_urls: {
19
19
+
spotify: playing.external_urls.spotify,
20
20
+
},
14
21
album: {
15
15
-
images: playing.album.images.map((x) => ({
16
16
-
url: x.url,
17
17
-
width: x.width,
18
18
-
height: x.height,
19
19
-
})),
22
22
+
name: playing.album.name,
23
23
+
external_urls: {
24
24
+
spotify: playing.album.external_urls.spotify,
25
25
+
},
26
26
+
images: [playing.album.images[0]],
20
27
},
21
21
-
artists: playing.artists.map((x) => ({
22
22
-
name: x.name,
23
23
-
id: x.id,
28
28
+
artists: playing.artists.map((artist) => ({
29
29
+
external_urls: { spotify: artist.external_urls.spotify },
30
30
+
name: artist.name,
24
31
})),
25
32
}
26
33
: null,
···
29
36
if (!(err instanceof SpotifyError))
30
37
throw new Error("Unhandled exception");
31
38
if (err.code === "NO_CONTENT") return null;
32
32
-
39
39
+
33
40
console.error(err.code, err.human, err.details);
34
41
return err;
35
42
});