34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
/**
|
|
* The YouTube route.
|
|
*
|
|
* @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 YouTube route, for the player's tracklist:
|
|
*
|
|
* - `GET /api/youtube/playlist?list=` — public. Resolves a YouTube playlist id
|
|
* to its tracklist (titles and lengths).
|
|
*/
|
|
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<YouTubePlaylist> = {
|
|
success: true,
|
|
data: await resolveYouTubePlaylist(listId),
|
|
};
|
|
|
|
ctx.response.headers.set("Cache-Control", "public, max-age=3600");
|
|
ctx.response.body = responseBody;
|
|
});
|
|
|
|
export default youtubeRouter;
|