1
0
Fork 0
taevas.xyz/backend/api/infos/gaming/osu.ts
Taevas d781f7138f
Make backend/frontend distinction clearer
Helps with eventually adding other pages
Also makes it clear it's the backend that decides what data to send to the frontend
2025-07-08 14:40:35 +02:00

32 linhas
861 B
TypeScript

import * as osuv2 from "osu-api-v2-js";
import type { Handler } from "../../index.ts";
import { tokens } from "../../../database.ts";
export type Info = {
country: string;
ranks: {
global: number;
country: number;
};
} | undefined;
const user_id = 7276846;
export const osu: Handler = async (params) => {
const token = await tokens.get("osu");
let ruleset = params.has("ruleset") ? Number(params.get("ruleset")) : undefined;
if (ruleset && isNaN(ruleset)) {ruleset = undefined;}
const api = new osuv2.API({access_token: token?.access_token});
const profile = await api.getUser(user_id, ruleset);
const info: Info = {
country: profile.country.name,
ranks: {
global: profile.statistics.global_rank ?? 0,
country: profile.statistics.country_rank ?? 0,
},
};
return Response.json(info, {status: 200});
};