diff --git a/exporter/file.ts b/exporter/file.ts index 8a2ac70..1916db2 100644 --- a/exporter/file.ts +++ b/exporter/file.ts @@ -10,6 +10,15 @@ type FileExporterType = { data: VsBattle; }; +/** + * Don't save url in exported file + */ +function replacer(key: string, value: unknown): unknown { + return ["url", "maskImageUrl", "overlayImageUrl"].includes(key) + ? undefined + : value; +} + /** * Exporter to file. * @@ -26,6 +35,10 @@ export class FileExporter implements BattleExporter { fullId.slice(fullId.length - 52, fullId.length - 37), ); + if (!/\d{8}T\d{6}/.test(ts)) { + throw new Error("Invalid battle ID"); + } + return `${ts}Z.json`; } async exportBattle(battle: VsBattle) { @@ -42,7 +55,10 @@ export class FileExporter implements BattleExporter { data: battle, }; - await Deno.writeTextFile(filepath, JSON.stringify(body)); + await Deno.writeTextFile( + filepath, + JSON.stringify(body, replacer), + ); } async notExported(list: string[]): Promise { const out: string[] = [];