feat: add latest battle history
parent
15c0e20966
commit
4d7b8ad33b
|
|
@ -8,3 +8,4 @@ export const DEFAULT_APP_USER_AGENT =
|
|||
export const SPLATNET3_URL = "https://api.lp1.av5ja.srv.nintendo.net";
|
||||
export const SPLATNET3_ENDPOINT =
|
||||
"https://api.lp1.av5ja.srv.nintendo.net/api/graphql";
|
||||
export const S3SI_NAMESPACE = "63941e1c-e32e-4b56-9a1d-f6fbe19ef6e1";
|
||||
|
|
|
|||
26
splatnet3.ts
26
splatnet3.ts
|
|
@ -3,7 +3,7 @@ import { State } from "./state.ts";
|
|||
import { DEFAULT_APP_USER_AGENT, SPLATNET3_ENDPOINT } from "./constant.ts";
|
||||
import { APIError } from "./APIError.ts";
|
||||
import {
|
||||
BattleType,
|
||||
BattleListType,
|
||||
GraphQLResponse,
|
||||
HistoryGroups,
|
||||
Queries,
|
||||
|
|
@ -85,34 +85,28 @@ function getIdsFromGroups({ historyGroups }: { historyGroups: HistoryGroups }) {
|
|||
}
|
||||
|
||||
const BATTLE_LIST_TYPE_MAP: Record<
|
||||
BattleType,
|
||||
BattleListType,
|
||||
(state: State) => Promise<string[]>
|
||||
> = {
|
||||
[BattleType.Regular]: (state: State) =>
|
||||
[BattleListType.Latest]: (state: State) =>
|
||||
request(state, Queries.LatestBattleHistoriesQuery)
|
||||
.then((r) => getIdsFromGroups(r.latestBattleHistories)),
|
||||
[BattleListType.Regular]: (state: State) =>
|
||||
request(state, Queries.RegularBattleHistoriesQuery)
|
||||
.then((r) => getIdsFromGroups(r.regularBattleHistories)),
|
||||
[BattleType.Bankara]: (state: State) =>
|
||||
[BattleListType.Bankara]: (state: State) =>
|
||||
request(state, Queries.BankaraBattleHistoriesQuery)
|
||||
.then((r) => getIdsFromGroups(r.bankaraBattleHistories)),
|
||||
[BattleType.Private]: (state: State) =>
|
||||
[BattleListType.Private]: (state: State) =>
|
||||
request(state, Queries.PrivateBattleHistoriesQuery)
|
||||
.then((r) => getIdsFromGroups(r.privateBattleHistories)),
|
||||
};
|
||||
|
||||
export async function getBattleList(
|
||||
state: State,
|
||||
types: BattleType[] = [
|
||||
BattleType.Regular,
|
||||
BattleType.Bankara,
|
||||
BattleType.Private,
|
||||
],
|
||||
battleListType: BattleListType = BattleListType.Latest,
|
||||
) {
|
||||
const out = [];
|
||||
for (const battleType of types) {
|
||||
const ids = await BATTLE_LIST_TYPE_MAP[battleType](state);
|
||||
out.push(...ids);
|
||||
}
|
||||
return out;
|
||||
return await BATTLE_LIST_TYPE_MAP[battleListType](state);
|
||||
}
|
||||
|
||||
export function getBattleDetail(
|
||||
|
|
|
|||
9
types.ts
9
types.ts
|
|
@ -56,7 +56,11 @@ export type RespMap = {
|
|||
};
|
||||
footerMessages: unknown[];
|
||||
};
|
||||
[Queries.LatestBattleHistoriesQuery]: Record<never, never>;
|
||||
[Queries.LatestBattleHistoriesQuery]: {
|
||||
latestBattleHistories: {
|
||||
historyGroups: HistoryGroups;
|
||||
};
|
||||
};
|
||||
[Queries.RegularBattleHistoriesQuery]: {
|
||||
regularBattleHistories: {
|
||||
historyGroups: HistoryGroups;
|
||||
|
|
@ -84,7 +88,8 @@ export type GraphQLResponse<T> = {
|
|||
}[];
|
||||
};
|
||||
|
||||
export enum BattleType {
|
||||
export enum BattleListType {
|
||||
Latest,
|
||||
Regular,
|
||||
Bankara,
|
||||
Private,
|
||||
|
|
|
|||
Loading…
Reference in New Issue