readBranch
uses tcmts.share.servedCodebase, which uses process
Read branch in this browser's studio, from its next page on (none, or the codebase's own: back to it). Only the
studio's maintainer; a branch that isn't there is refused.
import { HttpError, setCookie } from "#codebase/tcmts/server"; import { callerNow, servedCodebase } from "#codebase/tcmts/share"; import { BRANCH_COOKIE } from "#codebase/tcmts/studio"; export async function readBranch(branch: string): Promise<string> { const own = servedCodebase().cb; if (callerNow(own)?.role !== "maintainer") throw new HttpError(403, "Sign in first."); const name = branch.trim(); if (name && name !== own.store.branch().name && !own.store.hasBranch(name)) throw new HttpError(404, `There's no branch named ${name}.`); const back = !name || name === own.store.branch().name; setCookie(BRANCH_COOKIE, back ? "" : name, { maxAge: back ? 0 : 60 * 60 * 24 * 365, sameSite: "Strict", path: "/", }); return back ? own.store.branch().name : name; }
uses
- tcmts.server.HttpError
- tcmts.server.setCookie
- tcmts.share.callerNow
- tcmts.share.servedCodebase
- tcmts.studio.BRANCH_COOKIE