feat: use /api/v3/salmon/weapon (#31)

* feat: use /api/v3/salmon/weapon

https://github.com/fetus-hina/stat.ink/issues/1128#issuecomment-1328007235

* feat: remove hardcoded dict

* build: bump version
main
imspace 2022-11-26 21:12:23 +08:00 committed by GitHub
parent d6980c8208
commit d13d75d40a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 32 deletions

View File

@ -1,3 +1,7 @@
## 0.1.30
feat: use /api/v3/salmon/weapon
## 0.1.29
feat: add fail_reason for salmon run

View File

@ -1,7 +1,7 @@
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
export const AGENT_NAME = "s3si.ts";
export const S3SI_VERSION = "0.1.29";
export const S3SI_VERSION = "0.1.30";
export const NSOAPP_VERSION = "2.3.1";
export const WEB_VIEW_VERSION = "1.0.0-433ec0e8";
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";

View File

@ -1,19 +0,0 @@
const SOURCE = `
kuma_slosher 23900, grizzco_slosher Bär-Schwapper Grizzco Slosher Grizzco Slosher Derramatic Don Oso Derramatic Don Oso Seau M. Ours SA Seau M. Ours Cie Secchiostro Ursus Beer & Co-morser Ведроган «Потапыч Inc.» Grizzco Slosher
kuma_blaster 20900, grizzco_blaster Bär-Blaster Grizzco Blaster Grizzco Blaster Devastador Don Oso Lanzamotas Don Oso Blaster M. Ours SA Blasteur M. Ours Cie Blaster Ursus Beer & Co-blaster Бластер «Потапыч Inc.» Mr.
kuma_stringer 27900, grizzco_stringer Bär-Stringer Grizzco Stringer Grizzco Stringer Arcromatizador Don Oso Arcromatizador Don Oso Transperceur M. Ours SA Transperceur M. Ours Cie Calamarco Ursus Beer & Co-spanner Тетиватор «Потапыч Inc.» Mr.
kuma_charger 22900, grizzco_charger Bär-Konzentrator Grizzco Charger Grizzco Charger Cargatintas Don Oso Cargatintas Don Oso Fusil M. Ours SA Fusil M. Ours Cie Splatter Ursus Beer & Co-lader Сплатган «Потапыч Inc.» Grizzco Charger
kuma_shelter 26900, grizzco_brella Bär-Pluviator Grizzco Brella Grizzco Brella Paratintas Don Oso Paratintas Don Oso Para-encre M. Ours SA Para-encre M. Ours Cie Sparasole Ursus Beer & Co-plenzer Зонтган «Потапыч Inc.» Mr.
`;
export const KEY_DICT = new Map<string, string>();
for (const line of SOURCE.split(/\n/)) {
const [key, ...names] = line.split(/\t/);
for (let name of names) {
name = name.trim();
if (KEY_DICT.has(name) && KEY_DICT.get(name) !== key) {
console.log(`Conflict: ${name} => ${KEY_DICT.get(name)} and ${key}`);
}
KEY_DICT.set(name, key);
}
}

View File

@ -37,7 +37,6 @@ import {
urlSimplify,
} from "../utils.ts";
import { Env } from "../env.ts";
import { KEY_DICT } from "../dict/stat.ink.ts";
const COOP_POINT_MAP: Record<number, number | undefined> = {
0: -20,
@ -47,6 +46,7 @@ const COOP_POINT_MAP: Record<number, number | undefined> = {
};
class StatInkAPI {
statInk = "https://stat.ink";
FETCH_LOCK = new Mutex();
cache: Record<string, unknown> = {};
@ -67,8 +67,8 @@ class StatInkAPI {
const fetch = this.env.newFetcher();
return await (await fetch.get({
url: type === "VsInfo"
? "https://stat.ink/api/v3/s3s/uuid-list"
: "https://stat.ink/api/v3/salmon/uuid-list",
? `${this.statInk}/api/v3/s3s/uuid-list`
: `${this.statInk}/api/v3/salmon/uuid-list`,
headers: this.requestHeaders(),
})).json();
}
@ -76,7 +76,7 @@ class StatInkAPI {
async postBattle(body: StatInkPostBody) {
const fetch = this.env.newFetcher();
const resp = await fetch.post({
url: "https://stat.ink/api/v3/battle",
url: `${this.statInk}/api/v3/battle`,
headers: {
...this.requestHeaders(),
"Content-Type": "application/x-msgpack",
@ -108,7 +108,7 @@ class StatInkAPI {
async postCoop(body: StatInkCoopPostBody) {
const fetch = this.env.newFetcher();
const resp = await fetch.post({
url: "https://stat.ink/api/v3/salmon",
url: `${this.statInk}/api/v3/salmon`,
headers: {
...this.requestHeaders(),
"Content-Type": "application/x-msgpack",
@ -156,12 +156,16 @@ class StatInkAPI {
}
}
getSalmonWeapon = () =>
this._getCached<StatInkWeapon>(
`${this.statInk}/api/v3/salmon/weapon?full=1`,
);
getWeapon = () =>
this._getCached<StatInkWeapon>("https://stat.ink/api/v3/weapon?full=1");
this._getCached<StatInkWeapon>(`${this.statInk}/api/v3/weapon?full=1`);
getAbility = () =>
this._getCached<StatInkAbility>("https://stat.ink/api/v3/ability?full=1");
this._getCached<StatInkAbility>(`${this.statInk}/api/v3/ability?full=1`);
getStage = () =>
this._getCached<StatInkStage>("https://stat.ink/api/v3/stage");
this._getCached<StatInkStage>(`${this.statInk}/api/v3/stage`);
}
export type NameDict = {
@ -479,10 +483,9 @@ export class StatInkExporter implements GameExporter {
async mapCoopWeapon(
{ name, image }: { name: string; image: Image | null },
): Promise<string | null> {
const weaponMap = await this.api.getWeapon();
const weapon =
weaponMap.find((i) => Object.values(i.name).includes(name))?.key ??
KEY_DICT.get(name);
const weaponMap = await this.api.getSalmonWeapon();
const weapon = weaponMap.find((i) => Object.values(i.name).includes(name))
?.key;
if (!weapon) {
if (this.isRandomWeapon(image)) {