mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-24 05:19:45 +08:00
@@ -30,17 +30,17 @@ async function fetchWeapon(): Promise<TGApp.Plugins.Hakushi.WeaponResp> {
|
||||
|
||||
/**
|
||||
* 转换数据
|
||||
* @since Beta v0.9.0
|
||||
* @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: "武器" });
|
||||
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: "角色" });
|
||||
res.push({ id: id.toString(), name: data.CHS, type: "角色", star: data.rank });
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { type ClientOptions, fetch } from "@tauri-apps/plugin-http";
|
||||
import JSONBig from "json-bigint";
|
||||
|
||||
import TGLogger from "./TGLogger.js";
|
||||
|
||||
@@ -22,6 +23,8 @@ type TGHttpParams = {
|
||||
body?: string;
|
||||
/** 是否是Blob */
|
||||
isBlob?: boolean;
|
||||
/** 是否有BigInt */
|
||||
hasBigInt?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +68,11 @@ async function TGHttp<T>(
|
||||
return await fetch(url, fetchOptions)
|
||||
.then(async (res) => {
|
||||
if (res.ok) {
|
||||
const data = options.isBlob ? await res.arrayBuffer() : await res.json();
|
||||
const data = options.isBlob
|
||||
? await res.arrayBuffer()
|
||||
: options.hasBigInt
|
||||
? JSONBig.parse(await res.text())
|
||||
: await res.json();
|
||||
if (fullResponse) return { data, resp: res };
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user