Files
magpie/site/wrangler.jsonc
T
yetone 3fc6ee4111 site: release files from Cloudflare R2, GitHub behind them
Updates and the installer downloaded every file from github.com, which
answered 504 for every release file for hours on 2026-11-08. The site now
keeps a copy on R2 (bucket magpie-releases, binding RELEASES):

- A five-minute cron copies the newest release and the Stable one from
  github.com (or, when that fails, GitHub's API) into R2. R2's put takes a
  file only with the SHA-256 the release's SHA256SUMS gives. A run starts
  no copy after 4 minutes; the feeds' tags and the 4 newest besides are
  kept, older ones deleted.
- /files/<tag>/<file> serves R2's copy, Range and conditional asks
  included; a file R2 doesn't hold, or a failing R2, is a 302 to
  github.com.
- /api/latest (both channels) and /download name /files only for a file
  R2 holds under the release's hash, and give every file's github.com
  address as `github`, which the previous commit's clients fall back to.
  Older clients only mirror a github.com address, so a mirror never goes
  in front of the site's.
- start (en, zh, ja), privacy (en, zh, ja) and reference.md say where
  files come from.

Run (mote): node --test site/*.test.mjs 104/104, with files.test.mjs
(R2 stood in for by r2stub.mjs) and new worker tests for the feed,
/download, /files and the cron. wrangler deploy --dry-run binds RELEASES.

Broken by hand: onR2 taking any held file regardless of hash, two tests
red (the feed test and "bytes R2 holds under another hash").

Not tried yet: the real cron run and R2 serving (after deploy).
2026-11-09 05:48:23 +08:00

29 lines
1.2 KiB
JSON

// usemagpie.ai: the static site in public/, plus worker.js for the update
// feed and the download links. Deploy with `npx wrangler deploy` from here.
{
"name": "usemagpie",
"main": "worker.js",
"compatibility_date": "2026-09-01",
// the contributors page's list, from git history (credits-cli.mjs); a
// build that can't read git or GitHub keeps the last list, or none
"build": { "command": "node credits-cli.mjs wall" },
"assets": {
"directory": "./public",
"binding": "ASSETS",
// every request, so worker.js can send www.usemagpie.ai to usemagpie.ai
"run_worker_first": true
},
"routes": [
{ "pattern": "usemagpie.ai", "custom_domain": true },
{ "pattern": "www.usemagpie.ai", "custom_domain": true }
],
// the ledger of releases the Stable channel is chosen from (worker.js,
// "The Stable channel"), kept by the cron every quarter hour
"kv_namespaces": [{ "binding": "LEDGER", "id": "716b22ec7d4c496abb7b3dc085258fde" }],
// RELEASES: each release's files, copied from GitHub by the five-minute
// cron and served at /files (files.js)
"r2_buckets": [{ "binding": "RELEASES", "bucket_name": "magpie-releases" }],
"triggers": { "crons": ["*/15 * * * *", "*/5 * * * *"] },
"observability": { "enabled": true }
}