/** * The YouTube route, for the player's tracklist. * * - `GET /api/youtube/playlist?list=` — public. Resolves a YouTube playlist id * to its tracklist (titles and lengths). * * @module */ import { Router } from "@oak/oak"; import type { APIResponse } from "../../shared/api.ts"; import { resolveYouTubePlaylist } from "../remote/youtube-playlist.ts"; import type { YouTubePlaylist } from "../../shared/player.ts"; /** The router serving the endpoints the module doc lists. */ const youtubeRouter: Router = new Router(); // Public, like /api/bandcamp/tracks: it only reads a public page. The client // treats any failure as "show the embed without a tracklist". youtubeRouter.get("/api/youtube/playlist", async (ctx) => { const listId = ctx.request.url.searchParams.get("list") ?? ""; const responseBody: APIResponse = { success: true, data: await resolveYouTubePlaylist(listId), }; ctx.response.headers.set("Cache-Control", "public, max-age=3600"); ctx.response.body = responseBody; }); export default youtubeRouter;