♻️ 迁移recordReq

This commit is contained in:
BTMuli
2026-04-14 21:46:52 +08:00
parent 6f6959d987
commit b09097dd3c
7 changed files with 285 additions and 185 deletions

View File

@@ -36,6 +36,7 @@ import recordReq from "@req/recordReq.js";
import TSUserAccount from "@Sqlm/userAccount.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref, watch } from "vue";
@@ -108,18 +109,20 @@ async function loadData(): Promise<void> {
loadingText.value = `正在加载 ${account.gameBiz} - ${account.regionName} - ${account.gameUid}...`;
loadingProgress.value = (i / genshinAccounts.length) * 100;
let data: TGApp.Game.DailyNote.DnRes | undefined;
let dataResp: TGApp.Game.DailyNote.DnResp | undefined;
try {
const dataResp = await recordReq.daily(cookie.value, account);
console.debug("dailyResp", account, dataResp);
dataResp = await recordReq.daily(cookie.value, account);
if (dataResp.retcode !== 0) {
await TGLogger.Error(
`[Daily Note Card] Failed to get daily note for ${account.gameBiz}: ${dataResp.message}`,
await TGLogger.Warn(
`[Daily Note Card] ${account.gameBiz}: [${dataResp.retcode}] ${dataResp.message}`,
);
} else data = dataResp.data;
} catch (error) {
await TGLogger.Error(
`[Daily Note Card] Error loading data for ${account.gameBiz}: ${error}`,
);
} else {
data = dataResp.data;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await TGLogger.Error(`[Daily Note Card] ${account.gameBiz}: ${errMsg}`);
await TGLogger.Error(`[Daily Note Card] ${e}`);
}
dailyNoteAccounts.value.push({ account, data });
}
@@ -140,24 +143,28 @@ async function handleUserSwitch(newUid: string): Promise<void> {
}
async function handleRefresh(account: TGApp.Sqlite.Account.Game): Promise<void> {
let dataResp: TGApp.Game.DailyNote.DnResp | undefined;
try {
const dataResp = await recordReq.daily(cookie.value!, account);
dataResp = await recordReq.daily(cookie.value!, account);
if (dataResp.retcode !== 0) {
await TGLogger.Error(`[Daily Note Card] Refresh failed: ${dataResp.message}`);
showSnackbar.error("刷新失败");
await TGLogger.Warn(`[Daily Note Card] [${dataResp.retcode}] ${dataResp.message}`);
showSnackbar.error(`刷新失败:[${dataResp.retcode}] ${dataResp.message}`);
return;
}
const item = dailyNoteAccounts.value.find(
(i) => i.account.gameUid === account.gameUid && i.account.gameBiz === account.gameBiz,
);
if (item) {
item.data = dataResp.data;
}
showSnackbar.success("刷新成功");
} catch (error) {
await TGLogger.Error(`[Daily Note Card] Refresh error: ${error}`);
showSnackbar.error("刷新失败");
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await TGLogger.Error(`[Daily Note Card] 刷新失败:${errMsg}`);
await TGLogger.Error(`[Daily Note Card] ${e}`);
showSnackbar.error(`刷新失败:${errMsg}`);
return;
}
const item = dailyNoteAccounts.value.find(
(i) => i.account.gameUid === account.gameUid && i.account.gameBiz === account.gameBiz,
);
if (item) {
item.data = dataResp.data;
}
showSnackbar.success("刷新成功");
}
</script>
<style lang="scss" scoped>

View File

@@ -156,8 +156,8 @@ function getType(type: number): string {
}
function getTimeStr(pool: TGApp.App.Gacha.PoolItem): string {
const startTime = timestampToDate(Date.parse(pool.from));
const endTime = timestampToDate(Date.parse(pool.to));
const startTime = timestampToDate(new Date(pool.from).getTime());
const endTime = timestampToDate(new Date(pool.to).getTime());
return `${startTime} ~ ${endTime}`;
}

View File

@@ -224,30 +224,48 @@ async function refreshAbyss(): Promise<void> {
const { account: rfAccount, cookie: rfCk } = refreshData;
await TGLogger.Info("[Abyss][refreshAbyss] 更新深渊数据");
await showLoading.start(`正在获取 ${rfAccount.gameUid} 的深渊数据`, "正在获取上期数据");
const resP = await recordReq.spiralAbyss(rfCk!, rfAccount, "2");
console.log(resP);
if ("retcode" in resP) {
let resP: TGApp.Game.Abyss.Response | undefined;
try {
resP = await recordReq.spiralAbyss(rfCk!, rfAccount, "2");
if (resP.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${resP.retcode}] ${resP.message}`);
await TGLogger.Warn(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}的上期深渊数据失败`);
await TGLogger.Warn(`[Abyss][refreshAbyss] ${resP.retcode} ${resP.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${resP.retcode}]${resP.message}`);
await TGLogger.Error(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}上期深渊数据失败`);
await TGLogger.Error(`[Abyss][refreshAbyss] ${resP.retcode} ${resP.message}`);
showSnackbar.error(`获取上期深渊数据失败:${errMsg}`);
await TGLogger.Error(`[Abyss][refreshAbyss] 获取上期深渊数据异常`);
await TGLogger.Error(`[Abyss][refreshAbyss] ${e}`);
return;
}
await TGLogger.Info("[Abyss][refreshAbyss] 成功获取上期深渊数据");
await showLoading.update("正在保存上期深渊数据");
await TSUserAbyss.saveAbyss(rfAccount.gameUid, resP);
await TSUserAbyss.saveAbyss(rfAccount.gameUid, resP.data);
await showLoading.update("正在获取本期深渊数据");
const res = await recordReq.spiralAbyss(rfCk!, rfAccount, "1");
console.log(res);
if ("retcode" in res) {
let res: TGApp.Game.Abyss.Response | undefined;
try {
res = await recordReq.spiralAbyss(rfCk!, rfAccount, "1");
if (res.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${res.retcode}] ${res.message}`);
await TGLogger.Warn(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}的本期深渊数据失败`);
await TGLogger.Warn(`[Abyss][refreshAbyss] ${res.retcode} ${res.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${res.retcode}]${res.message}`);
await TGLogger.Error(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}本期深渊数据失败`);
await TGLogger.Error(`[Abyss][refreshAbyss] ${res.retcode} ${res.message}`);
showSnackbar.error(`获取本期深渊数据失败:${errMsg}`);
await TGLogger.Error(`[Abyss][refreshAbyss] 获取本期深渊数据异常`);
await TGLogger.Error(`[Abyss][refreshAbyss] ${e}`);
return;
}
await showLoading.update("正在保存本期深渊数据");
await TSUserAbyss.saveAbyss(rfAccount.gameUid, res);
await TSUserAbyss.saveAbyss(rfAccount.gameUid, res.data);
await TGLogger.Info(`[Abyss][refreshAbyss] 成功获取${rfAccount.gameUid}的本期深渊数据`);
await showLoading.update("正在加载深渊数据");
await reloadUid(uidCur.value);
@@ -401,8 +419,8 @@ async function uploadAbyss(): Promise<void> {
const res = await Hutao.Abyss.upload(transAbyss);
if (res.retcode !== 0) {
showSnackbar.error(`[${res.retcode}]${res.message}`);
await TGLogger.Error("[Abyss][uploadAbyss] 上传深渊数据失败");
await TGLogger.Error(`[Abyss][uploadAbyss] ${res.retcode} ${res.message}`);
await TGLogger.Warn("[Abyss][uploadAbyss] 上传深渊数据失败");
await TGLogger.Warn(`[Abyss][uploadAbyss] ${res.retcode} ${res.message}`);
return;
}
showSnackbar.success(res.message ?? "上传深渊数据成功,即将刷新祈愿时长");
@@ -427,7 +445,6 @@ async function refreshAvatars(
ac: TGApp.Sqlite.Account.Game,
): Promise<boolean> {
await showLoading.update("正在更新角色数据");
// 更新战绩数据
let indexResp: TGApp.Game.Record.Resp | undefined;
try {
indexResp = await recordReq.index(ck, ac, 1);
@@ -441,32 +458,50 @@ async function refreshAvatars(
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取战绩数据异常: ${errMsg}`);
await TGLogger.Error(`[Record][refreshRecord] 获取战绩异常`);
await TGLogger.Error(`${e}`);
await TGLogger.Error(`[Abyss][refreshAvatars] 获取战绩异常`);
await TGLogger.Error(`[Abyss][refreshAvatars] ${e}`);
return false;
}
await showLoading.update("正在更新角色列表");
const listRes = await recordReq.character.list(ck, ac);
if ("retcode" in listRes) {
await showLoading.update("角色列表更新失败");
showSnackbar.error(`[${listRes.message}] ${listRes.message}`);
await TGLogger.Error(JSON.stringify(listRes));
await showLoading.end();
let listResp: TGApp.Game.Avatar.ListResp | undefined;
try {
listResp = await recordReq.character.list(ck, ac);
if (listResp.retcode !== 0) {
await showLoading.update("角色列表更新失败");
showSnackbar.error(`[${listResp.retcode}] ${listResp.message}`);
await TGLogger.Warn(`[Abyss][refreshAvatars] ${listResp.retcode} ${listResp.message}`);
await showLoading.end();
return false;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取角色列表异常: ${errMsg}`);
await TGLogger.Error(`[Abyss][refreshAvatars] 获取角色列表异常`);
await TGLogger.Error(`[Abyss][refreshAvatars] ${e}`);
return false;
}
const idList = listRes.map((i) => i.id.toString());
const idList = listResp.data.list.map((i) => i.id.toString());
await showLoading.update(`正在获取 ${idList.length} 个角色详情`);
const detailRes = await recordReq.character.detail(ck, ac, idList);
if ("retcode" in detailRes) {
await showLoading.update("角色详情获取失败");
showSnackbar.error(`[${detailRes.retcode}] ${detailRes.message}`);
await TGLogger.Error(JSON.stringify(detailRes));
await showLoading.end();
let detailResp: TGApp.Game.Avatar.DetailResp | undefined;
try {
detailResp = await recordReq.character.detail(ck, ac, idList);
if (detailResp.retcode !== 0) {
await showLoading.update("角色详情获取失败");
showSnackbar.error(`[${detailResp.retcode}] ${detailResp.message}`);
await TGLogger.Warn(`[Abyss][refreshAvatars] ${detailResp.retcode} ${detailResp.message}`);
await showLoading.end();
return false;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取角色详情异常: ${errMsg}`);
await TGLogger.Error(`[Abyss][refreshAvatars] 获取角色详情异常`);
await TGLogger.Error(`[Abyss][refreshAvatars] ${e}`);
return false;
}
propMap.value = detailRes.property_map;
propMap.value = detailResp.data.property_map;
await showLoading.update("正在保存角色数据");
await TSUserAvatar.saveAvatars(ac.gameUid, detailRes.list);
await TSUserAvatar.saveAvatars(ac.gameUid, detailResp.data.list);
return true;
}
</script>

View File

@@ -157,6 +157,7 @@ import { readTextFile } from "@tauri-apps/plugin-fs";
import { openUrl } from "@tauri-apps/plugin-opener";
import Hutao from "@Hutao/index.js";
import { getRfAc } from "@utils/acUtils.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { generateShareImg } from "@utils/TGShare.js";
import { storeToRefs } from "pinia";
@@ -266,16 +267,26 @@ async function refreshChallenge(): Promise<void> {
await TGLogger.Info("[Challenge][refreshChallenge] 开始刷新挑战数据");
await showLoading.start(`正在获取${rfAccount.gameUid}的幽境危战数据`);
isRefresh.value = true;
const resp = await recordReq.challenge.detail(rfCk!, rfAccount);
console.log(resp);
if ("retcode" in resp) {
let resp: TGApp.Game.Challenge.ChallengeResp | undefined;
try {
resp = await recordReq.challenge.detail(rfCk!, rfAccount);
if (resp.retcode !== 0) {
isRefresh.value = false;
await showLoading.end();
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Warn(`[Challenge][refreshChallenge] ${resp.retcode} - ${resp.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
isRefresh.value = false;
await showLoading.end();
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Error(`[Challenge][refreshChallenge] ${resp.retcode} - ${resp.message}`);
showSnackbar.error(`获取幽境危战数据失败:${errMsg}`);
await TGLogger.Error(`[Challenge][refreshChallenge] 获取幽境危战数据异常`);
await TGLogger.Error(`[Challenge][refreshChallenge] ${e}`);
return;
}
if (!resp.is_unlock) {
if (!resp.data.is_unlock) {
isRefresh.value = false;
await showLoading.end();
showSnackbar.warn("幽境危战未解锁");
@@ -283,7 +294,7 @@ async function refreshChallenge(): Promise<void> {
return;
}
await showLoading.update("", { title: "正在保存幽境危战数据" });
for (const challenge of resp.data) {
for (const challenge of resp.data.data) {
if (challenge.schedule.schedule_id === "0") continue;
await showLoading.update(`ScheduleID${challenge.schedule.schedule_id}`);
await TSUserChallenge.saveChallenge(rfAccount.gameUid, challenge);
@@ -321,14 +332,24 @@ async function refreshPopList(hint: boolean = true): Promise<void> {
`服务器: ${gameEnum.serverDesc(server.value)}`,
);
}
const resp = await recordReq.challenge.pop(server.value);
console.log("赋光之人列表", resp);
if (resp.retcode !== 0) {
let resp: TGApp.Game.Challenge.PopularityResp | undefined;
try {
resp = await recordReq.challenge.pop(server.value);
if (resp.retcode !== 0) {
reqPop.value = false;
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Warn(
`[UserChallenge][RefreshPopList] Error: ${resp.retcode} - ${resp.message}`,
);
await showLoading.end();
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
reqPop.value = false;
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Error(
`[UserChallenge][RefreshPopList] Error: ${resp.retcode} - ${resp.message}`,
);
showSnackbar.error(`获取赋光之人列表失败:${errMsg}`);
await TGLogger.Error(`[UserChallenge][RefreshPopList] 获取赋光之人列表异常`);
await TGLogger.Error(`[UserChallenge][RefreshPopList] ${e}`);
await showLoading.end();
return;
}

View File

@@ -421,16 +421,14 @@ async function refresh(): Promise<void> {
await TGLogger.Info(`[Character][refresh][${rfAccount.gameUid}] 正在更新角色数据`);
await showLoading.start(`正在更新${rfAccount.gameUid}的角色数据`);
loadData.value = true;
// 刷新战绩数据
await showLoading.update("正在刷新首页数据");
let indexResp: TGApp.Game.Record.Resp | undefined;
try {
indexResp = await recordReq.index(rfCk!, rfAccount, 1);
console.debug("recordIndexResp", indexResp);
if (indexResp.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${indexResp.retcode}] ${indexResp.message}`);
await TGLogger.Warn(`[Characters] ${indexResp.retcode}-${indexResp.message}`);
await TGLogger.Warn(`[Characters][refresh] ${indexResp.retcode}-${indexResp.message}`);
loadData.value = false;
return;
}
@@ -439,43 +437,63 @@ async function refresh(): Promise<void> {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取战绩数据异常: ${errMsg}`);
await TGLogger.Error(`[Characters][refresh] 获取战绩异常`);
await TGLogger.Error(`${e}`);
await TGLogger.Error(`[Characters][refresh] ${e}`);
loadData.value = false;
return;
}
await showLoading.update("正在获取角色列表");
const listRes = await recordReq.character.list(rfCk!, rfAccount);
console.log(listRes);
if (!Array.isArray(listRes)) {
showSnackbar.error(`[${listRes.retcode}] ${listRes.message}`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] 获取角色列表失败`);
await TGLogger.Error(
`[Character][refresh][${rfAccount.gameUid}] ${listRes.retcode} ${listRes.message}`,
);
let listResp: TGApp.Game.Avatar.ListResp | undefined;
try {
listResp = await recordReq.character.list(rfCk!, rfAccount);
if (listResp.retcode !== 0) {
showSnackbar.error(`[${listResp.retcode}] ${listResp.message}`);
await TGLogger.Warn(`[Character][refresh][${rfAccount.gameUid}] 获取角色列表失败`);
await TGLogger.Warn(
`[Character][refresh][${rfAccount.gameUid}] ${listResp.retcode} ${listResp.message}`,
);
await showLoading.end();
loadData.value = false;
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取角色列表异常: ${errMsg}`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] 获取角色列表异常`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] ${e}`);
await showLoading.end();
loadData.value = false;
return;
}
const idList = listRes.map((i) => i.id.toString());
const idList = listResp.data.list.map((i) => i.id.toString());
await showLoading.update(`${idList.length}个角色,正在获取角色详情`);
const res = await recordReq.character.detail(rfCk!, rfAccount, idList);
console.log(res);
if ("retcode" in res) {
showSnackbar.error(`[${res.retcode}] ${res.message}`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] 获取角色数据失败`);
await TGLogger.Error(
`[Character][refresh][${rfAccount.gameUid}] ${res.retcode} ${res.message}`,
);
let detailResp: TGApp.Game.Avatar.DetailResp | undefined;
try {
detailResp = await recordReq.character.detail(rfCk!, rfAccount, idList);
if (detailResp.retcode !== 0) {
showSnackbar.error(`[${detailResp.retcode}] ${detailResp.message}`);
await TGLogger.Warn(`[Character][refresh][${rfAccount.gameUid}] 获取角色数据失败`);
await TGLogger.Warn(
`[Character][refresh][${rfAccount.gameUid}] ${detailResp.retcode} ${detailResp.message}`,
);
await showLoading.end();
loadData.value = false;
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
showSnackbar.error(`获取角色详情异常: ${errMsg}`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] 获取角色详情异常`);
await TGLogger.Error(`[Character][refresh][${rfAccount.gameUid}] ${e}`);
await showLoading.end();
loadData.value = false;
return;
}
propMap.value = res.property_map;
propMap.value = detailResp.data.property_map;
await showLoading.update("正在保存角色数据");
await TSUserAvatar.saveAvatars(rfAccount.gameUid, res.list);
await TSUserAvatar.saveAvatars(rfAccount.gameUid, detailResp.data.list);
await TGLogger.Info(`[Character][refreshRoles][${rfAccount.gameUid}] 成功更新角色数据`);
await TGLogger.Info(
`[Character][refreshRoles][${rfAccount.gameUid}] 共更新${res.list.length}个角色`,
`[Character][refreshRoles][${rfAccount.gameUid}] 共更新${detailResp.data.list.length}个角色`,
);
await showLoading.update("正在加载角色数据");
await loadUid(uidCur.value);

View File

@@ -174,6 +174,7 @@ import { open } from "@tauri-apps/plugin-dialog";
import { readTextFile } from "@tauri-apps/plugin-fs";
import { openUrl } from "@tauri-apps/plugin-opener";
import { getRfAc } from "@utils/acUtils.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { generateShareImg } from "@utils/TGShare.js";
import { storeToRefs } from "pinia";
@@ -285,22 +286,31 @@ async function refreshCombat(): Promise<void> {
const { account: rfAccount, cookie: rfCk } = refreshData;
await TGLogger.Info("[Combat][refreshCombat] 更新剧诗数据");
await showLoading.start(`正在获取${rfAccount.gameUid}的剧诗数据`);
const res = await recordReq.combat.base(rfCk!, rfAccount);
console.log(res);
if ("retcode" in res) {
let resp: TGApp.Game.Combat.CombatResp | undefined;
try {
resp = await recordReq.combat.base(rfCk!, rfAccount);
if (resp.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Warn(`[Combat][refreshCombat] 获取${rfAccount.gameUid}的剧诗数据失败`);
await TGLogger.Warn(`[Combat][refreshCombat] ${resp.retcode} ${resp.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${res.retcode}]${res.message}`);
await TGLogger.Error(`[Combat][refreshCombat] 获取${rfAccount.gameUid}剧诗数据失败`);
await TGLogger.Error(`[Combat][refreshCombat] ${res.retcode} ${res.message}`);
showSnackbar.error(`获取剧诗数据失败:${errMsg}`);
await TGLogger.Error(`[Combat][refreshCombat] 获取剧诗数据异常`);
await TGLogger.Error(`[Combat][refreshCombat] ${e}`);
return;
}
if (!res.is_unlock) {
if (!resp.data.is_unlock) {
await showLoading.end();
showSnackbar.warn("用户未解锁幻想真境剧诗");
return;
}
await showLoading.update("正在保存剧诗数据");
for (const combat of res.data) {
for (const combat of resp.data.data) {
await showLoading.update("正在保存剧诗数据");
await TSUserCombat.saveCombat(rfAccount.gameUid, combat);
}
@@ -312,7 +322,6 @@ async function refreshCombat(): Promise<void> {
async function loadCharMaster(): Promise<void> {
const gcFind = await TSUserAccount.game.getAccountByGid(uidCur.value!.toString());
console.log(uidCur.value, gcFind);
if (!gcFind) {
showSnackbar.warn(`未找到 ${uidCur.value} 对应 UID无法获取对应游迹数据`);
return;
@@ -324,20 +333,30 @@ async function loadCharMaster(): Promise<void> {
}
await TGLogger.Info("[Combat][loadCharMaster] 获取绘想游迹数据");
await showLoading.start(`正在获取${gcFind.gameUid}的绘想游迹数据`);
const res = await recordReq.combat.char(acFind.cookie!, gcFind);
console.log(res);
if ("retcode" in res) {
let resp: TGApp.Game.Combat.CharResp | undefined;
try {
resp = await recordReq.combat.char(acFind.cookie!, gcFind);
if (resp.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Warn(`[Combat][loadCharMaster] 获取${gcFind.gameUid}的剧诗数据失败`);
await TGLogger.Warn(`[Combat][loadCharMaster] ${resp.retcode} ${resp.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${res.retcode}]${res.message}`);
await TGLogger.Error(`[Combat][loadCharMaster] 获取${gcFind.gameUid}的剧诗数据失败`);
await TGLogger.Error(`[Combat][loadCharMaster] ${res.retcode} ${res.message}`);
showSnackbar.error(`获取绘想游迹数据失败:${errMsg}`);
await TGLogger.Error(`[Combat][loadCharMaster] 获取绘想游迹数据异常`);
await TGLogger.Error(`[Combat][loadCharMaster] ${e}`);
return;
}
if (!res.is_unlock) {
if (!resp.data.is_unlock) {
await showLoading.end();
showSnackbar.warn("用户未解锁绘想游迹");
return;
} else charMasters.value = res.list;
}
charMasters.value = resp.data.list;
showSnackbar.success(`成功获取 ${uidCur.value} 的绘想游迹数据`);
await hideAllOverlay();
await showLoading.end();
@@ -346,7 +365,6 @@ async function loadCharMaster(): Promise<void> {
async function loadTarot(): Promise<void> {
const gcFind = await TSUserAccount.game.getAccountByGid(uidCur.value!.toString());
console.log(uidCur.value, gcFind);
if (!gcFind) {
showSnackbar.warn(`未找到 ${uidCur.value} 对应 UID无法获取对应圣牌数据`);
return;
@@ -358,20 +376,30 @@ async function loadTarot(): Promise<void> {
}
await TGLogger.Info("[Combat][loadTarot] 获取月谕圣牌数据");
await showLoading.start(`正在获取${gcFind.gameUid}的月谕圣牌数据`);
const res = await recordReq.combat.base(acFind.cookie!, gcFind);
console.log(res);
if ("retcode" in res) {
let res: TGApp.Game.Combat.CombatResp | undefined;
try {
res = await recordReq.combat.base(acFind.cookie!, gcFind);
if (res.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${res.retcode}] ${res.message}`);
await TGLogger.Warn(`[Combat][loadTarot] 获取${gcFind.gameUid}的月谕圣牌数据失败`);
await TGLogger.Warn(`[Combat][loadTarot] ${res.retcode} ${res.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${res.retcode}]${res.message}`);
await TGLogger.Error(`[Combat][loadTarot] 获取${gcFind.gameUid}月谕圣牌数据失败`);
await TGLogger.Error(`[Combat][loadTarot] ${res.retcode} ${res.message}`);
showSnackbar.error(`获取月谕圣牌数据失败:${errMsg}`);
await TGLogger.Error(`[Combat][loadTarot] 获取月谕圣牌数据异常`);
await TGLogger.Error(`[Combat][loadTarot] ${e}`);
return;
}
if (!res.is_unlock) {
if (!res.data.is_unlock) {
await showLoading.end();
showSnackbar.warn("用户未解锁幻想真境剧诗");
return;
} else tarotStat.value = res.tarot_card_state;
}
tarotStat.value = res.data.tarot_card_state;
showSnackbar.success(`成功获取${uidCur.value}的月谕圣牌数据`);
await hideAllOverlay();
await showLoading.end();

View File

@@ -5,64 +5,60 @@
import gameEnum from "@enum/game.js";
import { getRequestHeader } from "@utils/getRequestHeader.js";
import TGHttp from "@utils/TGHttp.js";
import TGHttps from "@utils/TGHttps.js";
// TakumiRecordGenshinApiBaseUrl => trgAbu
const trgAbu: Readonly<string> =
"https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/";
/**
* 获取角色详情
* @since Beta v0.6.3
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @param avatarIds - 角色 id 列表
* @returns 角色详情返回
* @returns 角色详情响应数据
*/
async function characterDetail(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
avatarIds: Array<string>,
): Promise<TGApp.Game.Avatar.DetailRes | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Avatar.DetailResp> {
const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token };
const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds };
const resp = await TGHttp<TGApp.Game.Avatar.DetailResp | TGApp.BBS.Response.Base>(
`${trgAbu}character/detail`,
{ method: "POST", body: JSON.stringify(data), headers: getRequestHeader(ck, "POST", data) },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.post<TGApp.Game.Avatar.DetailResp>(`${trgAbu}character/detail`, {
headers: getRequestHeader(ck, "POST", data),
body: JSON.stringify(data),
});
return resp.data;
}
/**
* 获取角色列表
* @since Beta v0.6.3
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @returns 角色列表返回
* @returns 角色列表响应数据
*/
async function characterList(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
): Promise<Array<TGApp.Game.Avatar.Avatar> | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Avatar.ListResp> {
const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token };
const data = { role_id: user.gameUid, server: user.region };
const resp = await TGHttp<TGApp.Game.Avatar.ListResp | TGApp.BBS.Response.Base>(
`${trgAbu}character/list`,
{ method: "POST", body: JSON.stringify(data), headers: getRequestHeader(ck, "POST", data) },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data.list;
const resp = await TGHttps.post<TGApp.Game.Avatar.ListResp>(`${trgAbu}character/list`, {
headers: getRequestHeader(ck, "POST", data),
body: JSON.stringify(data),
});
return resp.data;
}
/**
* 获取首页信息
* @since Beta v0.10.0
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @param listType - 列表类型
* @returns 首页返回
* @returns 首页响应数据
*/
async function index(
cookie: TGApp.App.Account.Cookie,
@@ -80,15 +76,15 @@ async function index(
/**
* 获取真境剧诗数据
* @since Beta v0.9.6
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @returns 真境剧诗数据
* @returns 真境剧诗响应数据
*/
async function roleCombat(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
): Promise<TGApp.Game.Combat.CombatRes | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Combat.CombatResp> {
const ck = {
account_id: cookie.account_id,
cookie_token: cookie.cookie_token,
@@ -96,25 +92,24 @@ async function roleCombat(
ltuid: cookie.ltuid,
};
const params = { role_id: user.gameUid, server: user.region, active: 1, need_detail: true };
const resp = await TGHttp<TGApp.Game.Combat.CombatResp | TGApp.BBS.Response.Base>(
`${trgAbu}role_combat`,
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.get<TGApp.Game.Combat.CombatResp>(`${trgAbu}role_combat`, {
headers: getRequestHeader(ck, "GET", params),
query: params,
});
return resp.data;
}
/**
* 获取绘想游迹数据
* @since Beta v0.9.6
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @returns 绘想游迹数据
* @returns 绘想游迹响应数据
*/
async function charMaster(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
): Promise<TGApp.BBS.Response.Base | TGApp.Game.Combat.CharRes> {
): Promise<TGApp.Game.Combat.CharResp> {
const ck = {
account_id: cookie.account_id,
cookie_token: cookie.cookie_token,
@@ -122,28 +117,27 @@ async function charMaster(
ltuid: cookie.ltuid,
};
const params = { role_id: user.gameUid, server: user.region };
const resp = await TGHttp<TGApp.Game.Combat.CharResp | TGApp.BBS.Response.Base>(
`${trgAbu}char_master`,
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.get<TGApp.Game.Combat.CharResp>(`${trgAbu}char_master`, {
headers: getRequestHeader(ck, "GET", params),
query: params,
});
return resp.data;
}
/**
* 获取深渊螺旋记录
* @since Beta v0.6.3
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @param schedule - 档期
* @example 1: 本期, 2: 上期
* @returns 深渊螺旋记录
* @returns 深渊螺旋响应数据
*/
async function spiralAbyss(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
schedule: string,
): Promise<TGApp.Game.Abyss.FullData | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Abyss.Response> {
const ck = {
account_id: cookie.account_id,
cookie_token: cookie.cookie_token,
@@ -151,23 +145,22 @@ async function spiralAbyss(
ltuid: cookie.ltuid,
};
const params = { role_id: user.gameUid, schedule_type: schedule, server: user.region };
const resp = await TGHttp<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>(
`${trgAbu}spiralAbyss`,
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.get<TGApp.Game.Abyss.Response>(`${trgAbu}spiralAbyss`, {
headers: getRequestHeader(ck, "GET", params),
query: params,
});
return resp.data;
}
/**
* 获取赋光之人列表
* @since Beta v0.8.0
* @since Beta v0.10.1
* @param server - 区服
* @returns 赋光之人列表
* @returns 赋光之人列表响应数据
*/
async function hardChallengePopularity(
server: TGApp.Game.Base.ServerTypeEnum = gameEnum.server.CN_GF01,
): Promise<TGApp.Game.Challenge.PopularityResp | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Challenge.PopularityResp> {
let roleId: number | undefined;
switch (server) {
case gameEnum.server.CN_GF01:
@@ -177,34 +170,32 @@ async function hardChallengePopularity(
roleId = 500299765;
break;
default:
return <TGApp.BBS.Response.Base>{ retcode: -1, message: "不支持的服务器", data: null };
throw new Error("不支持的服务器");
}
const resp = await TGHttp<TGApp.Game.Challenge.PopularityResp | TGApp.BBS.Response.Base>(
const resp = await TGHttps.get<TGApp.Game.Challenge.PopularityResp>(
`${trgAbu}hard_challenge/popularity`,
{ method: "GET", query: { server, role_id: roleId } },
{ query: { server, role_id: roleId } },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp;
return resp.data;
}
/**
* 获取幽境危战数据
* @since Beta v0.8.0
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @returns 幽境危战数据
* @returns 幽境危战响应数据
*/
async function hardChallengeDetail(
cookie: TGApp.App.Account.Cookie,
user: TGApp.Sqlite.Account.Game,
): Promise<TGApp.Game.Challenge.ChallengeRes | TGApp.BBS.Response.Base> {
): Promise<TGApp.Game.Challenge.ChallengeResp> {
const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token };
const params = { need_detail: true, role_id: user.gameUid, server: user.region };
const resp = await TGHttp<TGApp.Game.Challenge.ChallengeResp | TGApp.BBS.Response.Base>(
`${trgAbu}hard_challenge`,
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.get<TGApp.Game.Challenge.ChallengeResp>(`${trgAbu}hard_challenge`, {
headers: getRequestHeader(ck, "GET", params),
query: params,
});
return resp.data;
}
@@ -230,10 +221,10 @@ async function actCalendar(
/**
* 获取实时便笺
* @since Beta v0.10.0
* @since Beta v0.10.1
* @param cookie - Cookie
* @param user - 用户
* @returns 实时便笺数据
* @returns 实时便笺响应数据
*/
async function dailyNote(
cookie: TGApp.App.Account.Cookie,