mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
🌱 新v版角色列表&详情请求 #121
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
* @file web/request/TGRequest.ts
|
||||
* @description 应用用到的请求函数
|
||||
* @since Beta v0.5.0
|
||||
* @since Beta v0.5.3
|
||||
*/
|
||||
|
||||
import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
|
||||
import { getAbyss } from "./getAbyss.js";
|
||||
import { getActionTicketBySToken } from "./getActionTicket.js";
|
||||
import { getAnnoContent, getAnnoList } from "./getAnno.js";
|
||||
import { getAvatarList, getAvatarDetail } from "./getAvatarDetail.js";
|
||||
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js";
|
||||
import { getDeviceFp } from "./getDeviceFp.js";
|
||||
// import * from "./getEnkaData.ts";
|
||||
import { getGachaLog } from "./getGachaLog.js";
|
||||
import { getGameAccountsByCookie, getGameAccountsBySToken } from "./getGameAccounts.js";
|
||||
import { getGameRecord } from "./getGameRecord.js";
|
||||
@@ -41,6 +41,8 @@ const TGRequest = {
|
||||
getAbyss,
|
||||
getAccounts: getGameAccountsByCookie,
|
||||
getUserInfo: getUserInfoByCookie,
|
||||
getAvatarList,
|
||||
getAvatarDetail,
|
||||
},
|
||||
byLToken: {
|
||||
verify: verifyLToken,
|
||||
|
||||
69
src/web/request/getAvatarDetail.ts
Normal file
69
src/web/request/getAvatarDetail.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @file web/request/getAvatarDetail.ts
|
||||
* @description 获取角色详情相关请求函数
|
||||
* @since Beta v0.5.3
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取角色列表
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {string} uid 用户 uid
|
||||
* @return {Promise<TGApp.Game.Avatar.Avatar[]|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getAvatarList(
|
||||
cookie: Record<string, string>,
|
||||
uid: string,
|
||||
): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarList;
|
||||
const data = { uid, region: TGUtils.Tools.getServerByUid(uid) };
|
||||
const version = await app.getVersion();
|
||||
const header = {
|
||||
"User-Agent": `TeyvatGuide/${version}`,
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
||||
};
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
headers: header,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取角色详情
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {number} avatarId 角色 id
|
||||
* @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getAvatarDetail(
|
||||
cookie: Record<string, string>,
|
||||
uid: string,
|
||||
avatarId: number,
|
||||
): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarDetail;
|
||||
const params = { uid, region: TGUtils.Tools.getServerByUid(uid), avatar_id: avatarId };
|
||||
const version = await app.getVersion();
|
||||
const header = {
|
||||
"User-Agent": `TeyvatGuide/${version}`,
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
||||
};
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
headers: header,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// /**
|
||||
// * @file web request getEnkaData.ts
|
||||
// * @description 获取 ENKA 数据
|
||||
// * @author BTMuli<bt-muli@outlook.com>
|
||||
// * @since Alpha v0.1.3
|
||||
// */
|
||||
//
|
||||
// // Tauri
|
||||
// import { http } from "@tauri-apps/api";
|
||||
// // Tauri.App
|
||||
// import TGApi from "../api/TGApi";
|
||||
//
|
||||
// /**
|
||||
// * @description 获取 ENKA 数据
|
||||
// * @since Alpha v0.1.3
|
||||
// * @param {number} uid 用户 UID
|
||||
// * @returns {Promise<TGApp.Plugins.Enka>}
|
||||
// */
|
||||
// export async function getEnkaData (uid: number): Promise<BTMuli.App.Enka.Data> {
|
||||
// return await http.fetch<BTMuli.App.Enka.Data>(`${TGApi.GameEnka}${uid}`).then((res) => res.data);
|
||||
// }
|
||||
Reference in New Issue
Block a user