mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-16 09:58:13 +08:00
♻️ 变更目录,参考 TGAssistant 优化一些方法
This commit is contained in:
41
src/web/request/TGRequest.ts
Normal file
41
src/web/request/TGRequest.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file core request TGRequest.ts
|
||||
* @description 应用用到的请求函数
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
import { getAnnoList, getAnnoContent } from "./getAnno";
|
||||
import {
|
||||
getTokensByLoginTicket, getLtokenBySToken,
|
||||
getCookieTokenBySToken, vetifySToken,
|
||||
} from "./getTokens";
|
||||
import {
|
||||
getGameCardByCookie, getGameAccountsByCookie,
|
||||
getAccountsBySToken, getGameRoleListByCookie,
|
||||
} from "./getGameData";
|
||||
|
||||
const TGRequest = {
|
||||
Anno: {
|
||||
getList: getAnnoList,
|
||||
getContent: getAnnoContent,
|
||||
},
|
||||
User: {
|
||||
byLoginTicket: {
|
||||
getLTokens: getTokensByLoginTicket,
|
||||
},
|
||||
byCookie: {
|
||||
getAccounts: getGameAccountsByCookie,
|
||||
getGameCard: getGameCardByCookie,
|
||||
getCharacter: getGameRoleListByCookie,
|
||||
},
|
||||
bySToken: {
|
||||
verify: vetifySToken,
|
||||
getLToken: getLtokenBySToken,
|
||||
getAccounts: getAccountsBySToken,
|
||||
getCookieToken: getCookieTokenBySToken,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default TGRequest;
|
||||
38
src/web/request/getAnno.ts
Normal file
38
src/web/request/getAnno.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file web request getAnnouncement.ts
|
||||
* @description 获取游戏内公告
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
// Tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
// Tauri.Genshin
|
||||
import TGApi from "../api/TGApi";
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告列表
|
||||
* @since Alpha v0.1.2
|
||||
* @returns {Promise<BTMuli.Genshin.Announcement.ListData>}
|
||||
*/
|
||||
export async function getAnnoList (): Promise<BTMuli.Genshin.Announcement.ListData> {
|
||||
return await http.fetch<BTMuli.Genshin.Announcement.ListResponse>(`${TGApi.GameAnnoList}${TGApi.GameAnnoQuery}`).then((res) => res.data.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告内容
|
||||
* @since Alpha v0.1.2
|
||||
* @param {number} annId 公告 ID
|
||||
* @returns {Promise<BTMuli.Genshin.Announcement.ContentItem>}
|
||||
*/
|
||||
export async function getAnnoContent (annId: number): Promise<BTMuli.Genshin.Announcement.ContentItem> {
|
||||
const annoContents: BTMuli.Genshin.Announcement.ContentItem[] = await http
|
||||
.fetch<BTMuli.Genshin.Announcement.ContentResponse>(`${TGApi.GameAnnoContent}${TGApi.GameAnnoQuery}`)
|
||||
.then((res) => res.data.data.list);
|
||||
const annoContent = annoContents.find((item) => item.ann_id === annId);
|
||||
if (annoContent) {
|
||||
return annoContent;
|
||||
} else {
|
||||
throw new Error("公告内容不存在");
|
||||
}
|
||||
}
|
||||
21
src/web/request/getEnkaData.ts
Normal file
21
src/web/request/getEnkaData.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @file web request getEnkaData.ts
|
||||
* @description 获取 ENKA 数据
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.3
|
||||
*/
|
||||
|
||||
// Tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
// Tauri.Genshin
|
||||
import TGApi from "../api/TGApi";
|
||||
|
||||
/**
|
||||
* @description 获取 ENKA 数据
|
||||
* @since Alpha v0.1.3
|
||||
* @param {number} uid 用户 UID
|
||||
* @returns {Promise<BTMuli.Genshin.Enka.Data>}
|
||||
*/
|
||||
export async function getEnkaData (uid: number): Promise<BTMuli.Genshin.Enka.Data> {
|
||||
return await http.fetch<BTMuli.Genshin.Enka.Data>(`${TGApi.GameEnka}${uid}`).then((res) => res.data);
|
||||
}
|
||||
101
src/web/request/getGameData.ts
Normal file
101
src/web/request/getGameData.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @file core utils getGameData.ts
|
||||
* @description 获取游戏数据的函数
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
import qs from "qs";
|
||||
// utils
|
||||
import TGApi from "../api/TGApi";
|
||||
import TGUtils from "../utils/TGUtils";
|
||||
import TGConstant from "../constant/TGConstant";
|
||||
|
||||
/**
|
||||
* @description 获取用户游戏数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户的 Cookie
|
||||
* @param {string} uid 用户的 UID
|
||||
* @returns {Promise<unknown>} 用户基本信息
|
||||
*/
|
||||
export async function getGameCardByCookie (cookie: string, uid: string): Promise<unknown> {
|
||||
const url = `${TGApi.GameData.getUserCard}`;
|
||||
const params = { uid };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
|
||||
console.log("header:", header);
|
||||
return await http.fetch(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
body: http.Body.json(params),
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户绑定角色-通过stoken
|
||||
* @since Alpha v0.2.0
|
||||
* @todo 暂时不考虑使用
|
||||
* @param {string} cookie 用户的 Cookie
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<unknown>} 用户绑定角色
|
||||
*/
|
||||
export async function getAccountsBySToken (cookie: string, stoken: string): Promise<unknown> {
|
||||
const url = TGApi.GameData.bySToken.getAccounts;
|
||||
// eslint-disable-next-line camelcase
|
||||
const params = { stoken, game_biz: TGConstant.Utils.GAME_BIZ };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", JSON.stringify(params), "common");
|
||||
return await http.fetch(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
body: http.Body.json(params),
|
||||
}).then((res) => {
|
||||
console.log(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户绑定游戏账号-通过cookie
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户的 Cookie
|
||||
* @returns {Promise<BTMuli.Genshin.Base.Response| BTMuli.User.Game.Account[]>} 用户绑定角色
|
||||
*/
|
||||
export async function getGameAccountsByCookie (cookie: string): Promise<BTMuli.Genshin.Base.Response | BTMuli.User.Game.Account[]> {
|
||||
const url = TGApi.GameData.byCookie.getAccounts;
|
||||
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
|
||||
return await http.fetch<BTMuli.User.Response.GameAccounts>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
}).then((res) => {
|
||||
console.log(res.data);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户角色列表
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户的 Cookie
|
||||
* @param {string} uid 用户 uid
|
||||
* @returns {Promise<unknown>} 用户角色列表
|
||||
*/
|
||||
export async function getGameRoleListByCookie (cookie: string, uid: string): Promise<unknown> {
|
||||
const url = TGApi.GameData.byCookie.getCharacter;
|
||||
// eslint-disable-next-line camelcase
|
||||
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
|
||||
const header = TGUtils.User.getHeader(cookie, "", JSON.stringify(data), "common");
|
||||
return await http.fetch(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
}).then((res) => {
|
||||
console.log(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
107
src/web/request/getTokens.ts
Normal file
107
src/web/request/getTokens.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @file web request getTokens.ts
|
||||
* @description 获取游戏 Token
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
// Node
|
||||
import qs from "qs";
|
||||
// api
|
||||
import TGApi from "../api/TGApi";
|
||||
// utils
|
||||
import TGUtils from "../utils/TGUtils";
|
||||
|
||||
/**
|
||||
* @description 根据 login_ticket 获取游戏 Token,包括 stoken 和 ltoken
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie cookie
|
||||
* @param {string} ticket 登录票证
|
||||
* @param {string} uid 登录用户 uid
|
||||
* @returns {Promise<BTMuli.User.Base.TokenItem[] | BTMuli.Genshin.Base.Response>}
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
export async function getTokensByLoginTicket (cookie: string, ticket: string, uid: string): Promise<BTMuli.User.Base.TokenItem[] | BTMuli.Genshin.Base.Response> {
|
||||
// eslint-disable-next-line camelcase
|
||||
const url = `${TGApi.GameTokens.getTokens}?login_ticket=${ticket}&token_types=3&uid=${uid}`;
|
||||
// eslint-disable-next-line camelcase
|
||||
const param = { login_ticket: ticket, token_types: 3, uid };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(param), "common");
|
||||
console.log("header:", header);
|
||||
return await http.fetch<BTMuli.User.Response.Token>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据 stoken 获取 ltoken
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户 Cookie
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
export async function getLtokenBySToken (cookie: string, stoken: string): Promise<unknown> {
|
||||
const url = TGApi.GameTokens.getLToken;
|
||||
const params = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
|
||||
console.log("header:", header);
|
||||
return await http.fetch<BTMuli.User.Response.Token>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
body: http.Body.json(params),
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据 stoken 获取 cookieToken
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户 Cookie
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
export async function getCookieTokenBySToken (cookie: string, stoken: string): Promise<unknown> {
|
||||
const url = TGApi.GameTokens.getCookieToken;
|
||||
const params = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
|
||||
console.log("header:", header);
|
||||
return await http.fetch(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
body: http.Body.json(params),
|
||||
}).then((res) => {
|
||||
console.log(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 验证 stoken 有效性
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie 用户 Cookie
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
export async function verifySToken (cookie: string, stoken: string): Promise<unknown> {
|
||||
const url = TGApi.GameTokens.verifyStoken;
|
||||
const data = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", qs.stringify(data), "common");
|
||||
console.log("header:", header);
|
||||
return await http.fetch(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
}).then((res) => {
|
||||
console.log(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user