- Spotify playlist, library, album and artist browsing with in-app playback - Song, playlist and album downloads via spotdl with YouTube and Bandcamp fallbacks - Electron desktop app (castLabs Widevine) with a permanent sidebar layout - Linux and Windows packaging scripts
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { z } from "zod";
|
|
import superjson from "superjson";
|
|
|
|
export const schema = z.object({
|
|
playlistUrl: z.string().min(1),
|
|
});
|
|
|
|
export type InputType = z.infer<typeof schema>;
|
|
export type SpotifyPlaylistTrack = {
|
|
id: string;
|
|
uri: string;
|
|
title: string;
|
|
artist: string;
|
|
album: string;
|
|
durationMs: number;
|
|
imageUrl?: string;
|
|
externalUrl?: string;
|
|
trackNumber?: number;
|
|
discNumber?: number;
|
|
isrc?: string;
|
|
isLocal: boolean;
|
|
};
|
|
|
|
export type OutputType = {
|
|
id: string;
|
|
name: string;
|
|
description?: string;
|
|
imageUrl?: string;
|
|
owner?: string;
|
|
externalUrl?: string;
|
|
total: number;
|
|
tracks: SpotifyPlaylistTrack[];
|
|
};
|
|
|
|
export async function postSpotifyPlaylist(body: InputType): Promise<OutputType> {
|
|
const validated = schema.parse(body);
|
|
const response = await fetch("/_api/spotify-playlist", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: superjson.stringify(validated),
|
|
});
|
|
if (!response.ok) {
|
|
const parsed = superjson.parse<{ error: string }>(await response.text());
|
|
throw new Error(parsed.error);
|
|
}
|
|
return superjson.parse<OutputType>(await response.text());
|
|
}
|