mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: archived season number
This commit is contained in:
1 parent
3f264d6a49
commit
90ee71c9ca
1 file changed
+24
-11
@@ -1,17 +1,28 @@
|
||||
import getRatingsInfo from '../blitz/getRatingsInfo';
|
||||
|
||||
interface GitHubTrees {
|
||||
tree: { path: string; url: string }[];
|
||||
}
|
||||
|
||||
let cachedLatestArchivedSeasonNumber: number | null = null;
|
||||
|
||||
export async function getArchivedLatestSeasonNumber() {
|
||||
if (cachedLatestArchivedSeasonNumber !== null) {
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
|
||||
const ratingsInfo = await getRatingsInfo('com');
|
||||
|
||||
if (ratingsInfo.detail) {
|
||||
const comURL = (
|
||||
const regionsURL = (
|
||||
(await fetch(
|
||||
'https://api.github.com/repos/tresabhi/blitzkrieg-assets/git/trees/main/regions',
|
||||
).then((response) => response.json())) as {
|
||||
tree: { path: string; url: string }[];
|
||||
}
|
||||
'https://api.github.com/repos/tresabhi/blitzkrieg-assets/git/trees/main',
|
||||
).then((response) => response.json())) as GitHubTrees
|
||||
).tree.find(({ path }) => path === 'regions')!.url;
|
||||
const comURL = (
|
||||
(await fetch(regionsURL).then((response) =>
|
||||
response.json(),
|
||||
)) as GitHubTrees
|
||||
).tree.find(({ path }) => path === 'com')!.url;
|
||||
const ratingsURL = (
|
||||
(await fetch(comURL).then((response) => response.json())) as {
|
||||
@@ -20,14 +31,16 @@ export async function getArchivedLatestSeasonNumber() {
|
||||
).tree[0].url;
|
||||
const latestSeason = Math.max(
|
||||
...(
|
||||
(await fetch(ratingsURL).then((response) => {
|
||||
response.json();
|
||||
})) as { tree: { path: string }[] }
|
||||
).tree.map(({ path }) => parseInt(path)),
|
||||
(await fetch(ratingsURL).then((response) => response.json())) as {
|
||||
tree: { path: string }[];
|
||||
}
|
||||
).tree.map(({ path }) => Number(path)),
|
||||
);
|
||||
|
||||
return latestSeason;
|
||||
cachedLatestArchivedSeasonNumber = latestSeason;
|
||||
} else {
|
||||
return ratingsInfo.current_season - 1;
|
||||
cachedLatestArchivedSeasonNumber = ratingsInfo.current_season - 1;
|
||||
}
|
||||
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
Reference in new issue
Block a user