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_URL = "https://api.lp1.av5ja.srv.nintendo.net";
|
||||||
export const SPLATNET3_ENDPOINT =
|
export const SPLATNET3_ENDPOINT =
|
||||||
"https://api.lp1.av5ja.srv.nintendo.net/api/graphql";
|
"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 { DEFAULT_APP_USER_AGENT, SPLATNET3_ENDPOINT } from "./constant.ts";
|
||||||
import { APIError } from "./APIError.ts";
|
import { APIError } from "./APIError.ts";
|
||||||
import {
|
import {
|
||||||
BattleType,
|
BattleListType,
|
||||||
GraphQLResponse,
|
GraphQLResponse,
|
||||||
HistoryGroups,
|
HistoryGroups,
|
||||||
Queries,
|
Queries,
|
||||||
|
|
@ -85,34 +85,28 @@ function getIdsFromGroups({ historyGroups }: { historyGroups: HistoryGroups }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const BATTLE_LIST_TYPE_MAP: Record<
|
const BATTLE_LIST_TYPE_MAP: Record<
|
||||||
BattleType,
|
BattleListType,
|
||||||
(state: State) => Promise<string[]>
|
(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)
|
request(state, Queries.RegularBattleHistoriesQuery)
|
||||||
.then((r) => getIdsFromGroups(r.regularBattleHistories)),
|
.then((r) => getIdsFromGroups(r.regularBattleHistories)),
|
||||||
[BattleType.Bankara]: (state: State) =>
|
[BattleListType.Bankara]: (state: State) =>
|
||||||
request(state, Queries.BankaraBattleHistoriesQuery)
|
request(state, Queries.BankaraBattleHistoriesQuery)
|
||||||
.then((r) => getIdsFromGroups(r.bankaraBattleHistories)),
|
.then((r) => getIdsFromGroups(r.bankaraBattleHistories)),
|
||||||
[BattleType.Private]: (state: State) =>
|
[BattleListType.Private]: (state: State) =>
|
||||||
request(state, Queries.PrivateBattleHistoriesQuery)
|
request(state, Queries.PrivateBattleHistoriesQuery)
|
||||||
.then((r) => getIdsFromGroups(r.privateBattleHistories)),
|
.then((r) => getIdsFromGroups(r.privateBattleHistories)),
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getBattleList(
|
export async function getBattleList(
|
||||||
state: State,
|
state: State,
|
||||||
types: BattleType[] = [
|
battleListType: BattleListType = BattleListType.Latest,
|
||||||
BattleType.Regular,
|
|
||||||
BattleType.Bankara,
|
|
||||||
BattleType.Private,
|
|
||||||
],
|
|
||||||
) {
|
) {
|
||||||
const out = [];
|
return await BATTLE_LIST_TYPE_MAP[battleListType](state);
|
||||||
for (const battleType of types) {
|
|
||||||
const ids = await BATTLE_LIST_TYPE_MAP[battleType](state);
|
|
||||||
out.push(...ids);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBattleDetail(
|
export function getBattleDetail(
|
||||||
|
|
|
||||||
9
types.ts
9
types.ts
|
|
@ -56,7 +56,11 @@ export type RespMap = {
|
||||||
};
|
};
|
||||||
footerMessages: unknown[];
|
footerMessages: unknown[];
|
||||||
};
|
};
|
||||||
[Queries.LatestBattleHistoriesQuery]: Record<never, never>;
|
[Queries.LatestBattleHistoriesQuery]: {
|
||||||
|
latestBattleHistories: {
|
||||||
|
historyGroups: HistoryGroups;
|
||||||
|
};
|
||||||
|
};
|
||||||
[Queries.RegularBattleHistoriesQuery]: {
|
[Queries.RegularBattleHistoriesQuery]: {
|
||||||
regularBattleHistories: {
|
regularBattleHistories: {
|
||||||
historyGroups: HistoryGroups;
|
historyGroups: HistoryGroups;
|
||||||
|
|
@ -84,7 +88,8 @@ export type GraphQLResponse<T> = {
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum BattleType {
|
export enum BattleListType {
|
||||||
|
Latest,
|
||||||
Regular,
|
Regular,
|
||||||
Bankara,
|
Bankara,
|
||||||
Private,
|
Private,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue