完成角色列表数据获取

This commit is contained in:
BTMuli
2023-05-23 23:59:20 +08:00
parent b8f7b73f05
commit 52a6f87ab0
5 changed files with 311 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
* @since Alpha v0.1.5
*/
import { getAbyss } from "./getAbyss";
@@ -11,7 +11,7 @@ import { getCookieTokenBySToken } from "./getCookieToken";
// import * from "./getEnkaData.ts";
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
import { getLTokenBySToken } from "./getLToken";
// import * from "./getRoleList.ts";
import { getGameRoleListByLToken } from "./getRoleList";
// import * from "./getTickets.ts";
import { getTokensByLoginTicket } from "./getTokens";
import { getUserInfoByCookie } from "./getUserInfo";
@@ -36,6 +36,7 @@ const TGRequest = {
},
byLToken: {
verify: verifyLToken,
getRoleList: getGameRoleListByLToken,
},
bySToken: {
getAccounts: getGameAccountsBySToken,

View File

@@ -0,0 +1,35 @@
/**
* @file web request getRoleList.ts
* @description 获取游戏角色列表的请求方法
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// utils
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
/**
* @description 通过 Cookie 获取用户角色列表
* @since Alpha v0.2.0
* @param {Record<string, string>} cookie Cookie
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
*/
export async function getGameRoleListByLToken (cookie: Record<string, string>, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getCharacter;
const uid = account.gameUid;
// eslint-disable-next-line camelcase
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common");
return await http.fetch<TGApp.Game.Character.ListResponse>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
}).then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.avatars;
});
}