From dcbaa6fcefe02a8e3f2794b09b2b9d8b67a7d45f Mon Sep 17 00:00:00 2001 From: kartik Date: Sat, 21 Nov 2026 19:04:31 +0530 Subject: [PATCH 1/5] Serve downloads from the site's own storage on Cloudflare GitHub sent the disk image slowly, at times about 20 KB a second, so downloads and updates could take minutes. The Worker now serves each release from the outbound-downloads R2 bucket at /download/, keeps it in the cache where it was asked for, and falls back to the GitHub release for any file not in the bucket. release.sh uploads both files there before it makes the GitHub release, and new appcast items point at the site. --- Website/src/pages/[...lang]/index.astro | 6 +-- Website/src/pages/[...lang]/thanks.astro | 2 +- scripts/release.sh | 23 +++++++---- worker/index.js | 51 +++++++++++++++++++----- wrangler.jsonc | 10 ++++- 5 files changed, 70 insertions(+), 22 deletions(-) diff --git a/Website/src/pages/[...lang]/index.astro b/Website/src/pages/[...lang]/index.astro index 26f6c97..b69a98f 100644 --- a/Website/src/pages/[...lang]/index.astro +++ b/Website/src/pages/[...lang]/index.astro @@ -46,7 +46,7 @@ const DIRECT = new Set([9, 10, 11]);

- +

