feat: the redesigned Event Clock
The new reader app replaces the old UI: Checklist with a rail (focus pills, Next to expire, today's dailies, pinned routines), Timeline in a new and a classic look, Routines, Archive and a Settings area, in a Structured (default) and a Relaxed interface. It follows the approved Round 6 B and Round 7 mockups, corrected screen by screen with the owner. Reader data moves to a v2 store (gacha-tracker:v2:*). Existing v1 data is migrated on first load, a recovery copy is written first, and the v1 keys are never removed, so a rollback finds them unchanged. Redeem codes for Genshin arrive as their own feed. Also: live's urgency ramp, editable per theme; completion and section-complete fireworks; a returning-user tour; the design mockups, specs, plans, reviews and handoff record. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ddd9673f86
commit
50c6e91b00
@@ -0,0 +1,65 @@
|
||||
import { mkdir, rename } from "node:fs/promises";
|
||||
import { CODE_SOURCES } from "../src/ingest/codes/registry.ts";
|
||||
import { buildCodesFeed } from "../src/ingest/codes/build.ts";
|
||||
import { CodesFeedSchema, type CodesFeed } from "../src/shared/codes.ts";
|
||||
import { SnapshotStore, freshnessAt } from "../src/ingest/snapshots.ts";
|
||||
import type { SourceHealth } from "../src/shared/feed.ts";
|
||||
export async function buildCodes() {
|
||||
const root = process.env.SNAPSHOT_DIR ?? "snapshots",
|
||||
out = process.env.PUBLIC_DIR ?? "public",
|
||||
store = new SnapshotStore(root);
|
||||
const firstPath = `${root}/codes-first-seen.json`;
|
||||
let first: Record<string, string> = {};
|
||||
try {
|
||||
first = await Bun.file(firstPath).json();
|
||||
} catch {
|
||||
/* First offline build uses the fixture's capture date. */
|
||||
}
|
||||
const previous: CodesFeed = { schemaVersion: 1, codes: [], sources: [] };
|
||||
const codes: CodesFeed["codes"] = [];
|
||||
const sources: SourceHealth[] = [];
|
||||
for (const source of CODE_SOURCES) {
|
||||
const snapshot = await store.read(source.id),
|
||||
at = snapshot
|
||||
? freshnessAt(snapshot)
|
||||
: ((
|
||||
await Bun.file(
|
||||
"fixtures/genshin/game8-codes-2026-10-16.meta.json",
|
||||
).json()
|
||||
).contentChangedAt as string),
|
||||
html =
|
||||
snapshot?.html ??
|
||||
(await Bun.file("fixtures/genshin/game8-codes-2026-10-16.html").text());
|
||||
const parsed = source.parse(html, {
|
||||
now: new Date().toISOString(),
|
||||
sourceId: source.id,
|
||||
sourceUrl: source.url,
|
||||
game: source.game,
|
||||
});
|
||||
const built = buildCodesFeed(previous, parsed, at);
|
||||
for (const code of built.codes) {
|
||||
code.firstObservedAt = first[code.id] ?? code.firstObservedAt;
|
||||
first[code.id] = code.firstObservedAt;
|
||||
codes.push(code);
|
||||
}
|
||||
sources.push({
|
||||
sourceId: source.id,
|
||||
game: source.game,
|
||||
url: source.url,
|
||||
lastSuccessAt: at,
|
||||
lastConfirmedAt: snapshot?.meta.lastConfirmedAt ?? null,
|
||||
contentChangedAt: snapshot?.meta.contentChangedAt ?? at,
|
||||
eventCount: parsed.length,
|
||||
parsedCount: parsed.length,
|
||||
statesNoEvents: false,
|
||||
});
|
||||
}
|
||||
const feed = CodesFeedSchema.parse({ schemaVersion: 1, codes, sources });
|
||||
await mkdir(`${out}/data`, { recursive: true });
|
||||
await Bun.write(`${out}/data/codes.v1.json`, JSON.stringify(feed));
|
||||
await mkdir(root, { recursive: true });
|
||||
await Bun.write(firstPath + ".tmp", JSON.stringify(first, null, 2) + "\n");
|
||||
await rename(firstPath + ".tmp", firstPath);
|
||||
console.log(`build-codes: ${codes.length} current codes`);
|
||||
}
|
||||
if (import.meta.main) await buildCodes();
|
||||
@@ -47,10 +47,10 @@
|
||||
import { appendFile } from "node:fs/promises";
|
||||
import {
|
||||
ADAPTERS,
|
||||
adapterById,
|
||||
} from "../src/ingest/adapters/index.ts";
|
||||
import { SIX_HOURS_MS } from "../src/ingest/adapters/types.ts";
|
||||
import type { Adapter } from "../src/ingest/adapters/types.ts";
|
||||
import { CODE_SOURCES, type RefreshSource } from "../src/ingest/codes/registry.ts";
|
||||
const REFRESH_SOURCES: readonly RefreshSource[] = [...ADAPTERS, ...CODE_SOURCES];
|
||||
import { RobotsCache, type FetchLike } from "../src/ingest/robots.ts";
|
||||
import { decodeBody, SnapshotStore } from "../src/ingest/snapshots.ts";
|
||||
|
||||
@@ -129,7 +129,7 @@ export interface RobotsGate {
|
||||
}
|
||||
|
||||
export interface RefreshOptions {
|
||||
adapters: readonly Adapter[];
|
||||
adapters: readonly RefreshSource[];
|
||||
store: SnapshotStore;
|
||||
robots: RobotsGate;
|
||||
fetchImpl: FetchLike;
|
||||
@@ -335,7 +335,7 @@ export async function runRefresh(
|
||||
}
|
||||
|
||||
async function refreshOne(
|
||||
adapter: Adapter,
|
||||
adapter: RefreshSource,
|
||||
options: RefreshOptions,
|
||||
cycle: Cycle,
|
||||
): Promise<SourceOutcome> {
|
||||
@@ -715,6 +715,8 @@ export async function rebuildFeedViaScript(): Promise<void> {
|
||||
});
|
||||
const code = await proc.exited;
|
||||
if (code !== 0) throw new Error(`build-feed exited ${code}`);
|
||||
const codes = Bun.spawn(["bun", "run", "scripts/build-codes.ts"], { stdout: "inherit", stderr: "inherit" });
|
||||
if (await codes.exited !== 0) throw new Error("build-codes failed");
|
||||
}
|
||||
|
||||
/** Whether a person authorised this run, and who, for the override gates. */
|
||||
@@ -847,7 +849,7 @@ const USAGE = `usage: bun run refresh [--dry-run] [--only <sourceId>] [--snapsho
|
||||
[--force]
|
||||
|
||||
--dry-run report what each source would do; no requests, no writes
|
||||
--only <id> refresh a single source (${ADAPTERS.map((a) => a.id).join(", ")})
|
||||
--only <id> refresh a single source (${REFRESH_SOURCES.map((a) => a.id).join(", ")})
|
||||
--snapshots snapshot cache directory (default: snapshots, env SNAPSHOT_DIR)
|
||||
--user-agent override the User-Agent (env REFRESH_USER_AGENT)
|
||||
--no-feed skip regenerating public/data/events.v1.json
|
||||
@@ -878,7 +880,7 @@ async function main(): Promise<number> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (args.only !== null && adapterById(args.only) === undefined) {
|
||||
if (args.only !== null && !REFRESH_SOURCES.some(source => source.id === args.only)) {
|
||||
console.error(`unknown source '${args.only}'`);
|
||||
console.error(USAGE);
|
||||
return 2;
|
||||
@@ -939,7 +941,7 @@ async function main(): Promise<number> {
|
||||
});
|
||||
|
||||
if (args.force) {
|
||||
const n = args.only === null ? ADAPTERS.length : 1;
|
||||
const n = args.only === null ? REFRESH_SOURCES.length : 1;
|
||||
console.warn(
|
||||
` ! --force: ignoring the 6h floor for ${n} source${n === 1 ? "" : "s"}. ` +
|
||||
`Conditional headers still apply, so an unchanged page costs a 304.`,
|
||||
@@ -955,14 +957,14 @@ async function main(): Promise<number> {
|
||||
}
|
||||
|
||||
console.log(
|
||||
`refresh: ${args.only ?? `${ADAPTERS.length} sources`}${args.dryRun ? " (dry run)" : ""}`,
|
||||
`refresh: ${args.only ?? `${REFRESH_SOURCES.length} sources`}${args.dryRun ? " (dry run)" : ""}`,
|
||||
);
|
||||
console.log(` user-agent: ${args.userAgent}`);
|
||||
console.log(` snapshots: ${args.root}`);
|
||||
console.log(` interval: ${SIX_HOURS_MS / 3_600_000}h minimum per source\n`);
|
||||
|
||||
const summary = await runRefresh({
|
||||
adapters: ADAPTERS,
|
||||
adapters: REFRESH_SOURCES,
|
||||
store,
|
||||
robots,
|
||||
fetchImpl: (input, init) => fetch(input, init),
|
||||
|
||||
Reference in New Issue
Block a user