Files
poli0981andClaude Opus 5.5 f2a5135993 v4.4.0: admin automation, bulk remove/edit, theme icon, smooth chart tabs (#133)
Admin: add games from any list or itch.io collection (Check first, batches of 200, per-game ingest tracking from scripts/state/ingest_outcomes.json), followed collections and auto-approve run by the cron in one [auto] commit, bulk remove/edit up to 100 games in one commit, New games, Activity and Settings pages. D1 migration 0002 (applied to production before this merge). Policies (ToS, Privacy, Disclaimer, EN + VI) cover approval by the maintainer's rules; LEGAL_VERSION 2026-10-13.

Web: the theme button shows the theme in use, no dark-mode flash (pre-paint script, hash in three CSPs), Charts tabs stay mounted (no rebuilt charts or replayed animations), 300 ms entrances, scrollbar gutter on mouse devices.

Release 4.4.0 (changelog also covers #130).

[skip-discuss]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 10:08:33 +07:00

39 lines
1.3 KiB
TypeScript

/** Splitting long lists into the API's batch sizes and sending them one after another. */
export function chunk<T>(items: readonly T[], size: number): T[][] {
const out: T[][] = []
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size))
return out
}
export interface BatchRun<T, R> {
results: R[]
/** The first batch that failed (nothing after it was sent), with its error. */
failed: { batch: T[]; error: unknown } | null
/** The batches not sent yet (the failed one first): retry by running them again. */
remaining: T[][]
}
/**
* Send `batches` one at a time (each is one commit / one request). Stops at the
* first error, so a lost session or a GitHub outage never leaves half a list
* silently skipped; the rest can be run again as it is.
*/
export async function runBatches<T, R>(
batches: T[][],
send: (batch: T[], index: number) => Promise<R>,
onProgress?: (done: number, total: number) => void,
): Promise<BatchRun<T, R>> {
const results: R[] = []
onProgress?.(0, batches.length)
for (let i = 0; i < batches.length; i++) {
try {
results.push(await send(batches[i], i))
} catch (error) {
return { results, failed: { batch: batches[i], error }, remaining: batches.slice(i) }
}
onProgress?.(i + 1, batches.length)
}
return { results, failed: null, remaining: [] }
}