下载祈愿数据

close #202
This commit is contained in:
BTMuli
2026-01-12 01:05:11 +08:00
parent 8d541891ae
commit 62052d126f
11 changed files with 258 additions and 37 deletions

View File

@@ -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;
}

View File

@@ -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;
}