fix: stat.ink export
parent
bfdaa42f40
commit
5737f9da37
|
|
@ -70,7 +70,7 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async exportBattle(detail: 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", {
|
const resp = await fetch("https://stat.ink/api/v3/battle", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -81,17 +81,18 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
||||||
body: msgpack.encode(body),
|
body: msgpack.encode(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const json: {
|
||||||
|
error?: unknown;
|
||||||
|
} = await resp.json().catch(() => ({}));
|
||||||
|
|
||||||
if (resp.status !== 200 && resp.status !== 201) {
|
if (resp.status !== 200 && resp.status !== 201) {
|
||||||
throw new APIError({
|
throw new APIError({
|
||||||
response: resp,
|
response: resp,
|
||||||
message: "Failed to export battle",
|
message: "Failed to export battle",
|
||||||
|
json,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const json: {
|
|
||||||
error?: unknown;
|
|
||||||
} = await resp.json();
|
|
||||||
|
|
||||||
if (json.error) {
|
if (json.error) {
|
||||||
throw new APIError({
|
throw new APIError({
|
||||||
response: resp,
|
response: resp,
|
||||||
|
|
@ -198,7 +199,6 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
||||||
const startedAt = Math.floor(new Date(playedTime).getTime() / 1000);
|
const startedAt = Math.floor(new Date(playedTime).getTime() / 1000);
|
||||||
|
|
||||||
const result: StatInkPostBody = {
|
const result: StatInkPostBody = {
|
||||||
test: "yes",
|
|
||||||
uuid: await battleId(vsDetail.id),
|
uuid: await battleId(vsDetail.id),
|
||||||
lobby: this.mapLobby(vsDetail),
|
lobby: this.mapLobby(vsDetail),
|
||||||
rule: SPLATNET3_STATINK_MAP.RULE[vsDetail.vsRule.rule],
|
rule: SPLATNET3_STATINK_MAP.RULE[vsDetail.vsRule.rule],
|
||||||
|
|
@ -218,7 +218,7 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
||||||
|
|
||||||
agent: AGENT_NAME,
|
agent: AGENT_NAME,
|
||||||
agent_version: S3SI_VERSION,
|
agent_version: S3SI_VERSION,
|
||||||
agent_variables: {},
|
agent_variables: undefined,
|
||||||
automated: "yes",
|
automated: "yes",
|
||||||
start_at: startedAt,
|
start_at: startedAt,
|
||||||
end_at: startedAt + vsDetail.duration,
|
end_at: startedAt + vsDetail.duration,
|
||||||
|
|
@ -231,6 +231,8 @@ export class StatInkExporter implements BattleExporter<VsHistoryDetail> {
|
||||||
result.kill_or_assist = self.result.kill;
|
result.kill_or_assist = self.result.kill;
|
||||||
result.assist = self.result.assist;
|
result.assist = self.result.assist;
|
||||||
result.kill = result.kill_or_assist - result.assist;
|
result.kill = result.kill_or_assist - result.assist;
|
||||||
|
result.death = self.result.death;
|
||||||
|
result.special = self.result.special;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode === "FEST") {
|
if (mode === "FEST") {
|
||||||
|
|
|
||||||
14
s3si.ts
14
s3si.ts
|
|
@ -272,12 +272,14 @@ Options:
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onStep?.({
|
if (workQueue.length > 0) {
|
||||||
current: exported,
|
onStep?.({
|
||||||
total: workQueue.length,
|
current: exported,
|
||||||
});
|
total: workQueue.length,
|
||||||
for (const battle of workQueue) {
|
});
|
||||||
await step(battle);
|
for (const battle of workQueue) {
|
||||||
|
await step(battle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return exported;
|
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 = {
|
export type StatInkPostBody = {
|
||||||
test: "yes" | "no";
|
test?: "yes" | "no";
|
||||||
uuid: string;
|
uuid: string;
|
||||||
lobby:
|
lobby:
|
||||||
| "regular"
|
| "regular"
|
||||||
|
|
@ -254,7 +254,7 @@ export type StatInkPostBody = {
|
||||||
|
|
||||||
agent: string;
|
agent: string;
|
||||||
agent_version: string;
|
agent_version: string;
|
||||||
agent_variables: Record<string, string>;
|
agent_variables?: Record<string, string>;
|
||||||
automated: "yes";
|
automated: "yes";
|
||||||
start_at: number; // the battle starts at e.g. 1599577200
|
start_at: number; // the battle starts at e.g. 1599577200
|
||||||
end_at: number;
|
end_at: number;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue