Load an Info
's Website
separately from the Info
itself
Makes it so: - An `Info`'s `Website` doesn't need to wait for other `Website`s of that same `Info` to load to show up - An `Info`s `Website` not working won't prevent other `Website`s of that same `Info` from showing up - Code is more split and organized Furthermore, the token for the osu! API is now stored, and used for ALL osu! requests for 24 hours instead of being revoked Overall, it's a lot of future-proofing so things on working even if I'm no longer there to maintain them Also so `Info`s can be added, changed, and removed more easily
This commit is contained in:
parent
dec30acf14
commit
719672ffa0
45 changed files with 1125 additions and 759 deletions
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import fetch from "node-fetch";
|
||||
import {type AnilistInfo} from "../../src/components/Info/Anilist.js";
|
||||
import {type AnilistInfo} from "../../src/components/Info/Anime/Anilist.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const anilist = await fetch("https://graphql.anilist.co", {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {type GithubInfo} from "../../src/components/Info/Git.js";
|
||||
import {type GithubInfo} from "../../src/components/Info/Coding/GitHub.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const octokit = new Octokit({auth: process.env.API_GITHUB});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import fetch from "node-fetch";
|
||||
import {type GitlabInfo} from "../../src/components/Info/Git.js";
|
||||
import {type GitlabInfo} from "../../src/components/Info/Coding/GitLab.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const gitlab = await fetch("https://gitlab.com/api/v4/events?action=pushed", {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {api} from "./shared/api.js";
|
||||
import {type HacktheboxInfo} from "../../src/components/Info/Hackthebox.js";
|
||||
import {type HacktheboxInfo} from "../../src/components/Info/Hacking.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const hackthebox: {profile: {activity: HacktheboxInfo[]}} = await api<{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {api} from "./shared/api.js";
|
||||
import {type LastfmInfo} from "../../src/components/Info/Lastfm.js";
|
||||
import {type LastfmInfo} from "../../src/components/Info/Music/Lastfm.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const lastfm = await api<{
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import * as osu from "osu-api-v2-js";
|
||||
import {type OsuInfo} from "../../src/components/Info/Osu.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const api = await osu.API.createAsync({id: 11451, secret: process.env.API_OSU!});
|
||||
|
||||
const profile = await Promise.all([
|
||||
new Promise((resolve) => {
|
||||
resolve(api.getUser(7276846, osu.Ruleset.osu));
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
resolve(api.getUser(7276846, osu.Ruleset.taiko));
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
resolve(api.getUser(7276846, osu.Ruleset.fruits));
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
resolve(api.getUser(7276846, osu.Ruleset.mania));
|
||||
}),
|
||||
]) as osu.User.Extended[];
|
||||
|
||||
void api.revokeToken();
|
||||
|
||||
const info: OsuInfo = {
|
||||
country: (profile[0]).country.name ?? "Unknown",
|
||||
};
|
||||
|
||||
for (const ruleset of profile) {
|
||||
if (ruleset.rank_history) {
|
||||
const stats = ruleset.statistics;
|
||||
info[ruleset.rank_history.mode] = {
|
||||
global: stats.global_rank ?? 0,
|
||||
country: stats.country_rank ?? 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(info),
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
24
netlify/functions/osu_fruits.ts
Normal file
24
netlify/functions/osu_fruits.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import * as osu from "osu-api-v2-js";
|
||||
import {type FruitsInfo} from "../../src/components/Info/RhythmGames/OsuFruits.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const api = new osu.API({access_token: process.env["OSU_TOKEN"]});
|
||||
const profile = await api.getUser(7276846, osu.Ruleset.fruits);
|
||||
|
||||
const info: FruitsInfo = {
|
||||
country: profile.country.name,
|
||||
ranks: {
|
||||
global: profile.statistics.global_rank ?? 0,
|
||||
country: profile.statistics.country_rank ?? 0,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(info),
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
24
netlify/functions/osu_mania.ts
Normal file
24
netlify/functions/osu_mania.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import * as osu from "osu-api-v2-js";
|
||||
import {type ManiaInfo} from "../../src/components/Info/RhythmGames/OsuMania.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const api = new osu.API({access_token: process.env["OSU_TOKEN"]});
|
||||
const profile = await api.getUser(7276846, osu.Ruleset.mania);
|
||||
|
||||
const info: ManiaInfo = {
|
||||
country: profile.country.name,
|
||||
ranks: {
|
||||
global: profile.statistics.global_rank ?? 0,
|
||||
country: profile.statistics.country_rank ?? 0,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(info),
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
24
netlify/functions/osu_osu.ts
Normal file
24
netlify/functions/osu_osu.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import * as osu from "osu-api-v2-js";
|
||||
import {type OsuInfo} from "../../src/components/Info/RhythmGames/Osu.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const api = new osu.API({access_token: process.env["OSU_TOKEN"]});
|
||||
const profile = await api.getUser(7276846, osu.Ruleset.osu);
|
||||
|
||||
const info: OsuInfo = {
|
||||
country: profile.country.name,
|
||||
ranks: {
|
||||
global: profile.statistics.global_rank ?? 0,
|
||||
country: profile.statistics.country_rank ?? 0,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(info),
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
24
netlify/functions/osu_taiko.ts
Normal file
24
netlify/functions/osu_taiko.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import * as osu from "osu-api-v2-js";
|
||||
import {type TaikoInfo} from "../../src/components/Info/RhythmGames/OsuTaiko.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const api = new osu.API({access_token: process.env["OSU_TOKEN"]});
|
||||
const profile = await api.getUser(7276846, osu.Ruleset.taiko);
|
||||
|
||||
const info: TaikoInfo = {
|
||||
country: profile.country.name,
|
||||
ranks: {
|
||||
global: profile.statistics.global_rank ?? 0,
|
||||
country: profile.statistics.country_rank ?? 0,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(info),
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
31
netlify/functions/osu_token.ts
Normal file
31
netlify/functions/osu_token.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {API} from "osu-api-v2-js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
const [token, expiration] = [process.env["OSU_TOKEN"], process.env["OSU_TOKEN_EXPIRATION"]];
|
||||
let expired = false;
|
||||
|
||||
if (expiration) {
|
||||
try {
|
||||
expired = new Date(expiration) < new Date();
|
||||
} catch {
|
||||
expired = true;
|
||||
}
|
||||
} else {
|
||||
expired = true;
|
||||
}
|
||||
|
||||
if (!token || expired) {
|
||||
console.log("Setting a new token for osu!...");
|
||||
const api = await API.createAsync({id: 11451, secret: process.env.API_OSU!});
|
||||
process.env["OSU_TOKEN"] = api.access_token;
|
||||
process.env["OSU_TOKEN_EXPIRATION"] = api.expires.toISOString();
|
||||
console.log("Successfully set a new token for osu!");
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
};
|
||||
};
|
||||
|
||||
export {handler};
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {api} from "./shared/api.js";
|
||||
import {type SpeedruncomInfo} from "../../src/components/Info/Speedruncom.js";
|
||||
import {type SpeedruncomInfo} from "../../src/components/Info/Speedrunning/Speedruncom.js";
|
||||
|
||||
const handler: Handler = async () => {
|
||||
// using the API's embedding would be stupid here, as that'd create lag due to irrelevant runs
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {type Handler} from "@netlify/functions";
|
||||
import {api} from "./shared/api.js";
|
||||
import {type WanikaniInfo} from "../../src/components/Info/Wanikani.js";
|
||||
import {type WanikaniInfo} from "../../src/components/Info/Japanese/Wanikani.js";
|
||||
|
||||
type Subject = {
|
||||
id: number;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue