diff --git a/eslint/vueEslint.js b/eslint/vueEslint.js index 61455421..cea66f7e 100644 --- a/eslint/vueEslint.js +++ b/eslint/vueEslint.js @@ -10,10 +10,7 @@ const tsConfigRules = { "@typescript-eslint/no-import-type-side-effects": "error", "@typescript-eslint/strict-boolean-expressions": "off", "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-expressions": [ - "error", - { allowShortCircuit: false }, - ], + "@typescript-eslint/no-unused-expressions": ["error", { allowShortCircuit: false }], "import/order": [ "error", { diff --git a/src/pages/common/Announcements.vue b/src/pages/common/Announcements.vue index 00b86af3..1de12cce 100644 --- a/src/pages/common/Announcements.vue +++ b/src/pages/common/Announcements.vue @@ -64,7 +64,7 @@ import { useAppStore } from "../../store/modules/app.js"; import TGLogger from "../../utils/TGLogger.js"; import { AnnoLang, AnnoServer } from "../../web/request/getAnno.js"; import TGRequest from "../../web/request/TGRequest.js"; -import TGUtils from "../../web/utils/TGUtils.js"; +import { getAnnoCard } from "../../web/utils/getAnnoCard.js"; import { decodeRegExp } from "../../web/utils/tools.js"; type AnnoSelect = { text: string; value: string }; @@ -145,7 +145,7 @@ async function loadData(): Promise { `服务器:${getRegionName(curRegion.value)},语言:${getLangName(curLang.value)}`, ); const annoData = await TGRequest.Anno.getList(curRegion.value, curLang.value); - const listCards = TGUtils.Anno.getCard(annoData); + const listCards = getAnnoCard(annoData); await Promise.all( listCards.map(async (item) => { if (item.typeLabel === AnnoType.game) return; diff --git a/src/pages/common/News.vue b/src/pages/common/News.vue index c6992a0c..a1789da2 100644 --- a/src/pages/common/News.vue +++ b/src/pages/common/News.vue @@ -69,6 +69,7 @@ import Mys from "../../plugins/Mys/index.js"; import { useAppStore } from "../../store/modules/app.js"; import TGLogger from "../../utils/TGLogger.js"; import { createPost } from "../../utils/TGWindow.js"; +import { getGameName } from "../../web/utils/tools.js"; // 类型定义 enum NewsType { @@ -92,6 +93,7 @@ type RawData = { // 路由 const router = useRouter(); const gid = useRoute().params.gid; +const gameName = getGameName(Number(gid)); // loading const loading = ref(false); @@ -146,12 +148,12 @@ async function firstLoad(key: NewsKey, refresh: boolean = false): Promise postData.value[key] = []; rawData.value[key].lastId = 0; } - showLoading.start(`正在获取${rawData.value[key].name}数据...`); + showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`); const getData = await Mys.Painter.getNewsList(gid, NewsType[key]); rawData.value[key].isLast = getData.is_last; rawData.value[key].lastId = getData.list.length; postData.value[key] = getData.list; - showLoading.update(`正在渲染${rawData.value[key].name}数据...`); + showLoading.update(`正在渲染${gameName}${rawData.value[key].name}数据...`); await nextTick(() => showLoading.end()); await TGLogger.Info(`[News][${gid}][firstLoad] 获取${rawData.value[key].name}数据成功`); } @@ -169,7 +171,7 @@ async function loadMore(key: NewsKey): Promise { loading.value = false; return; } - showLoading.start(`正在获取${rawData.value[key].name}数据...`); + showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`); const getData = await Mys.Painter.getNewsList(gid, NewsType[key], 20, rawData.value[key].lastId); rawData.value[key].lastId = rawData.value[key].lastId + getData.list.length; rawData.value[key].isLast = getData.is_last; diff --git a/src/pages/common/PostForum.vue b/src/pages/common/PostForum.vue index 2a06e049..9368ef19 100644 --- a/src/pages/common/PostForum.vue +++ b/src/pages/common/PostForum.vue @@ -73,6 +73,7 @@ import ToPostSearch from "../../components/post/to-postSearch.vue"; import Mys from "../../plugins/Mys/index.js"; import TGLogger from "../../utils/TGLogger.js"; import { createPost } from "../../utils/TGWindow.js"; +import { getGameName } from "../../web/utils/tools.js"; type SortSelect = { text: string; @@ -184,9 +185,9 @@ const search = ref(""); const showSearch = ref(false); onMounted(async () => { - showLoading.start("正在获取帖子数据..."); if (gid && typeof gid === "string") curGid.value = Number(gid); if (forum && typeof forum === "string") curForum.value = Number(forum); + showLoading.start(`正在获取${getGameName(curGid.value)}帖子数据...`); const gameLabel = getGameLabel(curGid.value); const forumLabel = getForumLabel(curGid.value, curForum.value); await TGLogger.Info(`[Posts][${gameLabel}][onMounted][${forumLabel}] 打开帖子列表`); diff --git a/src/plugins/Mys/request/doCaptchaLogin.ts b/src/plugins/Mys/request/doCaptchaLogin.ts index a35377e2..489bef69 100644 --- a/src/plugins/Mys/request/doCaptchaLogin.ts +++ b/src/plugins/Mys/request/doCaptchaLogin.ts @@ -63,7 +63,7 @@ export async function getCaptcha( "user-agent": TGConstant.BBS.UA_MOBILE, "content-type": "application/json", referer: "https://user.miyoushe.com/", - "x-rpc-game_biz": TGConstant.Utils.GAME_BIZ, + "x-rpc-game_biz": TGConstant.GAME_BIZ, }; const resp = await TGHttp< TGApp.Plugins.Mys.CaptchaLogin.CaptchaResponse | TGApp.BBS.Response.Base diff --git a/src/views/t-anno-json.vue b/src/views/t-anno-json.vue index 37620919..a2e8fdf9 100644 --- a/src/views/t-anno-json.vue +++ b/src/views/t-anno-json.vue @@ -8,7 +8,7 @@ diff --git a/src/web/constant/TGConstant.ts b/src/web/constant/TGConstant.ts index c9e8e31c..6f16a56d 100644 --- a/src/web/constant/TGConstant.ts +++ b/src/web/constant/TGConstant.ts @@ -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; diff --git a/src/web/constant/server.ts b/src/web/constant/server.ts deleted file mode 100644 index d15339ad..00000000 --- a/src/web/constant/server.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file web constant server.ts - * @description 服务器地址常量文件 - * @author BTMuli - * @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; diff --git a/src/web/request/genAuthkey.ts b/src/web/request/genAuthkey.ts index 3ec1071c..6e1bea17 100644 --- a/src/web/request/genAuthkey.ts +++ b/src/web/request/genAuthkey.ts @@ -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(url, { method: "POST", headers: header, @@ -49,7 +49,7 @@ export async function genAuthkey2( payload: Record, ): Promise { 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(url, { method: "POST", headers: header, diff --git a/src/web/request/getAbyss.ts b/src/web/request/getAbyss.ts index 72e27554..ce36fd5e 100644 --- a/src/web/request/getAbyss.ts +++ b/src/web/request/getAbyss.ts @@ -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(url, { method: "GET", headers: header, diff --git a/src/web/request/getActionTicket.ts b/src/web/request/getActionTicket.ts index 12d3f85d..81f7e6dc 100644 --- a/src/web/request/getActionTicket.ts +++ b/src/web/request/getActionTicket.ts @@ -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(url, { method: "GET", headers: header, diff --git a/src/web/request/getAvatarDetail.ts b/src/web/request/getAvatarDetail.ts index 181a26f1..7c880ff4 100644 --- a/src/web/request/getAvatarDetail.ts +++ b/src/web/request/getAvatarDetail.ts @@ -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(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(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(url, { method: "POST", body: JSON.stringify(data), diff --git a/src/web/request/getCookieToken.ts b/src/web/request/getCookieToken.ts index 850c2522..f981f4d5 100644 --- a/src/web/request/getCookieToken.ts +++ b/src/web/request/getCookieToken.ts @@ -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( url, { diff --git a/src/web/request/getGameAccounts.ts b/src/web/request/getGameAccounts.ts index 4bb70c1e..cc44f8a3 100644 --- a/src/web/request/getGameAccounts.ts +++ b/src/web/request/getGameAccounts.ts @@ -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 { 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 { 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, params: Record, ): Promise { - const header = TGUtils.User.getHeader(cookie, "GET", params, "common"); + const header = getRequestHeader(cookie, "GET", params, "common"); const resp = await TGHttp(url, { method: "GET", headers: header, diff --git a/src/web/request/getGameRecord.ts b/src/web/request/getGameRecord.ts index 4379daea..adc510e2 100644 --- a/src/web/request/getGameRecord.ts +++ b/src/web/request/getGameRecord.ts @@ -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 { 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(url, { method: "GET", headers: header, diff --git a/src/web/request/getLToken.ts b/src/web/request/getLToken.ts index 344a64fd..02cc7b84 100644 --- a/src/web/request/getLToken.ts +++ b/src/web/request/getLToken.ts @@ -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(url, { method: "GET", headers: header, diff --git a/src/web/request/getRoleCombat.ts b/src/web/request/getRoleCombat.ts index 4cafe72c..cf3ce872 100644 --- a/src/web/request/getRoleCombat.ts +++ b/src/web/request/getRoleCombat.ts @@ -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(url, { method: "GET", headers: header, diff --git a/src/web/request/getUserCollect.ts b/src/web/request/getUserCollect.ts index 4d90d97d..57536b4c 100644 --- a/src/web/request/getUserCollect.ts +++ b/src/web/request/getUserCollect.ts @@ -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 { 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(url, { method: "GET", headers: header, diff --git a/src/web/request/getUserInfo.ts b/src/web/request/getUserInfo.ts index 55b58a41..e733ce41 100644 --- a/src/web/request/getUserInfo.ts +++ b/src/web/request/getUserInfo.ts @@ -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(url, { method: "GET", headers: header, diff --git a/src/web/request/verifyLToken.ts b/src/web/request/verifyLToken.ts index aab5ddb0..4dacab9b 100644 --- a/src/web/request/verifyLToken.ts +++ b/src/web/request/verifyLToken.ts @@ -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( url, { diff --git a/src/web/utils/TGUtils.ts b/src/web/utils/TGUtils.ts deleted file mode 100644 index 04e30f1d..00000000 --- a/src/web/utils/TGUtils.ts +++ /dev/null @@ -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; diff --git a/src/web/utils/annoParser.ts b/src/web/utils/annoParser.ts index 704d989a..241af2e9 100644 --- a/src/web/utils/annoParser.ts +++ b/src/web/utils/annoParser.ts @@ -207,7 +207,7 @@ function parseAnnoNode( /** * @description 解析公告段落 - * @since Beta v0.5.5 + * @since Beta v0.6.3 * @param {HTMLElement} p - 段落元素 * @param {Record} 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); diff --git a/src/web/utils/tools.ts b/src/web/utils/tools.ts index c5b32e81..3719e336 100644 --- a/src/web/utils/tools.ts +++ b/src/web/utils/tools.ts @@ -56,30 +56,11 @@ export function transParams(obj: Record= "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 : "未知游戏"; }