mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-11-18 16:58:18 -06:00
Prepare the shared updater and social code to run against R2 in a Worker while keeping the local Node runner working: - Add app/common/storage with public, private, and archive areas keyed like the R2 objects. FilesystemStorage maps them onto dist/ and storage/ for Node; BucketStorage wraps R2 bindings. Storage is configured once per process; only image existence is cached, so JSON reads are always fresh. - Move ValueCache, DataUpdater (data, calendars, archive snapshots), ImageProcessor, LocalizationProcessor, festival updaters, status generators, social translations, ImageWriter, and Buffer/Threads image hosting onto storage. Query hashes are a JSON import. - Add app/splatnet/auth.mjs: the existing bullet-token code behind auth(), so the Worker can route token requests to per-region Durable Objects. warmCaches uses auth().refresh(). - Remove the S3/R2 sync, vfs, the dual upload, the sync commands, and s3-sync-client. Local runs no longer read from or write to remote buckets. - Give every test fresh in-memory storage via app/test/setup.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
import { fileURLToPath } from 'node:url';
|
|
import { configureFilesystemStorage } from '../common/storage/filesystem.mjs';
|
|
import { defaultStatusGenerators } from './index.mjs';
|
|
import FileWriter from './clients/FileWriter.mjs';
|
|
import ScreenshotHelper from '../screenshots/ScreenshotHelper.mjs';
|
|
|
|
export async function previewStatuses(locale = 'en-US', date, onlyGenerator) {
|
|
if (!['en-US', 'ja-JP'].includes(locale)) throw new Error('Preview locale must be en-US or ja-JP');
|
|
|
|
const now = date ? Date.parse(date) : null;
|
|
if (date && !Number.isFinite(now)) throw new Error('Preview date must be an ISO date and time');
|
|
|
|
const generators = defaultStatusGenerators({ locale, now });
|
|
if (onlyGenerator && !generators.some(g => g.key === onlyGenerator)) {
|
|
throw new Error(`Unknown generator: ${onlyGenerator}`);
|
|
}
|
|
|
|
const writer = new FileWriter({ dir: `temp/social-preview/${locale}` });
|
|
let failed = false;
|
|
let count = 0;
|
|
|
|
for (const generator of generators) {
|
|
if (onlyGenerator && generator.key !== onlyGenerator) continue;
|
|
const screenshots = new ScreenshotHelper({ provider: 'local' });
|
|
|
|
try {
|
|
if (!await generator.shouldPost({ key: 'preview' })) continue;
|
|
|
|
const status = await generator.getStatus(screenshots);
|
|
await writer.send(status, generator);
|
|
console.log(`Preview: ${writer.dir}/${generator.key}`);
|
|
count++;
|
|
} catch (error) {
|
|
console.error(`${generator.key}: ${error.message}`);
|
|
failed = true;
|
|
} finally {
|
|
await screenshots.close();
|
|
}
|
|
}
|
|
|
|
console.log(`Created ${count} previews. No posts sent or delivery markers written.`);
|
|
if (failed) throw new Error('Some previews failed; see the errors above');
|
|
}
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
configureFilesystemStorage();
|
|
previewStatuses(...process.argv.slice(2)).catch(error => {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
});
|
|
}
|