- 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
22 lines
1.0 KiB
TypeScript
22 lines
1.0 KiB
TypeScript
import superjson from "superjson";
|
|
import { schema, type OutputType } from "./spotify-download_POST.schema";
|
|
import { appendSetCookies } from "../helpers/spotifyServer";
|
|
import { jsonError, requireDownloadAccess, startDownloadJob } from "../helpers/downloadJobs";
|
|
|
|
export async function handle(request: Request) {
|
|
try {
|
|
const access = await requireDownloadAccess(request);
|
|
if (access.error) return access.error;
|
|
|
|
const parsed = schema.safeParse(superjson.parse(await request.text()));
|
|
if (!parsed.success) return jsonError(parsed.error.issues[0]?.message || "Invalid download request.", 400);
|
|
|
|
const job = startDownloadJob({ ownerId: access.userId, ...parsed.data });
|
|
const headers = new Headers({ "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
appendSetCookies(headers, access.setCookies);
|
|
return new Response(superjson.stringify({ jobId: job.id } satisfies OutputType), { headers });
|
|
} catch (error) {
|
|
return jsonError(error instanceof Error ? error.message : "Unable to start the download.", 503);
|
|
}
|
|
}
|