From 2e152965dfb1b74e5f1ed8c399f1a212bd94ac5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sat, 12 Oct 2024 10:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9C=AA=E5=8D=B3=E6=97=B6=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/User/Characters.vue | 19 ++++++---- src/web/request/TGRequest.ts | 5 +-- src/web/request/getAvatarDetail.ts | 58 ++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/pages/User/Characters.vue b/src/pages/User/Characters.vue index 4bf9427b..ddfb8061 100644 --- a/src/pages/User/Characters.vue +++ b/src/pages/User/Characters.vue @@ -280,11 +280,14 @@ async function refresh(): Promise { loadData.value = false; return; } - const cookie = { - account_id: userStore.cookie.value.account_id, - cookie_token: userStore.cookie.value.cookie_token, - }; - const listRes = await TGRequest.User.byCookie.getAvatarList(cookie, user.value.gameUid); + const indexRes = await TGRequest.User.byCookie.getAvatarIndex(userStore.cookie.value, user.value); + if (indexRes.retcode !== 0) { + showSnackbar({ text: `[${indexRes.retcode}] ${indexRes.message}` }); + loading.value = false; + loadData.value = false; + return; + } + const listRes = await TGRequest.User.byCookie.getAvatarList(userStore.cookie.value, user.value); if (!Array.isArray(listRes)) { showSnackbar({ text: `[${listRes.retcode}] ${listRes.message}`, color: "error" }); await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色列表失败`); @@ -298,7 +301,11 @@ async function refresh(): Promise { const idList = listRes.map((i) => i.id.toString()); loadingTitle.value = "正在获取角色数据"; loadingSub.value = `共${idList.length}个角色`; - const res = await TGRequest.User.byCookie.getAvatarDetail(cookie, user.value.gameUid, idList); + const res = await TGRequest.User.byCookie.getAvatarDetail( + userStore.cookie.value, + user.value, + idList, + ); if ("retcode" in res) { showSnackbar({ text: `[${res.retcode}] ${res.message}`, color: "error" }); await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色数据失败`); diff --git a/src/web/request/TGRequest.ts b/src/web/request/TGRequest.ts index c1005c86..e84a8225 100644 --- a/src/web/request/TGRequest.ts +++ b/src/web/request/TGRequest.ts @@ -1,7 +1,7 @@ /** * @file web/request/TGRequest.ts * @description 应用用到的请求函数 - * @since Beta v0.6.0 + * @since Beta v0.6.1 */ import { genAuthkey, genAuthkey2 } from "./genAuthkey.js"; @@ -9,7 +9,7 @@ import { getAbyss } from "./getAbyss.js"; import { getActionTicketBySToken } from "./getActionTicket.js"; import { getAnnoContent, getAnnoList } from "./getAnno.js"; import getAuthTicket from "./getAuthTicket.js"; -import { getAvatarList, getAvatarDetail } from "./getAvatarDetail.js"; +import { getAvatarList, getAvatarDetail, getAvatarIndex } from "./getAvatarDetail.js"; import getCode from "./getCode.js"; import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js"; import { getDeviceFp } from "./getDeviceFp.js"; @@ -44,6 +44,7 @@ const TGRequest = { getAbyss, getAccounts: getGameAccountsByCookie, getUserInfo: getUserInfoByCookie, + getAvatarIndex, getAvatarList, getAvatarDetail, }, diff --git a/src/web/request/getAvatarDetail.ts b/src/web/request/getAvatarDetail.ts index 37815546..181a26f1 100644 --- a/src/web/request/getAvatarDetail.ts +++ b/src/web/request/getAvatarDetail.ts @@ -1,27 +1,50 @@ /** * @file web/request/getAvatarDetail.ts * @description 获取角色详情相关请求函数 - * @since Beta v0.5.3 + * @since Beta v0.6.1 */ import TGHttp from "../../utils/TGHttp.js"; import TGApi from "../api/TGApi.js"; import TGUtils from "../utils/TGUtils.js"; +/** + * @description 手动刷新角色数据 + * @since Beta v0.6.1 + * @param {TGApp.App.Account.Cookie} cookie Cookie + * @param {TGApp.Sqlite.Account.Game} user 用户 + * @returns {Promise} + */ +export async function getAvatarIndex( + cookie: TGApp.App.Account.Cookie, + user: TGApp.Sqlite.Account.Game, +): Promise { + const url = TGApi.GameData.getUserBase; + const params = { avatar_list_type: 1, role_id: user.gameUid, server: user.region }; + const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id }; + const header = TGUtils.User.getHeader(ck, "GET", params, "common"); + return await TGHttp(url, { + method: "GET", + headers: header, + query: params, + }); +} + /** * @description 获取角色列表 - * @since Beta v0.5.3 - * @param {Record} cookie Cookie - * @param {string} roleId 用户 uid + * @since Beta v0.6.1 + * @param {TGApp.App.Account.Cookie} cookie Cookie + * @param {TGApp.Sqlite.Account.Game} user 用户 * @return {Promise} */ export async function getAvatarList( - cookie: Record, - roleId: string, + cookie: TGApp.App.Account.Cookie, + user: TGApp.Sqlite.Account.Game, ): Promise { const url = TGApi.GameData.byCookie.getAvatarList; - const data = { role_id: roleId, server: TGUtils.Tools.getServerByUid(roleId) }; - const header = TGUtils.User.getHeader(cookie, "POST", data, "common"); + const data = { role_id: user.gameUid, server: user.region }; + const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id }; + const header = TGUtils.User.getHeader(ck, "POST", data, "common"); const resp = await TGHttp(url, { method: "POST", body: JSON.stringify(data), @@ -33,24 +56,21 @@ export async function getAvatarList( /** * @description 获取角色详情 - * @since Beta v0.5.3 - * @param {Record} cookie Cookie - * @param {string} roleId 用户 uid + * @since Beta v0.6.1 + * @param {TGApp.App.Account.Cookie} cookie Cookie + * @param {TGApp.Sqlite.Account.Game} user 用户 * @param {string[]} avatarIds 角色 id 列表 * @return {Promise} */ export async function getAvatarDetail( - cookie: Record, - roleId: string, + cookie: TGApp.App.Account.Cookie, + user: TGApp.Sqlite.Account.Game, avatarIds: string[], ): Promise { const url = TGApi.GameData.byCookie.getAvatarDetail; - const data = { - role_id: roleId, - server: TGUtils.Tools.getServerByUid(roleId), - character_ids: avatarIds, - }; - const header = TGUtils.User.getHeader(cookie, "POST", data, "common"); + const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds }; + const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id }; + const header = TGUtils.User.getHeader(ck, "POST", data, "common"); const resp = await TGHttp(url, { method: "POST", body: JSON.stringify(data),