File tree Expand file tree Collapse file tree 5 files changed +16
-42
lines changed
routes/music/playlist/[playlistID] Expand file tree Collapse file tree 5 files changed +16
-42
lines changed Original file line number Diff line number Diff line change 65
65
<div >
66
66
<h3 class =" header" >Playlists</h3 >
67
67
<div class =" section playlists" >
68
- {#each music .data ! .playlist_summaries as summary ( summary .id )}
69
- <Playlist {summary } />
68
+ {#each music .data ! .playlists as playlist ( playlist .id )}
69
+ <Playlist {playlist } />
70
70
{/each }
71
71
</div >
72
72
</div >
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
- import type { AppleMusicPlaylistSummary } from ' $lib/lcp/applemusic.server' ;
2
+ import type { AppleMusicPlaylist } from ' $lib/lcp/applemusic.server' ;
3
3
import { Card , Image } from ' @gleich/ui' ;
4
4
5
- const { summary }: { summary : AppleMusicPlaylistSummary } = $props ();
5
+ const { playlist }: { playlist : AppleMusicPlaylist } = $props ();
6
6
</script >
7
7
8
- <a href ={` /music/playlist/${summary .id } ` } class =" container" >
8
+ <a href ={` /music/playlist/${playlist .id } ` } class =" container" >
9
9
<Card padding =" 0" >
10
10
<div class =" collage-container" >
11
11
<div class =" collage" >
12
- {#each summary . first_four_tracks as track (track .id )}
12
+ {#each playlist . tracks . slice ( 0 , 4 ) as track (track .id )}
13
13
<div class =" collage-image" >
14
14
<Image
15
15
src ={track .album_art_preview_url }
22
22
</div >
23
23
{/each }
24
24
</div >
25
- <p class ="name" >{summary .name }</p >
25
+ <p class ="name" >{playlist .name }</p >
26
26
</div >
27
27
<button class =" view-more" >
28
- View {summary . track_count } tracks
28
+ View {playlist . tracks . length } tracks
29
29
</button >
30
30
</Card >
31
31
</a >
Original file line number Diff line number Diff line change 1
- import { LCP_TOKEN } from '$env/static/private' ;
2
- import type { SvelteFetch } from './lcp.server' ;
3
-
4
- export async function loadPlaylistFromLCP (
5
- id : string ,
6
- fetch : SvelteFetch
7
- ) : Promise < AppleMusicPlaylist | null > {
8
- try {
9
- const res = await fetch ( `https://lcp.mattglei.ch/applemusic/playlists/${ id } ` , {
10
- method : 'GET' ,
11
- cache : 'no-store' ,
12
- headers : {
13
- Authorization : `Bearer ${ LCP_TOKEN } `
14
- }
15
- } ) ;
16
- return await res . json ( ) ;
17
- } catch {
18
- return null ;
19
- }
20
- }
21
-
22
1
export interface CacheData {
23
2
recently_played : AppleMusicSong [ ] ;
24
- playlist_summaries : AppleMusicPlaylistSummary [ ] ;
3
+ playlists : AppleMusicPlaylist [ ] ;
25
4
}
26
5
27
6
export interface AppleMusicSong {
@@ -36,13 +15,6 @@ export interface AppleMusicSong {
36
15
preview_audio_url : string | null ;
37
16
}
38
17
39
- export interface AppleMusicPlaylistSummary {
40
- name : string ;
41
- id : string ;
42
- track_count : number ;
43
- first_four_tracks : AppleMusicSong [ ] ;
44
- }
45
-
46
18
export interface AppleMusicPlaylist {
47
19
name : string ;
48
20
id : string ;
Original file line number Diff line number Diff line change 1
- import { loadPlaylistFromLCP , type AppleMusicPlaylist } from '$lib/lcp/applemusic.server' ;
2
- import { type SvelteFetch } from '$lib/lcp/lcp.server' ;
1
+ import { type AppleMusicPlaylist , type CacheData } from '$lib/lcp/applemusic.server' ;
2
+ import { Cache , loadFromLCP , type SvelteFetch } from '$lib/lcp/lcp.server' ;
3
3
import type { PageServerLoad } from './$types' ;
4
4
5
5
export interface PlaylistData {
6
- playlist : AppleMusicPlaylist | null ;
6
+ playlist : AppleMusicPlaylist | undefined ;
7
7
}
8
8
9
9
export const load : PageServerLoad = async ( {
@@ -13,5 +13,7 @@ export const load: PageServerLoad = async ({
13
13
params : Record < string , string > ;
14
14
fetch : SvelteFetch ;
15
15
} ) => ( {
16
- playlist : await loadPlaylistFromLCP ( params . playlistID , fetch )
16
+ playlist : ( await loadFromLCP < CacheData > ( Cache . AppleMusic , fetch ) ) ?. data . playlists . find (
17
+ ( p ) => p . id === params . playlistID
18
+ )
17
19
} ) ;
Original file line number Diff line number Diff line change 5
5
import Since from ' $lib/time/since.svelte' ;
6
6
import ViewButton from ' $lib/view-button.svelte' ;
7
7
import { DynamicHead , Error } from ' @gleich/ui' ;
8
- import type { PlaylistData } from ' ./proxy +page.server' ;
8
+ import type { PlaylistData } from ' ./+page.server' ;
9
9
10
10
const { data }: { data: PlaylistData } = $props ();
11
11
</script >
You can’t perform that action at this time.
0 commit comments