From 7b43de7f9dcc73dd773d99957ac810d40e7d1a6c Mon Sep 17 00:00:00 2001 From: Taevas <67872932+TTTaevas@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:08:05 +0200 Subject: [PATCH] Update Beatmapset's `nominations_summary` & `WikiPage`'s `tags` I don't really understand what the data of `nominations_summary`'s `eligible_main_rulesets` actually mean so no documentation from me there The `tags` of a `WikiPage` could actually be numbers, the API server actually is the one that does this mistake, this wrapper fixes that --- lib/beatmapset.ts | 7 ++++++- lib/misc.ts | 22 +++++++++++++--------- lib/tests/test.ts | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/beatmapset.ts b/lib/beatmapset.ts index 54c7fc0..0f599d3 100644 --- a/lib/beatmapset.ts +++ b/lib/beatmapset.ts @@ -357,7 +357,12 @@ export namespace Beatmapset { legacy_thread_url: string nominations_summary: { current: number - required: number + eligible_main_rulesets: (keyof typeof Ruleset)[] | null + /** Required nominations */ + required_meta: { + main_ruleset: number + non_main_ruleset: number + } } ranked: RankStatus ranked_date: Date | null diff --git a/lib/misc.ts b/lib/misc.ts index 068f738..b0d7feb 100644 --- a/lib/misc.ts +++ b/lib/misc.ts @@ -108,11 +108,15 @@ export function adaptParametersForGETRequests(parameters: {[k: string]: any}): { * @param x Anything, but should be a string, an array that contains a string, or an object which has a string * @returns x, but with it (or what it contains) now having the correct type */ -export function correctType(x: any): any { +export function correctType(x: any, force_string?: boolean): any { + // those MUST be strings; turn the server's numbers into strings and keep the server's strings as strings const bannedProperties = [ - "name", "artist", "title", "location", "interests", "occupation", "twitter", - "discord", "version", "author", "raw", "bbcode", "title", "message", "creator", "source" + "name", "artist", "title", "tags", "username", "location", "interests", "occupation", "twitter", + "discord", "version", "display_version", "author", "raw", "bbcode", "title", "message", "creator", "source" ] + if (force_string && typeof x !== "object") { + return String(x) + } if (typeof x === "boolean") { return x @@ -121,17 +125,17 @@ export function correctType(x: any): any { if (/[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{2}:[0-9]{2}$/.test(x)) x = x.substring(0, x.indexOf("+")) + "Z" return new Date(x) } else if (Array.isArray(x)) { - return x.map((e) => correctType(e)) + return x.map((e) => correctType(e, force_string)) } else if (!isNaN(x) && x !== "") { return x === null ? null : Number(x) } else if (typeof x === "object" && x !== null) { - const k = Object.keys(x) - const v = Object.values(x) - for (let i = 0; i < k.length; i++) { - if (typeof v[i] === "string" && bannedProperties.some((p) => k[i].includes(p))) continue // don't turn names made of numbers into integers - x[k[i]] = correctType(v[i]) + const keys = Object.keys(x) + const vals = Object.values(x) + for (let i = 0; i < keys.length; i++) { + x[keys[i]] = correctType(vals[i], bannedProperties.some((p) => keys[i] === p)) } } + return x } diff --git a/lib/tests/test.ts b/lib/tests/test.ts index 493659c..581fefb 100644 --- a/lib/tests/test.ts +++ b/lib/tests/test.ts @@ -340,6 +340,7 @@ const testOther = async (): Promise => { const test = async (id: string, secret: string): Promise => { api = await osu.API.createAsync({id: Number(id), secret}, undefined, "all") //"http://127.0.0.1:8080") + api.timeout = 30 const tests = [ testBeatmapPack,