🌱 初步完成角色天赋获取

This commit is contained in:
BTMuli
2023-06-28 11:01:45 +08:00
parent 97314d131b
commit c8963efc98
7 changed files with 296 additions and 11 deletions

View File

@@ -1,8 +1,8 @@
/**
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.6
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { getAbyss } from "./getAbyss";
@@ -13,6 +13,8 @@ import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccou
import { getGameRecord } from "./getGameRecord";
import { getLTokenBySToken } from "./getLToken";
import { getGameRoleListByLToken } from "./getRoleList";
import getSyncAvatarDetail from "./getSyncAvatarDetail";
import getSyncAvatarListAll from "./getSyncAvatarListAll";
// import * from "./getTickets.ts";
import { getTokensByLoginTicket } from "./getTokens";
import { getUserInfoByCookie } from "./getUserInfo";
@@ -45,6 +47,10 @@ const TGRequest = {
getCookieToken: getCookieTokenBySToken,
getLToken: getLTokenBySToken,
},
calculate: {
getSyncAvatarListAll,
getSyncAvatarDetail,
},
},
};

View File

@@ -0,0 +1,51 @@
/**
* @file web request getSyncAvatarDetail.ts
* @description 获取同步角色详情相关请求函数
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
// tauri
import { http } from "@tauri-apps/api";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
/**
* @description 获取同步角色详情
* @since Alpha v0.2.1
* @param {Record<string, string>} cookie cookie
* @param {string} uid 用户 uid
* @param {string} avatarId 角色 id
* @returns {Promise<TGApp.Game.Calculate.AvatarDetail|TGApp.BBS.Response.Base>}
*/
async function getSyncAvatarDetail(
cookie: Record<string, string>,
uid: string,
avatarId: string,
): Promise<TGApp.Game.Calculate.AvatarDetail | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.calculate.getSyncAvatarDetail;
const params = {
uid,
region: TGUtils.Tools.getServerByUid(uid),
avatar_id: avatarId,
};
const header = {
"User-Agent": "Tauri.Genshin/0.2.1",
Referer: "https://webstatic.mihoyo.com/",
Cookie: TGUtils.Tools.transCookie(cookie),
};
return await http
.fetch<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
if (res.data.retcode !== 0) return res.data as TGApp.BBS.Response.Base;
return res.data.data as TGApp.Game.Calculate.AvatarDetail;
});
}
export default getSyncAvatarDetail;

View File

@@ -0,0 +1,74 @@
/**
* @file web request getSyncAvatarListAll.ts
* @description 获取同步角色列表请求
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
// tauri
import { http } from "@tauri-apps/api";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
/**
* @description 获取同步角色列表请求
* @since Alpha v0.2.1
* @param {Record<string,string>} cookie cookie
* @param {string} uid 用户 uid
* @param {number} page 页码
* @return {Promise<TGApp.Game.Calculate.AvatarListItem[]|TGApp.BBS.Response.Base>}
*/
async function getSyncAvatarList(
cookie: Record<string, string>,
uid: string,
page: number,
): Promise<TGApp.Game.Calculate.AvatarListItem[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.calculate.getSyncAvatarList; // 获取同步角色列表请求地址
const data = {
uid,
region: TGUtils.Tools.getServerByUid(uid),
page,
};
const header = {
"User-Agent": "Tauri.Genshin/0.2.1",
Referer: "https://webstatic.mihoyo.com/",
Cookie: TGUtils.Tools.transCookie(cookie),
};
return await http
.fetch<TGApp.Game.Calculate.SyncAvatarListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: http.Body.json(data),
headers: header,
})
.then((res) => {
if (res.data.retcode !== 0) return res.data as TGApp.BBS.Response.Base;
return res.data.data.list as TGApp.Game.Calculate.AvatarListItem[];
});
}
/**
* @description 获取同步角色列表-汇总
* @since Alpha v0.2.1
* @param {Record<string,string>} cookie cookie
* @param {string} uid 用户 uid
* @return {Promise<TGApp.Game.Calculate.AvatarListItem[]|TGApp.BBS.Response.Base>}
*/
async function getSyncAvatarListAll(
cookie: Record<string, string>,
uid: string,
): Promise<TGApp.Game.Calculate.AvatarListItem[] | TGApp.BBS.Response.Base> {
let page = 1;
let res = await getSyncAvatarList(cookie, uid, page);
if (!Array.isArray(res)) return res;
let list: TGApp.Game.Calculate.AvatarListItem[] = [];
while (Array.isArray(res) && res.length > 0) {
list = list.concat(res);
page++;
res = await getSyncAvatarList(cookie, uid, page);
}
return list;
}
export default getSyncAvatarListAll;