Files
brokeless/src/lib/updates.ts
T
MangaValkandClaude Opus 5.5 cec3b15c2c brokeless: fully local by default, and a README for it
- BROKE_OFFLINE=1 (on in Docker) turns off the GitHub update check and the
  exchange-rate fetch, so the server makes no calls out
- auto-update in scripts/start.mjs pulls from your own repo (origin), never upstream
- install.sh points at brokeless; drop the workflow that merged upstream by itself
- compose project and image are named brokeless
- README: what changed from broke, how to run it, how to review upstream

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:08:42 +01:00

23 lines
1.2 KiB
TypeScript

import "server-only";
// Is there a newer broke on GitHub than the code this copy was built from? Compares commit dates, so a copy with its
// own changes (newer commits of its own) isn't told to update. Asks GitHub at most every 6 hours; any failure means no.
const REPO = "nextwork-projects/broke";
const g = globalThis as unknown as { __brokeUpdate?: { at: number; newer: boolean } };
export async function updateReady() {
const built = process.env.BROKE_BUILT_FROM;
if (!built || process.env.BROKE_OFFLINE === "1") return false; // offline: updates are pulled and reviewed by hand
if (g.__brokeUpdate && Date.now() - g.__brokeUpdate.at < 6 * 3600_000) return g.__brokeUpdate.newer;
let newer = false;
try {
const res = await fetch(`https://api.github.com/repos/${REPO}/commits/main`, { headers: { accept: "application/vnd.github+json" }, signal: AbortSignal.timeout(3000) });
const date = res.ok ? ((await res.json()) as { commit?: { committer?: { date?: string } } }).commit?.committer?.date : null;
newer = !!date && Date.parse(date) > Date.parse(built) + 60_000;
} catch {
/* offline: say nothing */
}
g.__brokeUpdate = { at: Date.now(), newer };
return newer;
}