mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-16 09:58:13 +08:00
🎨 代码格式化
This commit is contained in:
@@ -20,17 +20,23 @@ import { getRequestHeader } from "../utils/getRequestHeader";
|
||||
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
||||
* @returns {Promise<TGApp.Game.Abyss.FullData|TGApp.App.Base.Response>}
|
||||
*/
|
||||
export async function getAbyss (cookie: Record<string, string>, schedule_type: string, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Abyss.FullData | TGApp.BBS.Response.Base> {
|
||||
export async function getAbyss(
|
||||
cookie: Record<string, string>,
|
||||
schedule_type: string,
|
||||
account: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.Game.Abyss.FullData | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.getAbyss;
|
||||
const role_id = account.gameUid;
|
||||
const params = { role_id, schedule_type, server: account.region };
|
||||
const header = getRequestHeader(cookie, "GET", params, "common");
|
||||
return await http.fetch<TGApp.Game.Abyss.Response>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then(res => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.Game.Abyss.Response>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ import TGApi from "../api/TGApi";
|
||||
* @since Alpha v0.1.2
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ListData>}
|
||||
*/
|
||||
export async function getAnnoList (): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
return await http.fetch<TGApp.BBS.Announcement.ListResponse>(`${TGApi.GameAnnoList}${TGApi.GameAnnoQuery}`).then((res) => res.data.data);
|
||||
export async function getAnnoList(): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Announcement.ListResponse>(`${TGApi.GameAnnoList}${TGApi.GameAnnoQuery}`)
|
||||
.then((res) => res.data.data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,12 +27,12 @@ export async function getAnnoList (): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
* @param {number} annId 公告 ID
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ContentItem>}
|
||||
*/
|
||||
export async function getAnnoContent (annId: number): Promise<TGApp.BBS.Announcement.ContentItem> {
|
||||
export async function getAnnoContent(annId: number): Promise<TGApp.BBS.Announcement.ContentItem> {
|
||||
const annoContents: TGApp.BBS.Announcement.ContentItem[] = await http
|
||||
.fetch<TGApp.BBS.Announcement.ContentResponse>(`${TGApi.GameAnnoContent}${TGApi.GameAnnoQuery}`)
|
||||
.then((res) => res.data.data.list);
|
||||
const annoContent = annoContents.find((item) => item.ann_id === annId);
|
||||
if (annoContent) {
|
||||
if (annoContent != null) {
|
||||
return annoContent;
|
||||
} else {
|
||||
throw new Error("公告内容不存在");
|
||||
|
||||
@@ -19,7 +19,10 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getCookieTokenBySToken (stuid: string, stoken: string): Promise<string | TGApp.BBS.Response.Base> {
|
||||
export async function getCookieTokenBySToken(
|
||||
stuid: string,
|
||||
stoken: string,
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameTokens.getCookieToken;
|
||||
const cookie = {
|
||||
stuid,
|
||||
@@ -27,12 +30,14 @@ export async function getCookieTokenBySToken (stuid: string, stoken: string): Pr
|
||||
};
|
||||
const params = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http.fetch<TGApp.BBS.Response.getCookieTokenBySToken>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.cookie_token;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Response.getCookieTokenBySToken>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.cookie_token;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ import TGConstant from "../constant/TGConstant";
|
||||
* @param {string} stuid 登录用户 uid
|
||||
* @returns {Promise<TGApp.User.Game.Account[]|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getGameAccountsBySToken (stoken: string, stuid: string): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
|
||||
export async function getGameAccountsBySToken(
|
||||
stoken: string,
|
||||
stuid: string,
|
||||
): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.bySToken.getAccounts;
|
||||
const cookie = {
|
||||
stuid,
|
||||
@@ -37,7 +40,10 @@ export async function getGameAccountsBySToken (stoken: string, stuid: string): P
|
||||
* @param {string} account_id 游戏账号 id
|
||||
* @returns {Promise<TGApp.User.Account.Game[]|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getGameAccountsByCookie (cookie_token: string, account_id: string): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
|
||||
export async function getGameAccountsByCookie(
|
||||
cookie_token: string,
|
||||
account_id: string,
|
||||
): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAccounts;
|
||||
const cookie = {
|
||||
account_id,
|
||||
@@ -55,14 +61,20 @@ export async function getGameAccountsByCookie (cookie_token: string, account_id:
|
||||
* @param {Record<string, string>} params 请求参数
|
||||
* @returns {Promise<TGApp.User.Account.Game[]|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getGameAccounts (url: string, cookie: Record<string, string>, params: Record<string, string>): Promise<TGApp.BBS.Response.Base | TGApp.User.Account.Game[]> {
|
||||
async function getGameAccounts(
|
||||
url: string,
|
||||
cookie: Record<string, string>,
|
||||
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<TGApp.User.Account.GameResponse>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then(res => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.User.Account.GameResponse>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,18 +20,23 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @param {TGApp.Sqlite.Account.Game} user 用户的基本信息
|
||||
* @returns {Promise<TGApp.Game.Record.FullData|TGApp.BBS.Response.Base>} 用户基本信息
|
||||
*/
|
||||
export async function getGameRecord (cookie: Record<string, string>, user: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Record.FullData | TGApp.BBS.Response.Base> {
|
||||
export async function getGameRecord(
|
||||
cookie: Record<string, string>,
|
||||
user: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.Game.Record.FullData | TGApp.BBS.Response.Base> {
|
||||
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<TGApp.Game.Record.Response>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) {
|
||||
return res.data;
|
||||
}
|
||||
return res.data.data;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.Game.Record.Response>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) {
|
||||
return res.data;
|
||||
}
|
||||
return res.data.data;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @param {string} stoken stoken
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getLTokenBySToken (stuid: string, stoken: string): Promise<string | TGApp.BBS.Response.Base> {
|
||||
export async function getLTokenBySToken(
|
||||
stuid: string,
|
||||
stoken: string,
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameTokens.getLToken;
|
||||
const cookie = {
|
||||
stuid,
|
||||
@@ -27,12 +30,14 @@ export async function getLTokenBySToken (stuid: string, stoken: string): Promise
|
||||
};
|
||||
const params = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http.fetch<TGApp.BBS.Response.getLTokenBySToken>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.ltoken;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Response.getLTokenBySToken>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.ltoken;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,18 +18,28 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @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, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> {
|
||||
export async function getGameRoleListByLToken(
|
||||
cookie: TGApp.BBS.Constant.CookieGroup4,
|
||||
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) };
|
||||
const header = TGUtils.User.getHeader(cookie as unknown as Record<string, string>, "POST", JSON.stringify(data), "common");
|
||||
return await http.fetch<TGApp.Game.Character.ListResponse>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.avatars;
|
||||
});
|
||||
const header = TGUtils.User.getHeader(
|
||||
cookie as unknown as Record<string, string>,
|
||||
"POST",
|
||||
JSON.stringify(data),
|
||||
"common",
|
||||
);
|
||||
return await http
|
||||
.fetch<TGApp.Game.Character.ListResponse>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.avatars;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @param {string} uid 登录用户 uid
|
||||
* @returns {Promise<TGApp.BBS.Response.getTokensRes[] | TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getTokensByLoginTicket (ticket: string, uid: string): Promise<TGApp.BBS.Response.getTokensRes[] | TGApp.BBS.Response.Base> {
|
||||
export async function getTokensByLoginTicket(
|
||||
ticket: string,
|
||||
uid: string,
|
||||
): Promise<TGApp.BBS.Response.getTokensRes[] | TGApp.BBS.Response.Base> {
|
||||
const cookie = {
|
||||
login_ticket: ticket,
|
||||
login_uid: uid,
|
||||
@@ -28,13 +31,15 @@ export async function getTokensByLoginTicket (ticket: string, uid: string): Prom
|
||||
// eslint-disable-next-line camelcase
|
||||
const params = { login_ticket: ticket, token_types: 3, uid };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http.fetch<TGApp.BBS.Response.getTokens>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Response.getTokens>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.list;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@ import { type UserResponse } from "../../plugins/Mys/interface/user";
|
||||
* @param {string} account_id 用户 account_id
|
||||
* @returns {Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getUserInfoByCookie (cookie_token: string, account_id: string): Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base> {
|
||||
export async function getUserInfoByCookie(
|
||||
cookie_token: string,
|
||||
account_id: string,
|
||||
): Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base> {
|
||||
const cookie = {
|
||||
cookie_token,
|
||||
account_id,
|
||||
@@ -29,18 +32,20 @@ export async function getUserInfoByCookie (cookie_token: string, account_id: str
|
||||
const url = TGApi.GameData.byCookie.getUserInfo;
|
||||
const params = { gids: "2" };
|
||||
const header = TGUtils.User.getSignHeader(cookie, "GET", {}, "common");
|
||||
return await http.fetch<UserResponse>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
const info = res.data.data.user_info;
|
||||
return {
|
||||
nickname: info.nickname,
|
||||
uid: info.uid,
|
||||
avatar: info.avatar_url,
|
||||
desc: info.introduce,
|
||||
};
|
||||
});
|
||||
return await http
|
||||
.fetch<UserResponse>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
const info = res.data.data.user_info;
|
||||
return {
|
||||
nickname: info.nickname,
|
||||
uid: info.uid,
|
||||
avatar: info.avatar_url,
|
||||
desc: info.introduce,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { verifyLToken } from "./verifyLToken";
|
||||
* @param {string} uid login_uid
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function initCookie (ticket: string, uid: string): Promise<void> {
|
||||
async function initCookie(ticket: string, uid: string): Promise<void> {
|
||||
const tokenRes = await getTokensByLoginTicket(ticket, uid);
|
||||
const cookie: TGApp.BBS.Constant.Cookie = {
|
||||
account_id: uid,
|
||||
@@ -35,8 +35,8 @@ async function initCookie (ticket: string, uid: string): Promise<void> {
|
||||
if (Array.isArray(tokenRes)) {
|
||||
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
||||
const sToken = tokenRes.find((item) => item.name === "stoken");
|
||||
if (lToken) cookie.ltoken = lToken.token;
|
||||
if (sToken) cookie.stoken = sToken.token;
|
||||
if (lToken != null) cookie.ltoken = lToken.token;
|
||||
if (sToken != null) cookie.stoken = sToken.token;
|
||||
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
|
||||
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
|
||||
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid);
|
||||
|
||||
@@ -19,7 +19,10 @@ import TGUtils from "../utils/TGUtils";
|
||||
* @param {string} ltuid 登录用户 uid
|
||||
* @returns {Promise<string | TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function verifyLToken (ltoken: string, ltuid: string): Promise<string | TGApp.BBS.Response.Base> {
|
||||
export async function verifyLToken(
|
||||
ltoken: string,
|
||||
ltuid: string,
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameTokens.verifyLToken;
|
||||
const cookie = {
|
||||
ltoken,
|
||||
@@ -27,12 +30,14 @@ export async function verifyLToken (ltoken: string, ltuid: string): Promise<stri
|
||||
};
|
||||
const data = { ltoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
|
||||
return await http.fetch<TGApp.BBS.Response.verifyUserInfoBySToken>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
}).then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.user_info.mid;
|
||||
});
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Response.verifyUserInfoBySToken>(url, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: http.Body.json(data),
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
return res.data.data.user_info.mid;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user