♻️ userStore 及 cookie 相关类型重构 #51

This commit is contained in:
BTMuli
2023-12-16 22:07:31 +08:00
parent 00386bc7ee
commit 4370bbaa57
16 changed files with 267 additions and 236 deletions

View File

@@ -145,11 +145,11 @@ async function checkUserLoad(): Promise<void> {
} else {
console.info("cookie 数据已加载!");
}
const infoLocal = userStore.briefInfo;
const infoLocal = userStore.getBriefInfo();
const appData = await TGSqlite.getAppData();
const infoDB = appData.find((item) => item.key === "userInfo")?.value;
if (infoDB === undefined && JSON.stringify(infoLocal) !== "{}") {
await TGSqlite.saveAppData("userInfo", JSON.stringify(infoLocal));
await userStore.saveBriefInfo();
} else if (infoDB !== undefined && infoLocal !== JSON.parse(infoDB)) {
userStore.setBriefInfo(JSON.parse(infoDB));
console.info("briefInfo 数据已更新!");

View File

@@ -171,18 +171,12 @@ const userStore = useUserStore();
const isDevEnv = ref<boolean>(import.meta.env.MODE === "development");
const userInfo = computed(() => {
if (appStore.isLogin) {
const info = userStore.getBriefInfo();
return {
nickname: info.nickname,
avatar: info.avatar,
};
} else {
return {
nickname: "未登录",
avatar: "/source/UI/defaultUser.webp",
};
}
const info = userStore.getBriefInfo();
if (info && info.nickname) return info;
return {
nickname: "未登录",
avatar: "/source/UI/defaultUser.webp",
};
});
const rail = ref(appStore.sidebar.collapse);
// theme

View File

@@ -21,7 +21,6 @@ import QrcodeVue from "qrcode.vue";
import { computed, reactive, ref, watch } from "vue";
import Mys from "../../plugins/Mys";
import TGSqlite from "../../plugins/Sqlite";
import { useUserStore } from "../../store/modules/user";
import TGRequest from "../../web/request/TGRequest";
import showSnackbar from "../func/snackbar";
@@ -48,7 +47,7 @@ const visible = computed({
const loading = ref<boolean>(false);
const qrCode = ref<string>("");
const ticket = ref<string>("");
const cookie = reactive<Record<string, string>>({
const cookie = reactive<TGApp.User.Account.Cookie>({
account_id: "",
ltuid: "",
stuid: "",
@@ -142,8 +141,7 @@ async function getTokens(): Promise<void> {
if (typeof cookieTokenRes === "string") cookie.cookie_token = cookieTokenRes;
const ltokenRes = await TGRequest.User.bySToken.getLToken(cookie.mid, cookie.stoken);
if (typeof ltokenRes === "string") cookie.ltoken = ltokenRes;
userStore.cookie = cookie;
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
await userStore.saveCookie(cookie);
}
</script>
<style lang="css" scoped>

View File

@@ -88,7 +88,7 @@ const loadingSub = ref<string>();
// data
const userTab = ref<number>(0);
const user = computed<TGApp.Sqlite.Account.Game>(() => userStore.getCurAccount());
const user = ref<TGApp.Sqlite.Account.Game>(userStore.getCurAccount());
const localAbyss = ref<TGApp.Sqlite.Abyss.SingleTable[]>([]);
const localAbyssID = ref<number[]>([]);
@@ -114,12 +114,19 @@ async function initAbyssData(): Promise<void> {
async function getAbyssData(): Promise<void> {
loadingTitle.value = "正在获取深渊数据";
loading.value = true;
const abyssCookie = userStore.getCookieGroup4();
const cookie: Record<string, string> = {
account_id: abyssCookie.account_id,
cookie_token: abyssCookie.cookie_token,
ltoken: abyssCookie.ltoken,
ltuid: abyssCookie.ltuid,
if (!userStore.cookie) {
showSnackbar({
text: "未登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
ltoken: userStore.cookie.ltoken,
ltuid: userStore.cookie.ltuid,
};
loadingTitle.value = "正在获取上期深渊数据";
const resP = await TGRequest.User.byCookie.getAbyss(cookie, "2", user.value);

View File

@@ -54,7 +54,7 @@
/>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { onMounted, ref } from "vue";
import DucDetailOverlay from "../../components/devCharacter/duc-detail-overlay.vue";
import showSnackbar from "../../components/func/snackbar";
@@ -78,7 +78,6 @@ const loadingSub = ref<string>();
// data
const isEmpty = ref(true);
const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
const roleCookie = computed(() => userStore.getCookieGroup4());
// overlay
const visible = ref(false);
@@ -134,7 +133,21 @@ async function loadRole(): Promise<void> {
async function refreshRoles(): Promise<void> {
loadingTitle.value = "正在获取角色数据";
loading.value = true;
const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user);
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
ltoken: userStore.cookie.ltoken,
ltuid: userStore.cookie.ltuid,
};
const res = await TGRequest.User.byLToken.getRoleList(cookie, user);
if (Array.isArray(res)) {
loadingTitle.value = "正在保存角色数据";
await TGSqlite.saveUserCharacter(user.gameUid, res);
@@ -153,12 +166,20 @@ async function refreshRoles(): Promise<void> {
async function refreshTalent(): Promise<void> {
loadingTitle.value = "正在获取天赋数据";
loading.value = true;
const talentCookie = userStore.getCookieGroup2();
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
for (const role of roleList.value) {
loadingTitle.value = `正在获取${role.name}的天赋数据`;
loadingSub.value = `CID${role.cid}`;
const res = await TGRequest.User.calculate.getSyncAvatarDetail(
talentCookie,
userStore.cookie.account_id,
userStore.cookie.cookie_token,
user.gameUid,
role.cid,
);

View File

@@ -119,6 +119,14 @@ async function confirmRefresh(): Promise<void> {
}
loadingTitle.value = "正在获取 authkey";
loading.value = true;
if (!userStore.cookie) {
showSnackbar({
color: "error",
text: "请先登录",
});
loading.value = false;
return;
}
const cookie = {
stoken: userStore.cookie.stoken,
mid: userStore.cookie.mid,

View File

@@ -32,7 +32,7 @@
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { onMounted, ref } from "vue";
import showSnackbar from "../../components/func/snackbar";
import TSubLine from "../../components/main/t-subline.vue";
@@ -58,7 +58,6 @@ const loadingSub = ref<string>();
// data
const isEmpty = ref<boolean>(true);
const recordData = ref<TGApp.Sqlite.Record.SingleTable>(<TGApp.Sqlite.Record.SingleTable>{});
const recordCookie = computed<TGApp.BBS.Constant.CookieGroup2>(() => userStore.getCookieGroup2());
onMounted(async () => {
loadingTitle.value = "正在加载战绩数据";
@@ -83,7 +82,19 @@ async function initUserRecordData(): Promise<void> {
async function refresh(): Promise<void> {
loadingTitle.value = "正在获取战绩数据";
loading.value = true;
const res = await TGRequest.User.getRecord(recordCookie.value, user);
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
};
const res = await TGRequest.User.getRecord(cookie, user);
if (!("retcode" in res)) {
console.log(res);
loadingTitle.value = "正在保存战绩数据";

View File

@@ -39,14 +39,14 @@
</template>
</v-list-item>
<v-list-item title="登录信息">
<v-list-item-subtitle v-show="userInfo.nickname !== '未登录'">
{{ userInfo.nickname }} uid:{{ userInfo.uid }}
<v-list-item-subtitle v-show="userInfo?.nickname !== '未登录'">
{{ userInfo?.nickname }} uid:{{ userInfo?.uid }}
</v-list-item-subtitle>
<v-list-item-subtitle v-show="userInfo.nickname === '未登录'">
<v-list-item-subtitle v-show="userInfo?.nickname === '未登录'">
未登录请扫码登录
</v-list-item-subtitle>
<template #prepend>
<img class="config-icon" :src="userInfo.avatar" alt="Login" />
<img class="config-icon" :src="userInfo?.avatar" alt="Login" />
</template>
<template #append>
<v-btn class="config-btn" @click="confirmScanLogin">扫码登录</v-btn>
@@ -202,15 +202,8 @@ const showReset = ref<boolean>(false);
// data
const showHome = ref<string[]>(homeStore.getShowValue());
const userInfo = computed(() => {
if (!appStore.isLogin) {
return {
nickname: "未登录",
uid: "-1",
desc: "请扫码登录",
avatar: "/source/UI/defaultUser.webp",
};
} else {
const info = userStore.getBriefInfo();
const info = userStore.getBriefInfo();
if (info && info.nickname) {
return {
nickname: info.nickname,
uid: info.uid,
@@ -218,6 +211,12 @@ const userInfo = computed(() => {
avatar: info.avatar,
};
}
return {
nickname: "未登录",
uid: "-1",
desc: "请扫码登录",
avatar: "/source/UI/defaultUser.webp",
};
});
const vuetifyTheme = computed(() => {
return appStore.theme === "dark" ? "dark" : "light";
@@ -280,6 +279,13 @@ async function confirmRefreshUser(): Promise<void> {
});
return;
}
if (!userStore.cookie) {
showSnackbar({
color: "error",
text: "请先登录",
});
return;
}
const ck = userStore.cookie;
if (JSON.stringify(ck) === "{}") {
showSnackbar({
@@ -322,7 +328,7 @@ async function confirmRefreshUser(): Promise<void> {
loadingTitle.value = "刷新失败!正在获取用户头像、昵称信息";
failCount++;
}
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
await userStore.saveCookie(ck);
const infoRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id);
if ("retcode" in infoRes) {
console.error(infoRes);
@@ -335,8 +341,7 @@ async function confirmRefreshUser(): Promise<void> {
avatar: infoRes.avatar_url,
desc: infoRes.introduce,
};
userStore.setBriefInfo(briefInfo);
await TGSqlite.saveAppData("userInfo", JSON.stringify(briefInfo));
await userStore.saveBriefInfo(briefInfo);
loadingTitle.value = "获取成功!正在获取用户游戏账号信息";
}
const accountRes = await TGRequest.User.byCookie.getAccounts(ck.cookie_token, ck.account_id);

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Sqlite/index.ts
* @description Sqlite 数据库操作类
* @since Beta v0.3.6
* @since Beta v0.3.8
*/
import { app } from "@tauri-apps/api";
@@ -103,10 +103,10 @@ class Sqlite {
/**
* @description 获取 cookie
* @since Beta v0.3.3
* @returns {Promise<Record<string, string>>}
* @since Beta v0.3.8
* @returns {Promise<TGApp.User.Account.Cookie>}
*/
public async getCookie(): Promise<Record<string, string>> {
public async getCookie(): Promise<TGApp.User.Account.Cookie> {
const db = await this.getDB();
const sql = "SELECT value FROM AppData WHERE key='cookie';";
const res: Array<{ value: string }> = await db.select(sql);

View File

@@ -1,87 +1,153 @@
/**
* @file store modules user.ts
* @description User store module
* @since Beta v0.3.0
* @file store/modules/user.ts
* @description 用户信息模块
* @since Beta v0.3.8
*/
import { defineStore } from "pinia";
import { ref } from "vue";
import TGSqlite from "../../plugins/Sqlite";
export const useUserStore = defineStore(
"user",
() => {
const briefInfo = ref<TGApp.App.Account.BriefInfo>({
nickname: "",
avatar: "",
uid: "",
desc: "",
});
const account = ref<TGApp.Sqlite.Account.Game>({
gameBiz: "",
gameUid: "",
isChosen: 0,
isOfficial: 0,
level: "",
nickname: "",
region: "",
regionName: "",
});
const cookie = ref<Record<string, string>>({});
const briefInfo = ref<TGApp.App.Account.BriefInfo>(loadBriefInfo());
const account = ref<TGApp.Sqlite.Account.Game>(loadAccount());
const cookie = ref<TGApp.User.Account.Cookie>();
function setBriefInfo(info: TGApp.App.Account.BriefInfo): void {
briefInfo.value = info;
/**
* @description 从本地加载用户信息
* @since Beta v0.3.8
* @function loadBriefInfo
* @memberof useUserStore
* @returns {TGApp.App.Account.BriefInfo}
*/
function loadBriefInfo(): TGApp.App.Account.BriefInfo {
const info = window.localStorage.getItem("briefInfo");
if (info !== null && info !== undefined) {
console.log(JSON.parse(info).briefInfo);
return JSON.parse(info).briefInfo;
}
return {
nickname: "",
avatar: "",
uid: "",
desc: "",
};
}
function getBriefInfo(): Record<string, string> {
/**
* @description 从本地加载当前用户信息
* @since Beta v0.3.8
* @function loadAccount
* @memberof useUserStore
* @returns {TGApp.Sqlite.Account.Game}
*/
function loadAccount(): TGApp.Sqlite.Account.Game {
const info = window.localStorage.getItem("account");
if (info !== null && info !== undefined) {
console.log(JSON.parse(info).account);
return JSON.parse(info).account;
}
return {
gameBiz: "",
gameUid: "",
isChosen: 0,
isOfficial: 0,
level: "",
nickname: "",
region: "",
regionName: "",
};
}
/**
* @description 获取用户信息
* @since Beta v0.3.8
* @function getBriefInfo
* @memberof useUserStore
* @returns {TGApp.App.Account.BriefInfo}
*/
function getBriefInfo(): TGApp.App.Account.BriefInfo {
return briefInfo.value;
}
function setCurAccount(user: TGApp.Sqlite.Account.Game): void {
account.value = user;
}
/**
* @description 获取当前用户信息
* @since Beta v0.3.8
* @function getCurAccount
* @memberof useUserStore
* @returns {TGApp.Sqlite.Account.Game}
*/
function getCurAccount(): TGApp.Sqlite.Account.Game {
return account.value;
}
function getCookieItem(key: string): string {
return cookie.value[key] || "";
/**
* @description 设置用户信息
* @param info
* @since Beta v0.3.8
* @function setBriefInfo
* @memberof useUserStore
* @param {TGApp.App.Account.BriefInfo} info - 用户信息
* @returns {void}
*/
function setBriefInfo(info: TGApp.App.Account.BriefInfo): void {
briefInfo.value = info;
}
function getCookieGroup2(): TGApp.BBS.Constant.CookieGroup2 {
return {
account_id: getCookieItem("account_id"),
cookie_token: getCookieItem("cookie_token"),
};
/**
* @description 设置当前用户信息
* @since Beta v0.3.8
* @function setCurAccount
* @memberof useUserStore
* @param {TGApp.Sqlite.Account.Game} user - 用户信息
* @returns {void}
*/
function setCurAccount(user: TGApp.Sqlite.Account.Game): void {
account.value = user;
}
function getCookieGroup3(): TGApp.BBS.Constant.CookieGroup3 {
return {
ltoken: getCookieItem("ltoken"),
ltuid: getCookieItem("ltuid"),
};
/**
* @description 保存cookie到本地
* @since Beta v0.3.8
* @function saveCookie
* @memberof useUserStore
* @param {TGApp.User.Account.Cookie} ck - cookie对象
* @returns {Promise<void>}
*/
async function saveCookie(ck?: TGApp.User.Account.Cookie): Promise<void> {
if (ck) {
cookie.value = ck;
}
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie.value));
}
function getCookieGroup4(): TGApp.BBS.Constant.CookieGroup4 {
return {
account_id: getCookieItem("account_id"),
cookie_token: getCookieItem("cookie_token"),
ltoken: getCookieItem("ltoken"),
ltuid: getCookieItem("ltuid"),
};
/**
* @description 保存用户信息到本地
* @since Beta v0.3.8
* @function saveBriefInfo
* @memberof useUserStore
* @param {TGApp.App.Account.BriefInfo} info - 用户信息
* @returns {Promise<void>}
*/
async function saveBriefInfo(info?: TGApp.App.Account.BriefInfo): Promise<void> {
if (info) {
setBriefInfo(info);
localStorage.setItem("briefInfo", JSON.stringify({ briefInfo: info }));
}
await TGSqlite.saveAppData("userInfo", JSON.stringify(briefInfo.value));
}
return {
briefInfo,
cookie,
account,
getBriefInfo,
setBriefInfo,
setCurAccount,
getCurAccount,
getCookieGroup2,
getCookieGroup3,
getCookieGroup4,
saveCookie,
saveBriefInfo,
};
},
{

View File

@@ -1,96 +0,0 @@
/**
* @file types/BBS/Constant.d.ts
* @description BBS 常量相关类型定义文件
* @since Alpha v0.1.6
*/
declare namespace TGApp.BBS.Constant {
/**
* @description 用户 Cookie 类型
* @interface Cookie
* @since Alpha v0.1.5
* @description 这边只写了需要的,其他的可以自行添加
* @description login_ticket 与 login_uid 一起使用
* @see TGRequest.User.byLoginTicket.getTokens
* @property {string} login_ticket 登录凭证
* @property {string} login_uid 登录 uid
* @description account_id 与 cookie_token 一起使用
* @see TGRequest.User.byCookie.getAccounts
* @property {string} account_id 账号 id
* @property {string} cookie_token cookie token
* @description ltoken 与 ltuid 一起使用
* @see TGRequest.User.byLToken.verify
* @property {string} ltoken ltoken
* @property {string} ltuid ltoken 对应的 uid
* @description stoken 与 stuid 一起使用,这是旧版本的 token
* @see TGRequest.User.bySToken.getCookieToken
* @property {string} stoken stoken
* @property {string} stuid stoken 对应的 uid
* @description stoken_v2 与 mid 一起使用,这是新版本的 token
* @see https://github.com/BTMuli/TeyvatGuide/issues/18
* @property {string} stoken_v2 stoken_v2
* @property {string} mid mid
* @return Cookie
*/
interface Cookie {
login_ticket: string;
login_uid: string;
account_id: string;
cookie_token: string;
ltoken: string;
ltuid: string;
mid: string;
stoken: string;
stuid: string;
stoken_v2?: string;
}
/**
* @description cookie 组合-1
* @interface CookieGroup1
* @since Alpha v0.1.6
* @property {string} login_ticket 登录凭证
* @property {string} login_uid 登录 uid
* @return CookieGroup1
*/
interface CookieGroup1 {
login_ticket: string;
login_uid: string;
}
/**
* @description cookie 组合-2
* @interface CookieGroup2
* @since Alpha v0.1.6
* @property {string} account_id 账号 id
* @property {string} cookie_token cookie token
* @return CookieGroup2
*/
interface CookieGroup2 {
account_id: string;
cookie_token: string;
}
/**
* @description cookie 组合-3
* @interface CookieGroup3
* @since Alpha v0.1.6
* @property {string} ltoken ltoken
* @property {string} ltuid ltoken 对应的 uid
* @return CookieGroup3
*/
interface CookieGroup3 {
ltoken: string;
ltuid: string;
}
/**
* @description cookie 组合-4
* @interface CookieGroup4
* @since Alpha v0.1.6
* @extends CookieGroup2
* @extends CookieGroup3
* @return CookieGroup4
*/
interface CookieGroup4 extends CookieGroup2, CookieGroup3 {}
}

View File

@@ -1,12 +1,12 @@
/**
* @file types/User/Account.d.ts
* @description 用户账号相关类型定义文件
* @since Alpha v0.1.5
* @since Beta v0.3.8
*/
/**
* @description 用户账号相关类型定义命名空间
* @since Alpha v0.1.5
* @since Beta v0.3.8
* @namespace TGApp.User.Account
* @memberof TGApp.User
*/
@@ -49,4 +49,29 @@ declare namespace TGApp.User.Account {
region: string;
region_name: string;
}
/**
* @description 用户 Cookie 类型
* @since Beta v0.3.8
* @interface Cookie
* @memberof TGApp.User.Account
* @property {string} account_id 账号 ID
* @property {string} cookie_token Cookie Token
* @property {string} game_token 游戏 Token
* @property {string} ltoken LToken
* @property {string} ltuid LTUID
* @property {string} mid MID
* @property {string} stoken SToken_v2
* @return Cookie
*/
interface Cookie {
account_id: string;
cookie_token: string;
game_token: string;
ltoken: string;
ltuid: string;
mid: string;
stoken: string;
stuid: string;
}
}

View File

@@ -334,7 +334,7 @@ class TGClient {
/**
* @func genAuthKey
* @since Beta v0.3.7
* @since Beta v0.3.8
* @desc 获取米游社客户端的 authkey
* @param {Record<string, string>} payload - 请求参数
* @param {string} callback - 回调函数名
@@ -342,6 +342,7 @@ class TGClient {
*/
async genAuthKey(payload: Record<string, string>, callback: string): Promise<void> {
const userStore = useUserStore();
if (!userStore.cookie) return;
const cookie = {
mid: userStore.cookie.mid,
stoken: userStore.cookie.stoken,
@@ -352,7 +353,7 @@ class TGClient {
/**
* @func getCookieInfo
* @since Beta v0.3.4
* @since Beta v0.3.8
* @desc 获取米游社客户端的 cookie
* @param {unknown} payload - 请求参数
* @param {string} callback - 回调函数名
@@ -360,6 +361,7 @@ class TGClient {
*/
async getCookieInfo(payload: unknown, callback: string): Promise<void> {
const user = useUserStore();
if (!user.cookie) return;
const data = {
ltoken: user.cookie.ltoken,
ltuid: user.cookie.ltuid,
@@ -382,6 +384,7 @@ class TGClient {
}
const ckPayload = <getCookieTokenPayload>payload;
const user = useUserStore();
if (!user.cookie) return;
if (ckPayload.forceRefresh) {
const res = await getCookieTokenBySToken(user.cookie.mid, user.cookie.stoken);
if (typeof res !== "string") {
@@ -405,7 +408,7 @@ class TGClient {
/**
* @func getActionTicket
* @since Beta v0.3.4
* @since Beta v0.3.8
* @desc 获取米游社客户端的 action_ticket\
* @param {unknown} payload - 请求参数
* @param {string} callback - 回调函数名
@@ -414,6 +417,7 @@ class TGClient {
async getActionTicket(payload: any, callback: string): Promise<void> {
const actionType = payload.action_type;
const user = useUserStore();
if (!user.cookie) return;
const uid = user.getCurAccount().gameUid;
const mid = user.cookie.mid;
const stoken = user.cookie.stoken;
@@ -477,13 +481,14 @@ class TGClient {
/**
* @func getUserInfo
* @since Beta v0.3.4
* @since Beta v0.3.8
* @desc 获取米游社客户端的用户信息
* @param {string} callback - 回调函数名
* @returns {void} - 无返回值
*/
async getUserInfo(callback: string): Promise<void> {
const user = useUserStore();
if (!user.cookie) return;
const cookieToken = user.cookie.cookie_token;
const accountId = user.cookie.account_id;
const userInfo = await TGRequest.User.byCookie.getUserInfo(cookieToken, accountId);

View File

@@ -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",

View File

@@ -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",

View File

@@ -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, {