Helps with eventually adding other pages Also makes it clear it's the backend that decides what data to send to the frontend
32 linhas
861 B
TypeScript
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});
|
|
};
|