Serve stock artwork and link official store media

Show the installed game artwork in the local store and marketplace. Use the official cover and gallery for each mapped product, with on-demand video playback. Include store cover images and screenshots in optional offline asset packs.

Verified TypeScript, browser script syntax, local service startup, game artwork endpoints, a sample image pack, and BMD-4M WebM byte-range delivery. In-game verification is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-26 17:18:32 +08:00
1 parent b15cece581
commit 64b11d56bf
14 files changed
+2580 -91

No files matched your search

+24 -13
View File
@@ -6,16 +6,18 @@
*
* node packages/local-service/src/asset-pack-cli.ts --data <data folder> [--concurrency 6]
*
* Sources: web-ui/web/official-images.json (official market images per vehicle / decor / item,
* from the official market snapshot) and the encyclopedia render of each of those vehicles.
* 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, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { parseArgs } from 'node:util';
import { writeFileAtomic } from './storage/atomic-file.ts';
const TABLE = new URL('./web-ui/web/official-images.json', import.meta.url);
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<number> {
const { values } = parseArgs({ options: { data: { type: 'string' }, concurrency: { type: 'string', default: '6' } } });
@@ -24,12 +26,20 @@ async function main(): Promise<number> {
return 2;
}
const packDir = join(values.data, 'asset-pack');
const table = JSON.parse(readFileSync(TABLE, 'utf8')) as { base: string; byKey: Record<string, string> };
const table = JSON.parse(readFileSync(MARKET_IMAGES, 'utf8')) as { base: string; byKey: Record<string, string> };
const store = JSON.parse(readFileSync(STORE_MEDIA, 'utf8')) as {
base: string;
byProduct: Record<string, { cover: string; screenshots?: string[] }>;
};
const urls = new Set<string>();
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<string>(existsSync(indexFile) ? JSON.parse(readFileSync(indexFile, 'utf8')) as string[] : []);
const queue = [...urls].filter((url) => !done.has(url.replace(/^https?:\/\//, '')));
@@ -38,11 +48,13 @@ async function main(): Promise<number> {
for (let url = queue.shift(); url; url = queue.shift()) {
const relative = url.replace(/^https?:\/\//, '');
try {
const response = await fetch(url);
if (!response.ok) { failed += 1; continue; }
const target = join(packDir, relative);
mkdirSync(dirname(target), { recursive: true });
writeFileSync(target, Buffer.from(await response.arrayBuffer()));
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;
@@ -50,8 +62,7 @@ async function main(): Promise<number> {
}
};
await Promise.all(Array.from({ length: Math.max(1, Number(values.concurrency)) }, worker));
mkdirSync(packDir, { recursive: true });
writeFileSync(indexFile, JSON.stringify([...done].sort(), null, 0));
writeFileAtomic(indexFile, JSON.stringify([...done].sort()));
console.log(`asset pack: ${done.size} file(s) in ${packDir}; ${failed} not available`);
return 0;
}