mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
♻️ 姑且能跑 dev,尚需调试功能
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/constant/bbs.ts
|
||||
* @description 常量-应用数据
|
||||
* @since Beta v0.4.10
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
export const BBS_VERSION = "2.72.2";
|
||||
@@ -12,7 +12,7 @@ export const BBS_APP_ID = "bll8iq97cem8";
|
||||
/**
|
||||
* @description salt 值
|
||||
* @version 2.72.2
|
||||
* @since Beta v0.4.10
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
export const BBS_SALT = {
|
||||
K2: "KsQAfcXzHdMjoQQqjnPXVTXAygltZbSI",
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/genAuthkey.ts
|
||||
* @description 生成 authkey
|
||||
* @since Beta v0.3.7
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 生成 authkey
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string, string>} cookie cookie // stoken_v2 & mid
|
||||
* @param {string} gameUid 游戏 uid
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>} authkey
|
||||
@@ -29,17 +27,18 @@ export async function genAuthkey(
|
||||
region: TGUtils.Tools.getServerByUid(gameUid),
|
||||
};
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "lk2", true);
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
|
||||
.then((res: Response<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode === 0) return res.data.data.authkey;
|
||||
return res.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.authkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 生成 authkey
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string, string>} cookie cookie // stoken_v2 & mid
|
||||
* @param {object} payload payload
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>} authkey
|
||||
@@ -50,7 +49,9 @@ export async function genAuthkey2(
|
||||
): Promise<TGApp.BBS.Response.Base> {
|
||||
const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey";
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(payload), "lk2", true);
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header, body: http.Body.json(payload) })
|
||||
.then((res: Response<TGApp.BBS.Response.Base>) => res.data);
|
||||
return await TGHttp<TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getAbyss.ts
|
||||
* @description 获取深渊信息
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取深渊信息
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @param {string} schedule_type 1: 本期, 2: 上期
|
||||
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
||||
@@ -27,10 +25,11 @@ export async function getAbyss(
|
||||
const role_id = account.gameUid;
|
||||
const params = { role_id, schedule_type, server: account.region };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
/**
|
||||
* @file web/request/getActionTicket.ts
|
||||
* @description 获取米游社动态的 ActionTicket
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 通过 stoken 获取 ActionTicket
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} ActionType 动作类型
|
||||
* @param {string} SToken stoken
|
||||
* @param {string} MID 用户 MID
|
||||
@@ -28,7 +26,9 @@ export async function getActionTicketBySToken(
|
||||
const params = { action_type: ActionType, stoken: SToken, uid: UID };
|
||||
const cookie = { mid: MID, stoken: SToken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "k2");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.BBS.Response.getActionTicketBySToken>) => res.data);
|
||||
return await TGHttp<TGApp.BBS.Response.getActionTicketBySToken>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* @file web/request/getAnnouncement.ts
|
||||
* @description 获取游戏内公告
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
|
||||
export enum AnnoServer {
|
||||
CN_ISLAND = "cn_gf01",
|
||||
@@ -48,7 +48,7 @@ function getAnnoParams(
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告列表
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} region 服务器
|
||||
* @param {AnnoLang} lang 语言
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ListData>}
|
||||
@@ -62,14 +62,16 @@ export async function getAnnoList(
|
||||
if (region !== AnnoServer.CN_ISLAND && region !== AnnoServer.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnList";
|
||||
}
|
||||
return await http
|
||||
.fetch(url, { method: "GET", query: params })
|
||||
.then((res: Response<TGApp.BBS.Announcement.ListResponse>) => res.data.data);
|
||||
const resp = await TGHttp<TGApp.BBS.Announcement.ListResponse>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
});
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告内容
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
* @param {number} annId 公告 ID
|
||||
* @param {AnnoServer} region 服务器
|
||||
* @param {AnnoLang} lang 语言
|
||||
@@ -85,10 +87,11 @@ export async function getAnnoContent(
|
||||
if (region !== AnnoServer.CN_ISLAND && region !== AnnoServer.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnContent";
|
||||
}
|
||||
const annoContents: TGApp.BBS.Announcement.ContentItem[] = await http
|
||||
.fetch(url, { method: "GET", query: params })
|
||||
.then((res: Response<TGApp.BBS.Announcement.ContentResponse>) => res.data.data.list);
|
||||
const annoContent = annoContents.find((item) => item.ann_id === annId);
|
||||
const annoResp = await TGHttp<TGApp.BBS.Announcement.ContentResponse>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
});
|
||||
const annoContent = annoResp.data.list.find((item) => item.ann_id === annId);
|
||||
if (annoContent != null) {
|
||||
return annoContent;
|
||||
} else {
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getCookieToken.ts
|
||||
* @description 获取 Cookie Token 的请求函数
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 根据 stoken 获取 cookie_token
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} Mid 登录用户的 mid
|
||||
* @param {string} Stoken stoken_v2
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
@@ -25,17 +23,21 @@ export async function getCookieTokenBySToken(
|
||||
const cookie = { mid: Mid, stoken: Stoken };
|
||||
const params = { stoken: Stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.cookie_token;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>(
|
||||
url,
|
||||
{
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.cookie_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据 gameToken 获取 cookie_token
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} accountId 账号 id
|
||||
* @param {string} gameToken gameToken
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
@@ -46,12 +48,13 @@ export async function getCookieTokenByGameToken(
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
|
||||
const data = { account_id: Number(accountId), game_token: gameToken };
|
||||
return await http
|
||||
.fetch(url, { method: "POST", body: http.Body.json(data) })
|
||||
.then(
|
||||
(res: Response<TGApp.BBS.Response.getCookieTokenByGameToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.cookie_token;
|
||||
},
|
||||
);
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getCookieTokenByGameToken | TGApp.BBS.Response.Base>(
|
||||
url,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.cookie_token;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file src/web/request/getDeviceFp.ts
|
||||
* @description 获取设备指纹
|
||||
* @since Beta v0.4.1
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import { getInitDeviceInfo } from "../../utils/toolFunc.js";
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
|
||||
/**
|
||||
* @description 获取设备指纹
|
||||
* @since Beta v0.4.1
|
||||
* @since Beta v0.5.0
|
||||
* @param {TGApp.App.Device.DeviceInfo} Info - 设备信息
|
||||
* @returns {Promise<string>} 设备指纹
|
||||
*/
|
||||
@@ -93,11 +91,19 @@ export async function getDeviceFp(
|
||||
"x-requested-with": "com.mihoyo.hyperion",
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
};
|
||||
info.device_fp = await http
|
||||
.fetch(url, { method: "POST", body: http.Body.json(data), headers: header })
|
||||
.then((res: Response<TGApp.BBS.Response.getDeviceFp>) => {
|
||||
if (res.data.data.code === 200) return res.data.data.device_fp;
|
||||
return "0000000000000";
|
||||
try {
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getDeviceFp>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
headers: header,
|
||||
});
|
||||
if (resp.retcode !== 0) {
|
||||
info.device_fp = "0000000000000";
|
||||
} else {
|
||||
info.device_fp = resp.data.device_fp;
|
||||
}
|
||||
} catch (error) {
|
||||
info.device_fp = "0000000000000";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
/**
|
||||
* @file web/request/getGachaLog.ts
|
||||
* @description 获取抽卡记录请求函数
|
||||
* @since Beta v0.3.5
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
|
||||
/**
|
||||
* @description 获取抽卡记录
|
||||
* @since Beta v0.3.5
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} authkey authkey
|
||||
* @param {string} gachaType 抽卡类型
|
||||
* @param {string} endId 结束 id,默认为 0
|
||||
@@ -31,10 +30,10 @@ export async function getGachaLog(
|
||||
size: "20",
|
||||
end_id: endId,
|
||||
};
|
||||
return await http
|
||||
.fetch(url, { method: "GET", query: params })
|
||||
.then((res: Response<TGApp.Game.Gacha.GachaLogResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Game.Gacha.GachaLogResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
/**
|
||||
* @file web/request/getGameAccounts.ts
|
||||
* @description 获取游戏账号信息相关请求函数
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
@@ -47,7 +45,7 @@ export async function getGameAccountsByCookie(
|
||||
|
||||
/**
|
||||
* @description 获取游戏账号信息
|
||||
* @since Alpha v0.2.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} url 请求地址
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @param {Record<string, string>} params 请求参数
|
||||
@@ -59,10 +57,11 @@ async function getGameAccounts(
|
||||
params: Record<string, string>,
|
||||
): Promise<TGApp.BBS.Response.Base | TGApp.User.Account.Game[]> {
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.User.Account.GameResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.User.Account.GameResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file core/utils/getGameRecord.ts
|
||||
* @description 获取游戏数据的函数
|
||||
* @since Beta v0.4.10
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取用户游戏数据
|
||||
* @since Beta v0.4.10
|
||||
* @since Beta v0.5.0
|
||||
* @description 这边的 ck 可以是 cookie_token 和 account_id
|
||||
* @description 也可以是 ltoken 和 ltuid
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
@@ -26,12 +24,11 @@ export async function getGameRecord(
|
||||
const url = TGApi.GameData.getUserBase;
|
||||
const params = { role_id: user.gameUid, server: user.region };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.Game.Record.Response | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) {
|
||||
return <TGApp.BBS.Response.Base>res.data;
|
||||
}
|
||||
return res.data.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Game.Record.Response | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getLToken.ts
|
||||
* @description 获取 ltoken 的请求
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 根据 stoken_v2 获取 ltoken
|
||||
* @since Beta v0.3.0
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} Mid 登录用户 mid
|
||||
* @param {string} Stoken stoken_v2
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
@@ -25,10 +23,11 @@ export async function getLTokenBySToken(
|
||||
const cookie = { mid: Mid, stoken: Stoken };
|
||||
const params = { stoken: Stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.ltoken;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.ltoken;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getRoleList.ts
|
||||
* @description 获取游戏角色列表的请求方法
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 通过 Cookie 获取用户角色列表
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
||||
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
|
||||
@@ -23,13 +21,13 @@ export async function getGameRoleListByLToken(
|
||||
): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getCharacter;
|
||||
const uid = account.gameUid;
|
||||
|
||||
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common");
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
|
||||
.then((res: Response<TGApp.Game.Character.ListResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data.avatars;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Game.Character.ListResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.avatars;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getStoken.ts
|
||||
* @description 获取 stoken
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
import { getRequestHeader } from "../utils/getRequestHeader.js";
|
||||
|
||||
/**
|
||||
* @description 获取 stoken
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} accountId 账户 ID
|
||||
* @param {string} token 游戏 Token
|
||||
* @param {string} isGameToken 是否为游戏 Token
|
||||
@@ -29,17 +27,17 @@ export async function getStokenByGameToken(
|
||||
}
|
||||
const data = { account_id: Number(accountId), game_token: token };
|
||||
const header = { "x-rpc-app_id": TGConstant.BBS.APP_ID };
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
|
||||
.then((res: Response<TGApp.BBS.Response.getStokenByGameToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getStokenByGameToken | TGApp.BBS.Response.Base>(
|
||||
url,
|
||||
{ method: "POST", headers: header, body: JSON.stringify(data) },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description stoken v1 到 v2
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} stoken 账户 ID
|
||||
* @param {string} stuid 游戏 Token
|
||||
* @returns {Promise<TGApp.BBS.Response.getStokenByGameTokenData | TGApp.BBS.Response.Base>}
|
||||
@@ -54,10 +52,10 @@ export async function getTokenBySToken(
|
||||
"x-rpc-app_id": TGConstant.BBS.APP_ID,
|
||||
...getRequestHeader(cookie, "POST", "", "prod"),
|
||||
};
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header })
|
||||
.then((res: Response<TGApp.BBS.Response.getTokenBySToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getTokenBySToken | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* @file web/request/getSyncAvatarDetail.ts
|
||||
* @description 获取同步角色详情相关请求函数
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { app, http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取同步角色详情
|
||||
* @since Beta v0.3.8
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} accountId 账号 id
|
||||
* @param {string} cookieToken cookie token
|
||||
* @param {string} uid 用户 uid
|
||||
@@ -37,14 +37,15 @@ async function getSyncAvatarDetail(
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie({ account_id: accountId, cookie_token: cookieToken }),
|
||||
};
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then(
|
||||
(res: Response<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data;
|
||||
},
|
||||
);
|
||||
const resp = await TGHttp<
|
||||
TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base
|
||||
>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
export default getSyncAvatarDetail;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* @file web/request/getSyncAvatarListAll.ts
|
||||
* @description 获取同步角色列表请求
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { app, http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取同步角色列表请求
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string,string>} cookie cookie
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {number} page 页码
|
||||
@@ -31,14 +31,12 @@ async function getSyncAvatarList(
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
||||
};
|
||||
return await http
|
||||
.fetch(url, { method: "POST", body: http.Body.json(data), headers: header })
|
||||
.then(
|
||||
(res: Response<TGApp.Game.Calculate.SyncAvatarListResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
},
|
||||
);
|
||||
const resp = await TGHttp<TGApp.Game.Calculate.SyncAvatarListResponse | TGApp.BBS.Response.Base>(
|
||||
url,
|
||||
{ method: "POST", body: JSON.stringify(data), headers: header },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getTokens.ts
|
||||
* @description 获取游戏 Token
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 根据 login_ticket 获取游戏 Token,包括 sToken 和 lToken
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} ticket 登录票证
|
||||
* @param {string} uid 登录用户 uid
|
||||
* @returns {Promise<TGApp.BBS.Response.getTokensRes[] | TGApp.BBS.Response.Base>}
|
||||
@@ -25,11 +23,12 @@ export async function getTokensByLoginTicket(
|
||||
const url = TGApi.GameTokens.getTokens;
|
||||
const params = { login_ticket: ticket, token_types: "3", uid };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.BBS.Response.getTokens | TGApp.BBS.Response.Base>) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.getTokens | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
console.log(resp);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
/**
|
||||
* @file web/request/getUserCollect.ts
|
||||
* @description 获取用户收藏请求模块
|
||||
* @since Beta v0.4.5
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取用户收藏帖子
|
||||
* @since Beta v0.4.5
|
||||
* @since Beta v0.5.0
|
||||
* @param {Record<string, string>} cookie - 用户 cookie
|
||||
* @param {string} uid - 用户 uid
|
||||
* @param {string} offset - 偏移量
|
||||
@@ -25,10 +23,11 @@ export async function getUserCollect(
|
||||
const url = "https://bbs-api.miyoushe.com/post/wapi/userFavouritePost";
|
||||
const params = { size: "20", uid, offset };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/getUserInfo.ts
|
||||
* @description 获取用户信息请求
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 根据 cookie 获取用户信息
|
||||
* @since Beta v0.3.4
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} cookie_token cookie token
|
||||
* @param {string} account_id 用户 account_id
|
||||
* @returns {Promise<TGApp.BBS.Response.Base | TGApp.Plugins.Mys.User.Info>}
|
||||
@@ -28,10 +26,11 @@ export async function getUserInfoByCookie(
|
||||
const url = TGApi.GameData.byCookie.getUserInfo;
|
||||
const params = { gids: "2" };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common", true);
|
||||
return await http
|
||||
.fetch(url, { method: "GET", headers: header, query: params })
|
||||
.then((res: Response<TGApp.Plugins.Mys.User.HomeResponse | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.user_info;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.Plugins.Mys.User.HomeResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.user_info;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/**
|
||||
* @file web/request/verifyLToken.ts
|
||||
* @description 验证 stoken 的请求函数
|
||||
* @since Alpha v0.1.5
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import type { Response } from "@tauri-apps/api/http";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 验证 ltoken 有效性,返回 mid
|
||||
* @since Alpha v0.1.5
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} ltoken ltoken
|
||||
* @param {string} ltuid 登录用户 uid
|
||||
* @returns {Promise<string | TGApp.BBS.Response.Base>}
|
||||
@@ -25,10 +23,14 @@ export async function verifyLToken(
|
||||
const cookie = { ltoken, ltuid };
|
||||
const data = { ltoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
|
||||
return await http
|
||||
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
|
||||
.then((res: Response<TGApp.BBS.Response.verifyUserInfoBySToken | TGApp.BBS.Response.Base>) => {
|
||||
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
|
||||
return res.data.data.user_info.mid;
|
||||
});
|
||||
const resp = await TGHttp<TGApp.BBS.Response.verifyUserInfoBySToken | TGApp.BBS.Response.Base>(
|
||||
url,
|
||||
{
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.user_info.mid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user