mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: website apis
This commit is contained in:
1 parent
3d9872a671
commit
3245284ecc
4 files changed
+65
-15
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { Region } from '../../../../../../../constants/regions';
|
||||
import getArchivedRatingsInfo from '../../../../../../../core/blitzkrieg/getArchivedRatingsInfo';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { region: Region; season: number } },
|
||||
) {
|
||||
return NextResponse.json(
|
||||
await getArchivedRatingsInfo(params.region, params.season),
|
||||
);
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { Region } from '../../../../../../constants/regions';
|
||||
import { getArchivedRatingsLeaderboard } from '../../../../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
||||
import { Region } from '../../../../../../../constants/regions';
|
||||
import { getArchivedRatingsLeaderboard } from '../../../../../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
FIRST_ARCHIVED_RATINGS_SEASON,
|
||||
getArchivedLatestSeasonNumberAPI,
|
||||
} from '../../../core/blitzkrieg/getArchivedLatestSeasonNumberAPI';
|
||||
import getArchivedRatingsInfoAPI from '../../../core/blitzkrieg/getArchivedRatingsInfoAPI';
|
||||
import { useRatings } from '../../../stores/ratings';
|
||||
|
||||
export default function Page() {
|
||||
@@ -24,22 +25,19 @@ export default function Page() {
|
||||
// null being the latest season
|
||||
const [season, setSeason] = useState<null | number>(null);
|
||||
|
||||
useEffect(() => {
|
||||
getArchivedLatestSeasonNumberAPI().then(setLatestArchivedSeasonNumber);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const [newRatingsInfo, newLatestArchivedSeasonNumber] = await Promise.all(
|
||||
[getRatingsInfo(ratings.region), getArchivedLatestSeasonNumberAPI()],
|
||||
);
|
||||
|
||||
setRatingsInfo(newRatingsInfo);
|
||||
setLatestArchivedSeasonNumber(newLatestArchivedSeasonNumber);
|
||||
|
||||
setSeason(
|
||||
newRatingsInfo.detail == undefined
|
||||
? null
|
||||
: newLatestArchivedSeasonNumber,
|
||||
);
|
||||
if (season === null) {
|
||||
setRatingsInfo(await getRatingsInfo(ratings.region));
|
||||
} else {
|
||||
setRatingsInfo(await getArchivedRatingsInfoAPI(ratings.region, season));
|
||||
}
|
||||
})();
|
||||
}, [ratings.region]);
|
||||
}, [season]);
|
||||
|
||||
return (
|
||||
<PageWrapper>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
|
||||
const INFO_CACHE: Record<
|
||||
Region,
|
||||
Record<
|
||||
number,
|
||||
RatingsInfo & {
|
||||
detail: undefined;
|
||||
}
|
||||
>
|
||||
> = {
|
||||
com: {},
|
||||
eu: {},
|
||||
asia: {},
|
||||
};
|
||||
|
||||
export default async function getArchivedRatingsInfoAPI(
|
||||
region: Region,
|
||||
season: number,
|
||||
) {
|
||||
if (INFO_CACHE[region][season]) {
|
||||
return INFO_CACHE[region][season];
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`/api/ratings/archives/${region}/${season}/info`,
|
||||
);
|
||||
const json = (await response.json()) as RatingsInfo;
|
||||
|
||||
if (json.detail) {
|
||||
throw new Error(
|
||||
`No ratings info found for season ${season}, region ${region}`,
|
||||
);
|
||||
}
|
||||
|
||||
INFO_CACHE[region][season] = json;
|
||||
|
||||
return json;
|
||||
}
|
||||
Reference in new issue
Block a user