🎨 一些优化

* 优化公告解析逻辑
* 咨讯页loading显示版块名称
* 移除无用文件
This commit is contained in:
目棃
2024-11-16 19:00:21 +08:00
parent 2f60e128a5
commit 680a54a0f1
23 changed files with 62 additions and 139 deletions

View File

@@ -1,7 +1,7 @@
/**
* @file web/constant/TGConstant.ts
* @description 常量
* @since Beta v0.5.1
* @since Beta v0.6.3
*/
import {
@@ -12,7 +12,6 @@ import {
BBS_VERSION,
CHANNEL_LIST,
} from "./bbs.js";
import SERVER from "./server.js";
import { GAME_BIZ } from "./utils.js";
const TGConstant = {
@@ -24,10 +23,7 @@ const TGConstant = {
CHANNELS: CHANNEL_LIST,
},
Salt: BBS_SALT,
Server: SERVER,
Utils: {
GAME_BIZ,
},
GAME_BIZ,
};
export default TGConstant;

View File

@@ -1,32 +0,0 @@
/**
* @file web constant server.ts
* @description 服务器地址常量文件
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
/**
* @description 服务器地址
* @since Alpha v0.2.0
* @enum {string}
* @readonly
* @property {string} CN_ISLAND 国服-天空岛
* @property {string} CN_TREE 国服-世界树
* @property {string} OS_USA 美服
* @property {string} OS_EURO 欧服
* @property {string} OS_ASIA 亚服
* @property {string} OS_CHT 台服
* @property {string} UNKNOWN 未知
* @returns {string} 服务器地址
*/
enum SERVER {
CN_ISLAND = "cn_gf01",
CN_TREE = "cn_qd01",
OS_USA = "os_usa",
OS_EURO = "os_euro",
OS_ASIA = "os_asia",
OS_CHT = "os_cht",
UNKNOWN = "unknown",
}
export default SERVER;

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 生成 authkey
@@ -23,11 +23,11 @@ export async function genAuthkey(
const ck = { stoken: cookie.stoken, mid: cookie.mid };
const data = {
auth_appid: "webview_gacha",
game_biz: TGConstant.Utils.GAME_BIZ,
game_biz: TGConstant.GAME_BIZ,
game_uid: account.gameUid,
region: account.region,
};
const header = TGUtils.User.getHeader(ck, "POST", JSON.stringify(data), "lk2", true);
const header = getRequestHeader(ck, "POST", JSON.stringify(data), "lk2", true);
const resp = await TGHttp<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
@@ -49,7 +49,7 @@ export async function genAuthkey2(
payload: Record<string, string>,
): 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);
const header = getRequestHeader(cookie, "POST", JSON.stringify(payload), "lk2", true);
return await TGHttp<TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 获取深渊信息
@@ -29,7 +29,7 @@ export async function getAbyss(
ltoken: cookie.ltoken,
ltuid: cookie.ltuid,
};
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
const header = getRequestHeader(ck, "GET", params, "common");
const resp = await TGHttp<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -5,7 +5,7 @@
*/
import TGHttp from "../../utils/TGHttp.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 通过 stoken 获取 ActionTicket
@@ -25,7 +25,7 @@ export async function getActionTicketBySToken(
const url = "https://api-takumi.mihoyo.com/auth/api/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");
const header = getRequestHeader(cookie, "GET", params, "k2");
return await TGHttp<TGApp.BBS.Response.getActionTicketBySToken>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 手动刷新角色数据
@@ -22,7 +22,7 @@ export async function getAvatarIndex(
const url = TGApi.GameData.getUserBase;
const params = { avatar_list_type: 1, role_id: user.gameUid, server: user.region };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
const header = getRequestHeader(ck, "GET", params, "common");
return await TGHttp<TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
@@ -44,7 +44,7 @@ export async function getAvatarList(
const url = TGApi.GameData.byCookie.getAvatarList;
const data = { role_id: user.gameUid, server: user.region };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
const header = getRequestHeader(ck, "POST", data, "common");
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: JSON.stringify(data),
@@ -70,7 +70,7 @@ export async function getAvatarDetail(
const url = TGApi.GameData.byCookie.getAvatarDetail;
const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
const header = getRequestHeader(ck, "POST", data, "common");
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: JSON.stringify(data),

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 根据 stoken 获取 cookie_token
@@ -22,7 +22,7 @@ export async function getCookieTokenBySToken(
const url = TGApi.GameTokens.getCookieToken;
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>(
url,
{

View File

@@ -7,7 +7,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 通过 stoken 获取游戏账号
@@ -22,7 +22,7 @@ export async function getGameAccountsBySToken(
): Promise<TGApp.BBS.Account.GameAccount[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.bySToken.getAccounts;
const cookie = { stuid, stoken };
const params = { stoken, stuid, game_biz: TGConstant.Utils.GAME_BIZ };
const params = { stoken, stuid, game_biz: TGConstant.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}
@@ -39,7 +39,7 @@ export async function getGameAccountsByCookie(
): Promise<TGApp.BBS.Account.GameAccount[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAccounts;
const cookie = { account_id, cookie_token };
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
const params = { game_biz: TGConstant.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}
@@ -56,7 +56,7 @@ async function getGameAccounts(
cookie: Record<string, string>,
params: Record<string, string>,
): Promise<TGApp.BBS.Response.Base | TGApp.BBS.Account.GameAccount[]> {
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getGameAccounts | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 获取用户游戏数据
@@ -23,7 +23,7 @@ export async function getGameRecord(
): 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");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.Game.Record.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 根据 stoken_v2 获取 ltoken
@@ -22,7 +22,7 @@ export async function getLTokenBySToken(
const url = TGApi.GameTokens.getLToken;
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 获取剧诗信息
@@ -27,7 +27,7 @@ export async function getRoleCombat(
ltoken: cookie.ltoken,
ltuid: cookie.ltuid,
};
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
const header = getRequestHeader(ck, "GET", params, "common");
const resp = await TGHttp<TGApp.Game.Combat.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -5,7 +5,7 @@
*/
import TGHttp from "../../utils/TGHttp.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 获取用户收藏帖子
@@ -22,7 +22,7 @@ export async function getUserCollect(
): Promise<TGApp.BBS.Collection.PostRespData | TGApp.BBS.Response.Base> {
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");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 根据 cookie 获取用户信息
@@ -25,7 +25,7 @@ export async function getUserInfoByCookie(
};
const url = TGApi.GameData.byCookie.getUserInfo;
const params = { gids: "2" };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common", true);
const header = getRequestHeader(cookie, "GET", params, "common", true);
const resp = await TGHttp<TGApp.Plugins.Mys.User.HomeResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,

View File

@@ -6,7 +6,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 验证 ltoken 有效性,返回 mid
@@ -22,7 +22,7 @@ export async function verifyLToken(
const url = TGApi.GameTokens.verifyLToken;
const cookie = { ltoken, ltuid };
const data = { ltoken };
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
const header = getRequestHeader(cookie, "POST", data, "common");
const resp = await TGHttp<TGApp.BBS.Response.verifyUserInfoBySToken | TGApp.BBS.Response.Base>(
url,
{

View File

@@ -1,24 +0,0 @@
/**
* @file web utils TGUtils.ts
* @description 应用用到的工具函数
* @since Beta v0.3.4
*/
import { getAnnoCard } from "./getAnnoCard.js";
import { getRequestHeader } from "./getRequestHeader.js";
import { getServerByUid, transCookie } from "./tools.js";
const TGUtils = {
Anno: {
getCard: getAnnoCard,
},
User: {
getHeader: getRequestHeader,
},
Tools: {
getServerByUid,
transCookie,
},
};
export default TGUtils;

View File

@@ -207,7 +207,7 @@ function parseAnnoNode(
/**
* @description 解析公告段落
* @since Beta v0.5.5
* @since Beta v0.6.3
* @param {HTMLElement} p - 段落元素
* @param {Record<string, string>} attr - 属性
* @returns {TGApp.Plugins.Mys.SctPost.Base} 结构化数据
@@ -267,7 +267,7 @@ function parseAnnoParagraph(
const res = parseAnnoNode(child, { bold: "true" });
return {
insert: "",
children: res,
children: [...res, { insert: "\n" }],
};
}
if (child.tagName === "T") {
@@ -295,10 +295,12 @@ function parseAnnoParagraph(
} else if (element.tagName === "A") {
childRes = parseAnnoAnchor(element);
} else if (element.tagName === "STRONG") {
childRes = {
insert: element.innerHTML,
attributes: { bold: true },
};
const resS = parseAnnoNode(element, { bold: "true" });
if (resS.length > 1) {
childRes = { insert: element.outerHTML };
} else {
childRes = resS[0];
}
} else if (element.tagName === "T") {
element.innerHTML = element.outerHTML;
const resE = parseAnnoNode(element);

View File

@@ -56,30 +56,11 @@ export function transParams(obj: Record<string, string | number | string[] | boo
}
/**
* @description 根据 uid 获取 server
* @since Beta v0.4.3
* @todo instead of account.region
* @deprecated
* @param {string} uid uid
* @returns {string} server
* @description 根据 gid 获取游戏名称
* @param {number} gid
* @returns {string}
*/
export function getServerByUid(uid: string): string {
// 若长度为 10则为国际服亚服
if (uid.length === 10) return TGConstant.Server.OS_ASIA;
// 获取第一个字符
const first = uid[0];
// 1-4 为国服-天空岛
if (first >= "1" && first <= "4") return TGConstant.Server.CN_ISLAND;
// 5 为国服-世界树
if (first === "5") return TGConstant.Server.CN_TREE;
// 6 为美服
if (first === "6") return TGConstant.Server.OS_USA;
// 7 为欧服
if (first === "7") return TGConstant.Server.OS_EURO;
// 8 为亚服
if (first === "8") return TGConstant.Server.OS_ASIA;
// 9 为台服
if (first === "9") return TGConstant.Server.OS_CHT;
// 其他情况返回未知
return TGConstant.Server.UNKNOWN;
export function getGameName(gid: number): string {
const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString());
return game ? game.title : "未知游戏";
}