mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-02 06:45:08 +08:00
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/**
|
|
* Hakushi 插件入口
|
|
* @since Beta v0.9.0
|
|
*/
|
|
import TGHttp from "@utils/TGHttp.js";
|
|
|
|
const HAKUSHI_API = "https://api.hakush.in/gi/data/";
|
|
|
|
/**
|
|
* 请求角色数据
|
|
* @since Beta v0.9.0
|
|
* @returns 角色数据
|
|
*/
|
|
async function fetchAvatar(): Promise<TGApp.Plugins.Hakushi.AvatarResp> {
|
|
return await TGHttp<TGApp.Plugins.Hakushi.AvatarResp>(`${HAKUSHI_API}character.json`, {
|
|
method: "GET",
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 请求武器数据
|
|
* @since Beta v0.9.0
|
|
* @returns 武器数据
|
|
*/
|
|
async function fetchWeapon(): Promise<TGApp.Plugins.Hakushi.WeaponResp> {
|
|
return await TGHttp<TGApp.Plugins.Hakushi.WeaponResp>(`${HAKUSHI_API}weapon.json`, {
|
|
method: "GET",
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 转换数据
|
|
* @since Beta v0.9.1
|
|
*/
|
|
async function fetchJson(): Promise<Array<TGApp.Plugins.Hakushi.ConvertData>> {
|
|
const jsonW = await fetchWeapon();
|
|
const jsonA = await fetchAvatar();
|
|
const res: Array<TGApp.Plugins.Hakushi.ConvertData> = [];
|
|
for (const [id, data] of Object.entries(jsonW)) {
|
|
res.push({ id: id.toString(), name: data.CHS, type: "武器", star: data.rank });
|
|
}
|
|
for (const [id, data] of Object.entries(jsonA)) {
|
|
res.push({ id: id.toString(), name: data.CHS, type: "角色", star: data.rank });
|
|
}
|
|
return res;
|
|
}
|
|
|
|
const Hakushi = {
|
|
fetch: fetchJson,
|
|
};
|
|
|
|
export default Hakushi;
|