Files
splatoon3.ink/app/screenshots/cli.mjs
Matt Isenhower 6df93806c2 Prepare the backend for Cloudflare Workers
Groundwork for running the existing updaters and social posters in a Worker:

- Derive IDs with @noble/hashes shake256; the Workers runtime's node:crypto
  lacks shake256. A test pins an ID produced by node:crypto.
- Split updaters into fast (schedules, gear, co-op, festivals, stages; run
  concurrently) and slow (X-Rank, Splatfest rankings; run one at a time).
  The cron posts after the fast updaters, before the slow ones.
- Fetch X-Rank seasons and detail types sequentially, cutting peak heap per
  division from ~85 MB to ~38 MB.
- Move Splatfest rankings into FestivalRankingsUpdater, driven by the
  published festivals data, so results never wait on ranking pagination.
- Coalesce concurrent downloads of the same SplatNet image.
- Bring over the Browser-binding screenshot work from develop (f7293b6):
  Cloudflare captures use the BROWSER binding with retries, Browserless is
  removed, and workers/screenshots offers capture-only local testing. The
  local driver keeps puppeteer-core with an installed Chrome, always serves
  dist/, and fails on page-reported screenshot errors.
- Remove the Docker image, compose files, and GHCR deploy workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 15:40:51 -08:00

42 lines
1.2 KiB
JavaScript

import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { parseArgs } from 'node:util';
import LocalScreenshotDriver from './drivers/LocalScreenshotDriver.mjs';
import { defaultScreenshotViewport } from '../../src/common/screenshot.mjs';
if (existsSync('.env')) {
process.loadEnvFile();
}
let driver = new LocalScreenshotDriver;
try {
let { values } = parseArgs({
options: {
route: { type: 'string', default: 'schedules' },
output: { type: 'string', default: 'dist/test-screenshots/capture.png' },
help: { type: 'boolean' },
},
});
if (values.help) {
console.log('Usage: npm run screenshot -- [--route schedules] [--output file.png]');
console.log('Captures the built site in dist/ with a local Chrome (set CHROME_PATH if it is not found).');
} else {
await driver.open();
let image = await driver.capture(values.route, defaultScreenshotViewport);
await mkdir(dirname(values.output), { recursive: true });
await writeFile(values.output, image);
console.log(`Saved screenshot to ${values.output}`);
}
} catch (error) {
console.error(error.message);
process.exitCode = 1;
} finally {
await driver.close();
}