import { Router } from "@oak/oak"; import { resolveBandcamp } from "../services/bandcamp-stream-service.ts"; const bandcampRouter = new Router(); /** * Resolve a Bandcamp page to its streamable tracks. * * Public, like /api/preview: it only reads a public page and returns URLs the * same page already hands any visitor. Errors are thrown as APIException and * rendered by errorMiddleware; the client treats any failure as "fall back to * the iframe embed". */ bandcampRouter.get("/api/bandcamp/tracks", async (ctx) => { const url = ctx.request.url.searchParams.get("url") ?? ""; const force = ctx.request.url.searchParams.get("force") === "1"; const album = await resolveBandcamp(url, { force }); // Private: the signed URLs in the body are per-fetch, so they must not be // held in a shared cache. Well inside the 24h signature life either way. ctx.response.headers.set("Cache-Control", "private, max-age=3600"); ctx.response.body = { success: true, data: album }; }); export default bandcampRouter;