Drops every YouTube-backed route, proxy and type (external albums/tracks, thumbnail proxy, youtube.ts) and simplifies player/track/mix types to the local-only catalog now that the backend contract dropped Source/ExternalId. Genre tiles on Explore and "Populares esta semana" on Home stay as deliberate client-only placeholders per product decision, just without the YouTube backing. Also finishes the design-system unification pass: Home's three hand-rolled track rows (Continuar escuchando, Playlist destacada, Populares esta semana) now reuse the shared TrackTitleCell component instead of duplicating cover+title+artist markup, and the orphaned Rail.svelte (no importers) is removed.
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import type { PageServerLoad, Actions } from './$types';
|
|
import { createApiClient, requireUser } from '$lib/server/api';
|
|
import { addTrackAction } from '$lib/server/playlistActions';
|
|
import {
|
|
HOME_LATEST_PAGE_SIZE,
|
|
HOME_MIXES_LIMIT,
|
|
HOME_SHELF_LIMIT,
|
|
HOME_SPOTLIGHT_TRACKS_LIMIT
|
|
} from '$lib/config';
|
|
import { pickGreeting } from '$lib/server/greeting';
|
|
|
|
export const load: PageServerLoad = async ({ locals, url, fetch }) => {
|
|
// This dashboard is personal; an anonymous listener goes to /explore instead.
|
|
if (!locals.user) redirect(302, '/explore');
|
|
const user = requireUser(locals, url);
|
|
const api = createApiClient({ fetch, accessToken: locals.accessToken ?? undefined });
|
|
|
|
const latestPromise = api.GET('/tracks', {
|
|
params: { query: { pageNumber: 1, pageSize: HOME_LATEST_PAGE_SIZE } }
|
|
});
|
|
const playlistsPromise = api.GET('/playlists/users/{userId}', {
|
|
params: {
|
|
path: { userId: user.sub },
|
|
query: { pageNumber: 1, pageSize: HOME_SHELF_LIMIT + 1 }
|
|
}
|
|
});
|
|
const mixesPromise = api.GET('/mixes');
|
|
const recentlyPlayedPromise = api.GET('/users/{id}/listening-history', {
|
|
params: { path: { id: user.sub } }
|
|
});
|
|
const listeningStatsPromise = api
|
|
.GET('/users/{id}/listening-stats', { params: { path: { id: user.sub } } })
|
|
.then((res) => res.data ?? { tracksThisWeek: 0, secondsThisWeek: 0, streakDays: 0 })
|
|
.catch(() => ({ tracksThisWeek: 0, secondsThisWeek: 0, streakDays: 0 }));
|
|
|
|
const [latest, playlists, mixes, recentlyPlayed] = await Promise.all([
|
|
latestPromise,
|
|
playlistsPromise,
|
|
mixesPromise,
|
|
recentlyPlayedPromise
|
|
]);
|
|
const playlistItems = playlists.data?.items ?? [];
|
|
const latestItems = (latest.data?.items ?? []).map((item) => item.track);
|
|
|
|
const spotlightPlaylist = playlistItems[0] ?? null;
|
|
const spotlightTracksPromise = spotlightPlaylist
|
|
? api
|
|
.GET('/playlists/{playlistId}/tracks', {
|
|
params: {
|
|
path: { playlistId: spotlightPlaylist.id },
|
|
query: { pageNumber: 1, pageSize: HOME_SPOTLIGHT_TRACKS_LIMIT }
|
|
}
|
|
})
|
|
.then((res) => ({
|
|
items: res.data?.items ?? [],
|
|
totalCount: Number(res.data?.totalItemCount ?? 0)
|
|
}))
|
|
.catch(() => ({ items: [], totalCount: 0 }))
|
|
: Promise.resolve({ items: [], totalCount: 0 });
|
|
|
|
return {
|
|
greeting: pickGreeting(new Date()),
|
|
recentlyPlayed: recentlyPlayed.data ?? [],
|
|
mixes: (mixes.data ?? []).slice(0, HOME_MIXES_LIMIT),
|
|
playlists: playlistItems.slice(0, HOME_SHELF_LIMIT),
|
|
playlistsHasMore: playlistItems.length > HOME_SHELF_LIMIT,
|
|
newReleases: latestItems,
|
|
spotlightPlaylist,
|
|
spotlightTracks: spotlightTracksPromise,
|
|
listeningStats: listeningStatsPromise
|
|
};
|
|
};
|
|
|
|
export const actions: Actions = {
|
|
addTrack: addTrackAction
|
|
};
|