diff --git a/exporter/stat.ink.ts b/exporter/stat.ink.ts index 198cddd..dfc668e 100644 --- a/exporter/stat.ink.ts +++ b/exporter/stat.ink.ts @@ -70,7 +70,7 @@ export class StatInkExporter implements BattleExporter { }; } async exportBattle(detail: VsHistoryDetail) { - const body = this.mapBattle(detail); + const body = await this.mapBattle(detail); const resp = await fetch("https://stat.ink/api/v3/battle", { method: "POST", @@ -81,17 +81,18 @@ export class StatInkExporter implements BattleExporter { body: msgpack.encode(body), }); + const json: { + error?: unknown; + } = await resp.json().catch(() => ({})); + if (resp.status !== 200 && resp.status !== 201) { throw new APIError({ response: resp, message: "Failed to export battle", + json, }); } - const json: { - error?: unknown; - } = await resp.json(); - if (json.error) { throw new APIError({ response: resp, @@ -198,7 +199,6 @@ export class StatInkExporter implements BattleExporter { const startedAt = Math.floor(new Date(playedTime).getTime() / 1000); const result: StatInkPostBody = { - test: "yes", uuid: await battleId(vsDetail.id), lobby: this.mapLobby(vsDetail), rule: SPLATNET3_STATINK_MAP.RULE[vsDetail.vsRule.rule], @@ -218,7 +218,7 @@ export class StatInkExporter implements BattleExporter { agent: AGENT_NAME, agent_version: S3SI_VERSION, - agent_variables: {}, + agent_variables: undefined, automated: "yes", start_at: startedAt, end_at: startedAt + vsDetail.duration, @@ -231,6 +231,8 @@ export class StatInkExporter implements BattleExporter { result.kill_or_assist = self.result.kill; result.assist = self.result.assist; result.kill = result.kill_or_assist - result.assist; + result.death = self.result.death; + result.special = self.result.special; } if (mode === "FEST") { diff --git a/s3si.ts b/s3si.ts index 3400968..51e41df 100644 --- a/s3si.ts +++ b/s3si.ts @@ -272,12 +272,14 @@ Options: }); }; - onStep?.({ - current: exported, - total: workQueue.length, - }); - for (const battle of workQueue) { - await step(battle); + if (workQueue.length > 0) { + onStep?.({ + current: exported, + total: workQueue.length, + }); + for (const battle of workQueue) { + await step(battle); + } } return exported; diff --git a/scripts/delete.ts b/scripts/delete.ts new file mode 100644 index 0000000..bba793a --- /dev/null +++ b/scripts/delete.ts @@ -0,0 +1,20 @@ +import { USERAGENT } from "../constant.ts"; + +const [key, ...uuids] = Deno.args; +if (!key || uuids.length === 0) { + console.log("Usage: delete.ts "); + Deno.exit(1); +} + +for (const uuid of uuids) { + console.log("Deleting", uuid); + const resp = await fetch(`https://stat.ink/api/v3/battle/${uuid}`, { + method: "DELETE", + headers: { + "Authorization": `Bearer ${key}`, + "User-Agent": USERAGENT, + }, + }); + + console.log(resp.status); +} diff --git a/types.ts b/types.ts index 0cb0272..c82a573 100644 --- a/types.ts +++ b/types.ts @@ -196,7 +196,7 @@ export type StatInkStage = { }[]; export type StatInkPostBody = { - test: "yes" | "no"; + test?: "yes" | "no"; uuid: string; lobby: | "regular" @@ -254,7 +254,7 @@ export type StatInkPostBody = { agent: string; agent_version: string; - agent_variables: Record; + agent_variables?: Record; automated: "yes"; start_at: number; // the battle starts at e.g. 1599577200 end_at: number;