mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
Update get stats functions to use JSON endpoint.
This commit is contained in:
@@ -279,24 +279,24 @@ export async function getStats(
|
|||||||
];
|
];
|
||||||
const shouldGetFormattedRsn = options?.shouldGetFormattedRsn ?? true;
|
const shouldGetFormattedRsn = options?.shouldGetFormattedRsn ?? true;
|
||||||
|
|
||||||
const mainRes = await httpGet<string>(
|
const mainRes = await httpGet<HiscoresResponse>(
|
||||||
getStatsURL('main', rsn),
|
getStatsURL('main', rsn, true),
|
||||||
options?.axiosConfigs?.main
|
options?.axiosConfigs?.main
|
||||||
);
|
);
|
||||||
if (mainRes.status === 200) {
|
if (mainRes.status === 200) {
|
||||||
const emptyResponse: AxiosResponse<string> = {
|
const emptyResponse: AxiosResponse<HiscoresResponse> = {
|
||||||
status: 404,
|
status: 404,
|
||||||
data: '',
|
data: { skills: [], activities: [] },
|
||||||
statusText: '',
|
statusText: '',
|
||||||
headers: {},
|
headers: {},
|
||||||
config: {}
|
config: {}
|
||||||
};
|
};
|
||||||
const getModeStats = async (
|
const getModeStats = async (
|
||||||
mode: Extract<Gamemode, 'ironman' | 'hardcore' | 'ultimate'>
|
mode: Extract<Gamemode, 'ironman' | 'hardcore' | 'ultimate'>
|
||||||
): Promise<AxiosResponse<string>> =>
|
): Promise<AxiosResponse<HiscoresResponse>> =>
|
||||||
otherGamemodes.includes(mode)
|
otherGamemodes.includes(mode)
|
||||||
? httpGet<string>(
|
? httpGet<HiscoresResponse>(
|
||||||
getStatsURL(mode, rsn),
|
getStatsURL(mode, rsn, true),
|
||||||
options?.axiosConfigs?.[mode]
|
options?.axiosConfigs?.[mode]
|
||||||
).catch((err) => err)
|
).catch((err) => err)
|
||||||
: emptyResponse;
|
: emptyResponse;
|
||||||
@@ -313,16 +313,16 @@ export async function getStats(
|
|||||||
deulted: false,
|
deulted: false,
|
||||||
deironed: false
|
deironed: false
|
||||||
};
|
};
|
||||||
player.main = parseStats(mainRes.data);
|
player.main = parseJsonStats(mainRes.data);
|
||||||
|
|
||||||
const ironRes = await getModeStats('ironman');
|
const ironRes = await getModeStats('ironman');
|
||||||
if (ironRes.status === 200) {
|
if (ironRes.status === 200) {
|
||||||
player.ironman = parseStats(ironRes.data);
|
player.ironman = parseJsonStats(ironRes.data);
|
||||||
const hcRes = await getModeStats('hardcore');
|
const hcRes = await getModeStats('hardcore');
|
||||||
const ultRes = await getModeStats('ultimate');
|
const ultRes = await getModeStats('ultimate');
|
||||||
if (hcRes.status === 200) {
|
if (hcRes.status === 200) {
|
||||||
player.mode = 'hardcore';
|
player.mode = 'hardcore';
|
||||||
player.hardcore = parseStats(hcRes.data);
|
player.hardcore = parseJsonStats(hcRes.data);
|
||||||
if (
|
if (
|
||||||
player.ironman.skills.overall.xp !== player.hardcore.skills.overall.xp
|
player.ironman.skills.overall.xp !== player.hardcore.skills.overall.xp
|
||||||
) {
|
) {
|
||||||
@@ -337,7 +337,7 @@ export async function getStats(
|
|||||||
}
|
}
|
||||||
} else if (ultRes.status === 200) {
|
} else if (ultRes.status === 200) {
|
||||||
player.mode = 'ultimate';
|
player.mode = 'ultimate';
|
||||||
player.ultimate = parseStats(ultRes.data);
|
player.ultimate = parseJsonStats(ultRes.data);
|
||||||
if (
|
if (
|
||||||
player.ironman.skills.overall.xp !== player.ultimate.skills.overall.xp
|
player.ironman.skills.overall.xp !== player.ultimate.skills.overall.xp
|
||||||
) {
|
) {
|
||||||
@@ -383,11 +383,8 @@ export async function getStatsByGamemode(
|
|||||||
if (!GAMEMODES.includes(mode)) {
|
if (!GAMEMODES.includes(mode)) {
|
||||||
throw Error('Invalid game mode');
|
throw Error('Invalid game mode');
|
||||||
}
|
}
|
||||||
const response = await httpGet<string>(getStatsURL(mode, rsn), config);
|
const response = await getOfficialStats(rsn, mode, config);
|
||||||
if (response.status !== 200) {
|
const stats = parseJsonStats(response);
|
||||||
throw Error(PLAYER_NOT_FOUND_ERROR);
|
|
||||||
}
|
|
||||||
const stats = parseStats(response.data);
|
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user