feat: replace ky with better-fetch for API requests

This commit is contained in:
HorizonCode 2025-07-02 11:44:05 +02:00
parent 2034016ac7
commit 1b1914f684
4 changed files with 27 additions and 33 deletions

View File

@ -4,6 +4,7 @@
"": {
"name": "ezpplauncher",
"dependencies": {
"@better-fetch/fetch": "^1.1.18",
"@elron/svelte-audio-store": "1.0.0",
"@number-flow/svelte": "^0.3.9",
"@tailwindcss/typography": "0.5.16",
@ -16,7 +17,6 @@
"buffer": "^6.0.3",
"crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"ky": "1.8.1",
"lucide-svelte": "0.523.0",
"osu-classes": "3.1.0",
"osu-parsers": "4.1.7",
@ -56,6 +56,8 @@
"@ampproject/remapping": ["@ampproject/remapping@2.3.0", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw=="],
"@better-fetch/fetch": ["@better-fetch/fetch@1.1.18", "", {}, "sha512-rEFOE1MYIsBmoMJtQbl32PGHHXuG2hDxvEd7rUHE0vCBoFQVSDqaVs9hkZEtHCxRoY+CljXKFCOuJ8uxqw1LcA=="],
"@bufbuild/protobuf": ["@bufbuild/protobuf@2.5.2", "", {}, "sha512-foZ7qr0IsUBjzWIq+SuBLfdQCpJ1j8cTuNNT4owngTHoN5KsJb8L9t65fzz7SCeSWzescoOil/0ldqiL041ABg=="],
"@elron/svelte-audio-store": ["@elron/svelte-audio-store@1.0.0", "", { "peerDependencies": { "svelte": "^4.0.0" } }, "sha512-ksBF88rG4cbIt+ZLrxMKDdr1CxWxxEiyyZfHfNHCF/G9O2eDflSnCytSpid0Y43R4DwK+AukUlFfc0j5evqqEw=="],
@ -382,8 +384,6 @@
"kleur": ["kleur@4.1.5", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="],
"ky": ["ky@1.8.1", "", {}, "sha512-7Bp3TpsE+L+TARSnnDpk3xg8Idi8RwSLdj6CMbNWoOARIrGrbuLGusV0dYwbZOm4bB3jHNxSw8Wk/ByDqJEnDw=="],
"lilconfig": ["lilconfig@3.1.3", "", {}, "sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw=="],
"lines-and-columns": ["lines-and-columns@1.2.4", "", {}, "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg=="],

View File

@ -16,6 +16,7 @@
},
"license": "MIT",
"dependencies": {
"@better-fetch/fetch": "^1.1.18",
"@elron/svelte-audio-store": "1.0.0",
"@number-flow/svelte": "^0.3.9",
"@tailwindcss/typography": "0.5.16",
@ -28,7 +29,6 @@
"buffer": "^6.0.3",
"crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"ky": "1.8.1",
"lucide-svelte": "0.523.0",
"osu-classes": "3.1.0",
"osu-parsers": "4.1.7",

View File

@ -1,4 +1,5 @@
import ky from 'ky';
import type { EZPPUser } from '@/types';
import { betterFetch } from '@better-fetch/fetch';
const BANCHO_ENDPOINT = 'https://c.ez-pp.farm/';
const ENDPOINT = 'https://ez-pp.farm/';
@ -7,8 +8,8 @@ export const ezppfarm = {
ping: async (): Promise<number | undefined> => {
try {
const start = Date.now();
const request = await ky(BANCHO_ENDPOINT);
if (!request.ok) return undefined;
const request = await betterFetch(BANCHO_ENDPOINT);
if (request.error) return undefined;
const ping = Date.now() - start;
return ping;
} catch {
@ -31,28 +32,23 @@ export const ezppfarm = {
}
| undefined
> => {
try {
const request = await ky(`${ENDPOINT}login/check`, {
method: 'POST',
body: JSON.stringify({ username, password }),
headers: {
'Content-Type': 'application/json',
'User-Agent': 'EZPPLauncher',
},
});
if (!request.ok) return undefined;
return await request.json<{
code: number;
message: string;
user?: {
id: number;
donor: boolean;
name: string;
email: string;
};
}>();
} catch {
return undefined;
}
const request = await betterFetch<{
code: number;
message: string;
user?: EZPPUser;
}>('https://ez-pp.farm/login/check', {
method: 'POST',
body: JSON.stringify({
username: username,
password: password,
}),
headers: {
'Content-Type': 'application/json',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
},
});
if (request.error) return undefined;
return request.data;
},
};

View File

@ -1,11 +1,9 @@
import ky from "ky";
const API_ENDPOINT = "https://osu.direct/api/";
export const osudirect = {
osu: async (mapId: number): Promise<string | undefined> => {
try {
return await ky(API_ENDPOINT + `osu/${mapId}?raw`).text();
return await (await fetch(API_ENDPOINT + `osu/${mapId}?raw`)).text();
} catch {
return undefined;
}