Cotton code
50 lines · 2.6 KB · TypeScriptRaw
/** * Cotton for the Mac (the menu bar app, `apps/cotton/Mac`): its update feed and its builds, served from * cottondb.com out of R2. * * The app's `SUFeedURL` is `https://cottondb.com/mac/cotton/appcast.xml` (build-cotton-mac.sh stamps it). * Until 23 Nov 2026 nothing answered that address: the site served only the retired CottonDB app's * `/mac/appcast.xml`, forwarded to a serving Mac that no longer serves, so the installed Cotton.app could never * update itself. The feed and the zips it names now live in the bucket the runner binaries * already do (`cotton-mac-releases`, bound as `MAC_RELEASES`), under `cotton/`, put there by * `apps/cotton/scripts/publish-cotton-mac.sh`: * *     https://cottondb.com/mac/cotton/appcast.xml          → cotton/appcast.xml   (five minutes of cache) *     https://cottondb.com/mac/cotton/Cotton-0.4.0-4.zip   → cotton/Cotton-0.4.0-4.zip (immutable) * * Each feed entry carries the EdDSA signature the app checks against the public key in its own Info.plist, so * the bucket being readable by anyone is fine: a zip nobody signed is refused by the app. *//** Everything under here is Cotton for the Mac's update surface. One prefix. */export const MAC_COTTON_PREFIX = "/mac/cotton/";/** The feed's file name; its key is `cotton/appcast.xml`. */export const MAC_COTTON_FEED = "appcast.xml";/** * A build's file name: `Cotton-<marketing version>-<build number>.zip`, nothing else. The grammar keeps a * request from naming an object nobody published: no path segments, no `..`, no query-shaped tail. */export const MAC_COTTON_ZIP = /^Cotton-\d+\.\d+\.\d+-\d+\.zip$/;/** The bucket key a `/mac/cotton/…` path names, with what it is, or null when the path names neither. */export function macCottonKey(pathname: string): { key: string; kind: "feed" | "zip" } | null {  if (!pathname.startsWith(MAC_COTTON_PREFIX)) return null;  const name = pathname.slice(MAC_COTTON_PREFIX.length);  if (name === MAC_COTTON_FEED) return { key: `cotton/${name}`, kind: "feed" };  if (MAC_COTTON_ZIP.test(name)) return { key: `cotton/${name}`, kind: "zip" };  return null;}/** The feed: XML, and short-lived, so a published build reaches Macs within minutes. */export const MAC_COTTON_FEED_HEADERS: Readonly<Record<string, string>> = {  "Content-Type": "application/xml; charset=utf-8",  "Cache-Control": "public, max-age=300",};/** A build: a zip whose bytes never change (a new build is a new name). */export const MAC_COTTON_ZIP_HEADERS: Readonly<Record<string, string>> = {  "Content-Type": "application/zip",  "Cache-Control": "public, max-age=31536000, immutable",};