{/* Shown to buyers for a year after checkout, from this browser's storage only, while app.js puts their key @@ -132,7 +132,7 @@ const DIRECT = new Set([9, 10, 11]);

- + @@ -188,7 +188,7 @@ const DIRECT = new Set([9, 10, 11]);

- +
diff --git a/Website/src/pages/[...lang]/thanks.astro b/Website/src/pages/[...lang]/thanks.astro index f09f410..9681eeb 100644 --- a/Website/src/pages/[...lang]/thanks.astro +++ b/Website/src/pages/[...lang]/thanks.astro @@ -23,7 +23,7 @@ const href = (path: string) => localHref(lang, path);
  1. -
    +
  2. diff --git a/scripts/release.sh b/scripts/release.sh index 19730c3..06f4b46 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -6,12 +6,14 @@ cd "$(dirname "$0")/.." # # scripts/release.sh 1.1 "What's new, in a sentence or two." # -# It bumps the version, builds, signs and notarizes the app, publishes it as a GitHub release, and adds it to -# the appcast and the changelog on the website. Every copy checks that appcast once a day, downloads the update, checks its -# signature, and installs it the next time the Mac is left alone. +# It bumps the version, builds, signs and notarizes the app, publishes it as a GitHub release and in the site's own +# storage on Cloudflare, where downloads and updates come from, and adds it to the appcast and the changelog on the +# website. Every copy checks that appcast once a day, downloads the update, checks its signature, and installs it the +# next time the Mac is left alone. # # Needs the Developer ID identity, the outbound-notary profile, and Sparkle's signing key in the login -# keychain (made once with generate_keys --account app.outbound.Outbound; keep a backup of it). +# keychain (made once with generate_keys --account app.outbound.Outbound; keep a backup of it), and Wrangler +# logged in to Cloudflare (npx wrangler login). usage='Usage: scripts/release.sh ""' version="${1:?$usage}" notes="${2:?$usage}" @@ -25,6 +27,10 @@ git pull --ff-only --quiet ! gh release view "v$version" >/dev/null 2>&1 || { echo "v$version is already out." >&2; exit 1; } swift package resolve >/dev/null sign_update=.build/artifacts/sparkle/Sparkle/bin/sign_update +[[ -d node_modules ]] || npm ci --silent +bucket=outbound-downloads +npx wrangler r2 bucket info "$bucket" >/dev/null 2>&1 || + { echo "Can't reach the $bucket bucket on Cloudflare: log in with npx wrangler login." >&2; exit 1; } # The new version, and a build number one past the last, which is what Sparkle compares. build=$(( $(plutil -extract CFBundleVersion raw "$plist") + 1 )) @@ -39,7 +45,11 @@ zip="build/Outbound-v$version.zip" cp build/Outbound.dmg "$dmg" cp build/Outbound.zip "$zip" -# Publish the disk image first, so the appcast never points at a file that isn't there yet. +# Publish the disk image first, so the appcast never points at a file that isn't there yet: in the bucket, which the +# site serves downloads and updates from at /download/, and on GitHub, as the record of the release. +for file in "$dmg" "$zip"; do + npx wrangler r2 object put "$bucket/$(basename "$file")" --file "$file" --remote >/dev/null +done gh release create "v$version" "$dmg" "$zip" --target "$(git rev-parse HEAD)" \ --title "Outbound v$version" --notes "$notes" @@ -52,7 +62,7 @@ item=" $build $version $(plutil -extract LSMinimumSystemVersion raw Configuration/Info.plist) - + " ITEM="$item" awk '{ print } // && !done { print ENVIRON["ITEM"]; done = 1 }' "$appcast" > "$appcast.new" mv "$appcast.new" "$appcast" @@ -69,7 +79,6 @@ fi git add "$entry" # The site serves the appcast, so it has to build before the update can go out. -[[ -d node_modules ]] || npm ci --silent npm run build >/dev/null || { echo "The site doesn't build, so v$version isn't offered yet: fix it, then commit and push." >&2; exit 1; } git commit --quiet -am "Offer Outbound v$version as an update" diff --git a/worker/index.js b/worker/index.js index be1ad64..0dfe442 100644 --- a/worker/index.js +++ b/worker/index.js @@ -7,7 +7,8 @@ // With ?from=appstore, as the Mac App Store copy opens them, without any way // to buy or download it here (forAppStore). // GET /buy[?currency=usd] On to a new Polar checkout for Outbound, in that money, or in dollars. -// GET /download The newest disk image, Outbound-v1.0.dmg and so on, from GitHub. +// GET /download On to the newest disk image, /download/Outbound-v1.0.dmg and so on. +// GET /download/Outbound-v1.0.dmg That version's disk image, or its .zip, from the site's own storage. // POST /api/checkout A new Polar checkout for Outbound, in the buyer's money: { id, url, expires_at }. // POST /api/license { checkout } That checkout's license key once it is paid: // { status: "ready", key, email, paid } or { status: "pending" | "open" | ... }. @@ -42,6 +43,8 @@ const MESSAGE_LIMIT = 2000; const VERSION = /^\d{1,3}(\.\d{1,3}){0,2}$/; // The app's line about how the painting runs on that Mac: chip, macOS, holds, GPU errors and cost. const DIAG = /^[A-Za-z0-9 =:,._-]{1,160}$/; +// What a release puts up for download: its disk image and its zip, by version. +const RELEASE_FILE = /^Outbound-v(\d{1,3}(?:\.\d{1,3}){1,2})\.(dmg|zip)$/; // Outbound's price in the visitor's own money, in the countries most buyers come from, as Cloudflare places them: // the currency its checkout charges, and how the pages write the price. The Outbound product in Polar needs a price // of that amount in each currency. Everywhere else, and for anyone who asks for dollars, it's $4.99. Turkish pages @@ -77,9 +80,10 @@ const PRICES = { const PRICE_OR_DOLLARS = /(]*\sdata-dollars\b[^>]*>)([\s\S]*?<\/a>)|\$4\.99(?![\d.,])/g; export default { - async fetch(request, env) { + async fetch(request, env, ctx) { const url = new URL(request.url); - if (url.pathname === "/download") return download(request, env); + if (url.pathname === "/download") return newest(request, env); + if (url.pathname.startsWith("/download/")) return download(request, env, ctx, url); if (url.pathname === "/buy") return buy(request, env, url); if (TRANSLATED.has(url.pathname)) return forAppStore(url, await page(request, env, url)); if (!url.pathname.startsWith("/api/")) return forAppStore(url, await priced(request, env)); @@ -98,15 +102,44 @@ export default { }, }; -// The newest disk image, read from the site's own update feed, which scripts/release.sh writes once the release +// The newest disk image is the first in the site's own update feed, which scripts/release.sh writes once the release // is up. No call to GitHub's API, whose limits shared addresses run into. Before any release, the releases page. -async function download(request, env) { +async function newest(request, env) { const feed = await env.ASSETS.fetch(new Request(new URL("/appcast.xml", request.url))); - const match = (await feed.text()).match(/ Date: Sat, 21 Nov 2026 19:04:31 +0530 Subject: [PATCH 2/5] Send the 1.9 update through the site as well --- Website/public/appcast.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Website/public/appcast.xml b/Website/public/appcast.xml index 5b0e8d1..b2f32ee 100644 --- a/Website/public/appcast.xml +++ b/Website/public/appcast.xml @@ -13,7 +13,7 @@ 12 1.9 13.0 - + Outbound v1.8.1 From 6095448b9fd9bd22f206c12a1f48ee8f9534a77d Mon Sep 17 00:00:00 2001 From: kartik Date: Sat, 21 Nov 2026 20:19:03 +0530 Subject: [PATCH 3/5] Make the download route safe to rely on A storage or cache error now sends the download on to GitHub instead of failing, and so does any Outbound-v name the bucket doesn't have, so a hand-made version name still works. A download resumed part way gets the rest from storage when the cache doesn't have it. Files are cached for a day rather than a year, and release.sh takes only versions like 1.9 or 1.9.1 and won't put up a version the bucket already has. The responses also carry the site's HSTS and nosniff headers. --- scripts/release.sh | 4 ++++ worker/index.js | 57 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index 06f4b46..d6beab8 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -17,6 +17,7 @@ cd "$(dirname "$0")/.." usage='Usage: scripts/release.sh ""' version="${1:?$usage}" notes="${2:?$usage}" +[[ "$version" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]] || { echo "A version looks like 1.9 or 1.9.1." >&2; exit 1; } identity="Developer ID Application: Kartik Kulloli (55W3P96VL4)" plist=Configuration/Info.plist appcast=Website/public/appcast.xml @@ -31,6 +32,9 @@ sign_update=.build/artifacts/sparkle/Sparkle/bin/sign_update bucket=outbound-downloads npx wrangler r2 bucket info "$bucket" >/dev/null 2>&1 || { echo "Can't reach the $bucket bucket on Cloudflare: log in with npx wrangler login." >&2; exit 1; } +# Caches near downloaders keep a file for a day, so a version's files go up once and are never replaced. +! npx wrangler r2 object get "$bucket/Outbound-v$version.dmg" --remote --pipe >/dev/null 2>&1 || + { echo "The $bucket bucket already has v$version." >&2; exit 1; } # The new version, and a build number one past the last, which is what Sparkle compares. build=$(( $(plutil -extract CFBundleVersion raw "$plist") + 1 )) diff --git a/worker/index.js b/worker/index.js index 0dfe442..df5c60c 100644 --- a/worker/index.js +++ b/worker/index.js @@ -43,8 +43,9 @@ const MESSAGE_LIMIT = 2000; const VERSION = /^\d{1,3}(\.\d{1,3}){0,2}$/; // The app's line about how the painting runs on that Mac: chip, macOS, holds, GPU errors and cost. const DIAG = /^[A-Za-z0-9 =:,._-]{1,160}$/; -// What a release puts up for download: its disk image and its zip, by version. -const RELEASE_FILE = /^Outbound-v(\d{1,3}(?:\.\d{1,3}){1,2})\.(dmg|zip)$/; +// What a release puts up for download: its disk image and its zip, by version. scripts/release.sh makes versions like +// 1.9 and 1.9.1; a name of any other version still finds its GitHub release. +const RELEASE_FILE = /^Outbound-v(\d[\w.-]{0,30})\.(dmg|zip)$/; // Outbound's price in the visitor's own money, in the countries most buyers come from, as Cloudflare places them: // the currency its checkout charges, and how the pages write the price. The Outbound product in Polar needs a price // of that amount in each currency. Everywhere else, and for anyone who asks for dollars, it's $4.99. Turkish pages @@ -106,14 +107,15 @@ export default { // is up. No call to GitHub's API, whose limits shared addresses run into. Before any release, the releases page. async function newest(request, env) { const feed = await env.ASSETS.fetch(new Request(new URL("/appcast.xml", request.url))); - const match = (await feed.text()).match(/ 0 || last < file.size - 1) { + headers.set("Content-Range", `bytes ${first}-${last}/${file.size}`); + headers.set("Content-Length", String(last - first + 1)); + return new Response(file.body, { status: 206, headers }); + } const response = new Response(file.body, { headers }); - ctx.waitUntil(caches.default.put(key, response.clone())); + ctx.waitUntil(caches.default.put(key, response.clone()).catch(() => {})); return response; } +// The first and last byte an R2 range covers, in a file of that size. +function span(range, size) { + if (range.suffix !== undefined) return [Math.max(size - range.suffix, 0), size - 1]; + const first = range.offset ?? 0; + const last = range.length === undefined ? size - 1 : first + range.length - 1; + return [first, Math.min(last, size - 1)]; +} + // An English page, or a redirect to the same page in the visitor's language. Search engines, which send no // languages, get English and find the others through the pages' hreflang links. async function page(request, env, url) { From 350507d00ec2ec5aa726b32f4b2e4a8fc5aa0da2 Mon Sep 17 00:00:00 2001 From: kartik Date: Sat, 21 Nov 2026 20:19:03 +0530 Subject: [PATCH 4/5] Say in the privacy policy that downloads come from this site --- Website/src/pages/privacy.astro | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Website/src/pages/privacy.astro b/Website/src/pages/privacy.astro index 62a8d39..aef4ee1 100644 --- a/Website/src/pages/privacy.astro +++ b/Website/src/pages/privacy.astro @@ -10,7 +10,7 @@ import Topbar from "../components/Topbar.astro";