FIX: Monster bar
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 1m38s
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 1m38s
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import useSocketStore from "@/stores/socketSettingStore";
|
||||
import { EnemyHakushiRawType, EnemyHakushiType } from "@/types";
|
||||
import { AvatarHakushiType, AvatarHakushiRawType } from "@/types/avatar";
|
||||
import axios from 'axios';
|
||||
|
||||
@@ -46,6 +47,29 @@ export async function getCharacterListApi(): Promise<AvatarHakushiType[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getEnemyListApi(): Promise<EnemyHakushiType[]> {
|
||||
try {
|
||||
const res = await axios.get<Record<string, EnemyHakushiRawType>>(
|
||||
'https://api.hakush.in/hsr/data/monster.json',
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const data = new Map(Object.entries(res.data));
|
||||
|
||||
return Array.from(data.entries()).map(([id, it]) => convertMonster(id, it));
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
console.log(`Error: ${error.response?.status} - ${error.message}`);
|
||||
} else {
|
||||
console.log(`Unexpected error: ${String(error)}`);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function convertAvatar(id: string, item: AvatarHakushiRawType): AvatarHakushiType {
|
||||
const lang = new Map<string, string>([
|
||||
@@ -66,5 +90,26 @@ function convertAvatar(id: string, item: AvatarHakushiRawType): AvatarHakushiTyp
|
||||
id: id
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function convertMonster(id: string, item: EnemyHakushiRawType): EnemyHakushiType {
|
||||
const lang = new Map<string, string>([
|
||||
['en', item.en],
|
||||
['kr', item.kr],
|
||||
['cn', item.cn],
|
||||
['jp', item.jp]
|
||||
]);
|
||||
const result: EnemyHakushiType = {
|
||||
id: id,
|
||||
rank: item.rank,
|
||||
camp: item.camp,
|
||||
icon: item.icon,
|
||||
child: item.child,
|
||||
weak: item.weak,
|
||||
desc: item.desc,
|
||||
lang: lang
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user