fix: file notExported
parent
7a4962f161
commit
d4de5ede8b
1
deps.ts
1
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 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 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 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 { 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";
|
export { Mutex } from "https://deno.land/x/semaphore@v1.1.1/mod.ts";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { BattleExporter, VsBattle } from "../types.ts";
|
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";
|
import { NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts";
|
||||||
const FILENAME_FORMAT = "yyyyMMddHHmmss";
|
|
||||||
|
|
||||||
type FileExporterType = {
|
type FileExporterType = {
|
||||||
type: "VS" | "COOP";
|
type: "VS" | "COOP";
|
||||||
|
|
@ -15,17 +14,24 @@ type FileExporterType = {
|
||||||
* Exporter to file.
|
* Exporter to file.
|
||||||
*
|
*
|
||||||
* This is useful for debugging. It will write each battle detail to a 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<VsBattle> {
|
export class FileExporter implements BattleExporter<VsBattle> {
|
||||||
name = "file";
|
name = "file";
|
||||||
constructor(private exportPath: string) {
|
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) {
|
async exportBattle(battle: VsBattle) {
|
||||||
await Deno.mkdir(this.exportPath, { recursive: true });
|
await Deno.mkdir(this.exportPath, { recursive: true });
|
||||||
|
|
||||||
const playedTime = new Date(battle.detail.playedTime);
|
const filename = this.getFilenameById(battle.detail.id);
|
||||||
const filename = `${datetime.format(playedTime, FILENAME_FORMAT)}.json`;
|
|
||||||
const filepath = path.join(this.exportPath, filename);
|
const filepath = path.join(this.exportPath, filename);
|
||||||
|
|
||||||
const body: FileExporterType = {
|
const body: FileExporterType = {
|
||||||
|
|
@ -42,7 +48,7 @@ export class FileExporter implements BattleExporter<VsBattle> {
|
||||||
const out: string[] = [];
|
const out: string[] = [];
|
||||||
|
|
||||||
for (const id of list) {
|
for (const id of list) {
|
||||||
const filename = `${id}.json`;
|
const filename = this.getFilenameById(id);
|
||||||
const filepath = path.join(this.exportPath, filename);
|
const filepath = path.join(this.exportPath, filename);
|
||||||
const isFile = await Deno.stat(filepath).then((f) => f.isFile).catch(() =>
|
const isFile = await Deno.stat(filepath).then((f) => f.isFile).catch(() =>
|
||||||
false
|
false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue