fix: stat.ink export
parent
bfdaa42f40
commit
5737f9da37
|
|
@ -70,7 +70,7 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
|||
};
|
||||
}
|
||||
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<VsHistoryDetail> {
|
|||
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<VsHistoryDetail> {
|
|||
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<VsHistoryDetail> {
|
|||
|
||||
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<VsHistoryDetail> {
|
|||
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") {
|
||||
|
|
|
|||
2
s3si.ts
2
s3si.ts
|
|
@ -272,6 +272,7 @@ Options:
|
|||
});
|
||||
};
|
||||
|
||||
if (workQueue.length > 0) {
|
||||
onStep?.({
|
||||
current: exported,
|
||||
total: workQueue.length,
|
||||
|
|
@ -279,6 +280,7 @@ Options:
|
|||
for (const battle of workQueue) {
|
||||
await step(battle);
|
||||
}
|
||||
}
|
||||
|
||||
return exported;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
import { USERAGENT } from "../constant.ts";
|
||||
|
||||
const [key, ...uuids] = Deno.args;
|
||||
if (!key || uuids.length === 0) {
|
||||
console.log("Usage: delete.ts <key> <uuid> <uuid...>");
|
||||
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);
|
||||
}
|
||||
4
types.ts
4
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<string, string>;
|
||||
agent_variables?: Record<string, string>;
|
||||
automated: "yes";
|
||||
start_at: number; // the battle starts at e.g. 1599577200
|
||||
end_at: number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue