mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
♻️ userStore 及 cookie 相关类型重构 #51
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file core/utils/getGameRecord.ts
|
||||
* @description 获取游戏数据的函数
|
||||
* @since Alpha v0.2.1
|
||||
* @since Beta v0.3.8
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
@@ -11,24 +11,20 @@ import TGUtils from "../utils/TGUtils";
|
||||
|
||||
/**
|
||||
* @description 获取用户游戏数据
|
||||
* @since Alpha v0.2.1
|
||||
* @since Beta v0.3.8
|
||||
* @description 这边的 ck 可以是 cookie_token 和 account_id
|
||||
* @description 也可以是 ltoken 和 ltuid
|
||||
* @param {TGApp.BBS.Constant.CookieGroup2} cookie cookie
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} user 用户的基本信息
|
||||
* @returns {Promise<TGApp.Game.Record.FullData|TGApp.BBS.Response.Base>} 用户基本信息
|
||||
*/
|
||||
export async function getGameRecord(
|
||||
cookie: TGApp.BBS.Constant.CookieGroup2,
|
||||
cookie: Record<string, string>,
|
||||
user: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.Game.Record.FullData | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.getUserBase;
|
||||
const ck: Record<string, string> = {
|
||||
account_id: cookie.account_id,
|
||||
cookie_token: cookie.cookie_token,
|
||||
};
|
||||
const params = { role_id: user.gameUid, server: user.region };
|
||||
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch<TGApp.Game.Record.Response | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/request/getRoleList.ts
|
||||
* @description 获取游戏角色列表的请求方法
|
||||
* @since Alpha v0.2.0
|
||||
* @since Beta v0.3.8
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
@@ -11,27 +11,20 @@ import TGUtils from "../utils/TGUtils";
|
||||
|
||||
/**
|
||||
* @description 通过 Cookie 获取用户角色列表
|
||||
* @since Alpha v0.2.0
|
||||
* @param {TGApp.BBS.Constant.CookieGroup4} cookie Cookie
|
||||
* @since Beta v0.3.8
|
||||
* @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: TGApp.BBS.Constant.CookieGroup4,
|
||||
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) };
|
||||
// 格式转换 将 cookie 对象转换 record<string, string>
|
||||
const ck: Record<string, string> = {
|
||||
account_id: cookie.account_id,
|
||||
cookie_token: cookie.cookie_token,
|
||||
ltuid: cookie.ltuid,
|
||||
ltoken: cookie.ltoken,
|
||||
};
|
||||
const header = TGUtils.User.getHeader(ck, "POST", JSON.stringify(data), "common");
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common");
|
||||
return await http
|
||||
.fetch<TGApp.Game.Character.ListResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/request/getSyncAvatarDetail.ts
|
||||
* @description 获取同步角色详情相关请求函数
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.3.8
|
||||
*/
|
||||
|
||||
import { app, http } from "@tauri-apps/api";
|
||||
@@ -11,14 +11,16 @@ import TGUtils from "../utils/TGUtils";
|
||||
|
||||
/**
|
||||
* @description 获取同步角色详情
|
||||
* @since Beta v0.3.4
|
||||
* @param {TGApp.BBS.Constant.CookieGroup2} cookie cookie
|
||||
* @since Beta v0.3.8
|
||||
* @param {string} accountId 账号 id
|
||||
* @param {string} cookieToken cookie token
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {number} avatarId 角色 id
|
||||
* @returns {Promise<TGApp.Game.Calculate.AvatarDetail|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getSyncAvatarDetail(
|
||||
cookie: TGApp.BBS.Constant.CookieGroup2,
|
||||
accountId: string,
|
||||
cookieToken: string,
|
||||
uid: string,
|
||||
avatarId: number,
|
||||
): Promise<TGApp.Game.Calculate.AvatarDetail | TGApp.BBS.Response.Base> {
|
||||
@@ -28,15 +30,11 @@ async function getSyncAvatarDetail(
|
||||
region: TGUtils.Tools.getServerByUid(uid),
|
||||
avatar_id: avatarId.toString(),
|
||||
};
|
||||
const ck: Record<string, string> = {
|
||||
account_id: cookie.account_id,
|
||||
cookie_token: cookie.cookie_token,
|
||||
};
|
||||
const version = await app.getVersion();
|
||||
const header = {
|
||||
"User-Agent": `TeyvatGuide/${version}`,
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(ck),
|
||||
Cookie: TGUtils.Tools.transCookie({ account_id: accountId, cookie_token: cookieToken }),
|
||||
};
|
||||
return await http
|
||||
.fetch<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>(url, {
|
||||
|
||||
Reference in New Issue
Block a user