mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: public blitzkrieg-db
This commit is contained in:
1 parent
0b9db21c10
commit
dfe1e37592
7 files changed
+44
-130
No files matched your search
@@ -1,25 +1,33 @@
|
||||
import { DATABASE_REPO } from './getArchivedRatingsMidnightLeaderboard';
|
||||
import { octokit } from './octokit';
|
||||
import getRatingsInfo from '../blitz/getRatingsInfo';
|
||||
|
||||
let cachedLatestArchivedSeasonNumber: number | null = null;
|
||||
|
||||
export async function getArchivedLatestSeasonNumber() {
|
||||
if (cachedLatestArchivedSeasonNumber) {
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
const ratingsInfo = await getRatingsInfo('com');
|
||||
|
||||
if (ratingsInfo.detail) {
|
||||
const comURL = (
|
||||
(await fetch(
|
||||
'https://api.github.com/repos/tresabhi/blitzkrieg-db/git/trees/main',
|
||||
).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;
|
||||
}
|
||||
|
||||
const { data } = await octokit.repos.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: 'com/ratings',
|
||||
});
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error('Archived ratings data is malformed');
|
||||
}
|
||||
|
||||
cachedLatestArchivedSeasonNumber = Math.max(
|
||||
...data.map(({ name }) => parseInt(name)),
|
||||
);
|
||||
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
Reference in new issue
Block a user