mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
34 lines
1006 B
TypeScript
34 lines
1006 B
TypeScript
import getRatingsInfo from '../blitz/getRatingsInfo';
|
|
|
|
let cachedLatestArchivedSeasonNumber: number | null = null;
|
|
|
|
export async function getArchivedLatestSeasonNumber() {
|
|
const ratingsInfo = await getRatingsInfo('com');
|
|
|
|
if (ratingsInfo.detail) {
|
|
const comURL = (
|
|
(await fetch(
|
|
'https://api.github.com/repos/tresabhi/blitzkrieg-assets/git/trees/main/regions',
|
|
).then((response) => response.json())) as {
|
|
tree: { path: string; url: string }[];
|
|
}
|
|
).tree.find(({ path }) => path === 'com')!.url;
|
|
const ratingsURL = (
|
|
(await fetch(comURL).then((response) => response.json())) as {
|
|
tree: [{ url: string }];
|
|
}
|
|
).tree[0].url;
|
|
const latestSeason = Math.max(
|
|
...(
|
|
(await fetch(ratingsURL).then((response) => {
|
|
response.json();
|
|
})) as { tree: { path: string }[] }
|
|
).tree.map(({ path }) => parseInt(path)),
|
|
);
|
|
|
|
return latestSeason;
|
|
} else {
|
|
return ratingsInfo.current_season - 1;
|
|
}
|
|
}
|