diff --git a/deps.ts b/deps.ts index 0b944a7..e57fe2c 100644 --- a/deps.ts +++ b/deps.ts @@ -9,6 +9,5 @@ export * as io from "https://deno.land/std@0.160.0/io/mod.ts"; export * as uuid from "https://deno.land/std@0.160.0/uuid/mod.ts"; export * as msgpack from "https://deno.land/x/msgpack@v1.4/mod.ts"; export * as path from "https://deno.land/std@0.160.0/path/mod.ts"; -export * as datetime from "https://deno.land/std@0.160.0/datetime/mod.ts"; export { MultiProgressBar } from "https://deno.land/x/progress@v1.2.8/mod.ts"; export { Mutex } from "https://deno.land/x/semaphore@v1.1.1/mod.ts"; diff --git a/exporter/file.ts b/exporter/file.ts index 6b55835..8a2ac70 100644 --- a/exporter/file.ts +++ b/exporter/file.ts @@ -1,7 +1,6 @@ import { BattleExporter, VsBattle } from "../types.ts"; -import { datetime, path } from "../deps.ts"; +import { base64, path } from "../deps.ts"; import { NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts"; -const FILENAME_FORMAT = "yyyyMMddHHmmss"; type FileExporterType = { type: "VS" | "COOP"; @@ -15,17 +14,24 @@ type FileExporterType = { * Exporter to file. * * This is useful for debugging. It will write each battle detail to a file. - * Timestamp is used as filename. Example: 2021-01-01T00:00:00.000Z.json + * Timestamp is used as filename. Example: 20210101T000000Z.json */ export class FileExporter implements BattleExporter { name = "file"; constructor(private exportPath: string) { } + getFilenameById(id: string) { + const fullId = base64.decode(id); + const ts = new TextDecoder().decode( + fullId.slice(fullId.length - 52, fullId.length - 37), + ); + + return `${ts}Z.json`; + } async exportBattle(battle: VsBattle) { await Deno.mkdir(this.exportPath, { recursive: true }); - const playedTime = new Date(battle.detail.playedTime); - const filename = `${datetime.format(playedTime, FILENAME_FORMAT)}.json`; + const filename = this.getFilenameById(battle.detail.id); const filepath = path.join(this.exportPath, filename); const body: FileExporterType = { @@ -42,7 +48,7 @@ export class FileExporter implements BattleExporter { const out: string[] = []; for (const id of list) { - const filename = `${id}.json`; + const filename = this.getFilenameById(id); const filepath = path.join(this.exportPath, filename); const isFile = await Deno.stat(filepath).then((f) => f.isFile).catch(() => false