mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +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 { NextResponse } from 'next/server';
|
||||||
import { Region } from '../../../../../../constants/regions';
|
import { Region } from '../../../../../../../constants/regions';
|
||||||
import { getArchivedRatingsLeaderboard } from '../../../../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
import { getArchivedRatingsLeaderboard } from '../../../../../../../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
FIRST_ARCHIVED_RATINGS_SEASON,
|
FIRST_ARCHIVED_RATINGS_SEASON,
|
||||||
getArchivedLatestSeasonNumberAPI,
|
getArchivedLatestSeasonNumberAPI,
|
||||||
} from '../../../core/blitzkrieg/getArchivedLatestSeasonNumberAPI';
|
} from '../../../core/blitzkrieg/getArchivedLatestSeasonNumberAPI';
|
||||||
|
import getArchivedRatingsInfoAPI from '../../../core/blitzkrieg/getArchivedRatingsInfoAPI';
|
||||||
import { useRatings } from '../../../stores/ratings';
|
import { useRatings } from '../../../stores/ratings';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
@@ -24,22 +25,19 @@ export default function Page() {
|
|||||||
// null being the latest season
|
// null being the latest season
|
||||||
const [season, setSeason] = useState<null | number>(null);
|
const [season, setSeason] = useState<null | number>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getArchivedLatestSeasonNumberAPI().then(setLatestArchivedSeasonNumber);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const [newRatingsInfo, newLatestArchivedSeasonNumber] = await Promise.all(
|
if (season === null) {
|
||||||
[getRatingsInfo(ratings.region), getArchivedLatestSeasonNumberAPI()],
|
setRatingsInfo(await getRatingsInfo(ratings.region));
|
||||||
);
|
} else {
|
||||||
|
setRatingsInfo(await getArchivedRatingsInfoAPI(ratings.region, season));
|
||||||
setRatingsInfo(newRatingsInfo);
|
}
|
||||||
setLatestArchivedSeasonNumber(newLatestArchivedSeasonNumber);
|
|
||||||
|
|
||||||
setSeason(
|
|
||||||
newRatingsInfo.detail == undefined
|
|
||||||
? null
|
|
||||||
: newLatestArchivedSeasonNumber,
|
|
||||||
);
|
|
||||||
})();
|
})();
|
||||||
}, [ratings.region]);
|
}, [season]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper>
|
<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