All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { Router } from "@oak/oak";
|
|
import type { APIResponse } from "../../shared/api.ts";
|
|
import { resolveBandcamp } from "../remote/bandcamp-streams.ts";
|
|
import type { Tralbum } from "../../shared/player.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 responseBody: APIResponse<Tralbum> = {
|
|
success: true,
|
|
data: 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 = responseBody;
|
|
});
|
|
|
|
export default bandcampRouter;
|