feat: reduce file exporter size

main
spacemeowx2 2022-10-21 15:56:43 +08:00
parent a210395975
commit dbc0985211
1 changed files with 17 additions and 1 deletions

View File

@ -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<VsBattle> {
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<VsBattle> {
data: battle,
};
await Deno.writeTextFile(filepath, JSON.stringify(body));
await Deno.writeTextFile(
filepath,
JSON.stringify(body, replacer),
);
}
async notExported(list: string[]): Promise<string[]> {
const out: string[] = [];