/** * Build an optional asset pack by downloading the public images that the local * pages use into /asset-pack/, so the pages show official pictures without a network * connection. Run it on a machine that can reach the official sites; nothing is shipped with * the project, every player makes their own copy. * * node apps/server/src/asset-pack-cli.ts --data [--concurrency 6] * * Sources: official marketplace art and vehicle renders, plus store covers and screenshots. * The storefront links videos directly. * Files keep their host/path layout (static-ggc.gaijin.net/units/x.png); index.json lists them. * The pages read the pack first (web-ui/web/common.js `sourcesFor`). */ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { parseArgs } from 'node:util'; import { writeFileAtomic } from './storage/atomic-file.ts'; const MARKET_IMAGES = new URL('./web-ui/web/official-images.json', import.meta.url); const STORE_MEDIA = new URL('./web-ui/web/official-store-media.json', import.meta.url); async function main(): Promise { const { values } = parseArgs({ options: { data: { type: 'string' }, concurrency: { type: 'string', default: '6' } } }); if (!values.data) { console.error('usage: asset-pack-cli.ts --data [--concurrency 6]'); return 2; } const packDir = join(values.data, 'asset-pack'); const table = JSON.parse(readFileSync(MARKET_IMAGES, 'utf8')) as { base: string; byKey: Record }; const store = JSON.parse(readFileSync(STORE_MEDIA, 'utf8')) as { base: string; byProduct: Record; }; const urls = new Set(); for (const [key, path] of Object.entries(table.byKey)) { urls.add(table.base + path); if (path.startsWith('units/')) urls.add(`https://static.encyclopedia.warthunder.com/images/${key.toLowerCase()}.png`); } for (const { cover, screenshots = [] } of Object.values(store.byProduct)) { urls.add(store.base + cover); for (const screenshot of screenshots) urls.add(store.base + screenshot); } const indexFile = join(packDir, 'index.json'); const done = new Set(existsSync(indexFile) ? JSON.parse(readFileSync(indexFile, 'utf8')) as string[] : []); const queue = [...urls].filter((url) => !done.has(url.replace(/^https?:\/\//, ''))); let failed = 0; const worker = async (): Promise => { for (let url = queue.shift(); url; url = queue.shift()) { const relative = url.replace(/^https?:\/\//, ''); try { const response = await fetch(url, { signal: AbortSignal.timeout(15000) }); if (!response.ok || !response.headers.get('content-type')?.startsWith('image/')) { await response.body?.cancel(); failed += 1; continue; } writeFileAtomic(join(packDir, relative), Buffer.from(await response.arrayBuffer())); done.add(relative); } catch { failed += 1; } } }; await Promise.all(Array.from({ length: Math.max(1, Number(values.concurrency)) }, worker)); writeFileAtomic(indexFile, JSON.stringify([...done].sort())); console.log(`asset pack: ${done.size} file(s) in ${packDir}; ${failed} not available`); return 0; } process.exitCode = await main();