From c9f74537b01af88d0c0ff6ed0f4dbfb6bba05348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Fri, 17 Jan 2025 16:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E5=8A=A8=E6=80=81=E8=8E=B7=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=83=A8=E5=88=86=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/pageNews/to-channel.vue | 25 ++++--- src/components/viewPost/vp-overlay-search.vue | 9 ++- src/pages/common/PageHome.vue | 25 ++++--- src/pages/common/PostForum.vue | 19 +++-- src/pages/common/PostNews.vue | 8 +- src/pages/common/PostTopic.vue | 33 +++++--- src/plugins/Mys/request/doCaptchaLogin.ts | 10 +-- src/types/BBS/Game.d.ts | 52 +++++++++++++ src/utils/TGBbs.ts | 49 ++++++++++++ src/utils/TGClient.ts | 6 +- src/utils/linkParser.ts | 4 +- src/utils/toolFunc.ts | 34 --------- src/views/t-post.vue | 10 +-- src/web/constant/TGConstant.ts | 13 ---- src/web/constant/bbs.ts | 75 ------------------- src/web/request/apiHubReq.ts | 15 ++++ src/web/request/otherReq.ts | 8 +- src/web/utils/getRequestHeader.ts | 6 +- 18 files changed, 216 insertions(+), 185 deletions(-) create mode 100644 src/types/BBS/Game.d.ts create mode 100644 src/utils/TGBbs.ts delete mode 100644 src/web/constant/TGConstant.ts delete mode 100644 src/web/constant/bbs.ts diff --git a/src/components/pageNews/to-channel.vue b/src/components/pageNews/to-channel.vue index e04230fb..33d91923 100644 --- a/src/components/pageNews/to-channel.vue +++ b/src/components/pageNews/to-channel.vue @@ -7,10 +7,10 @@ v-for="(item, index) in channelList" :key="index" class="toc-list-item" - :class="{ active: props.gid === item.gid }" + :class="props.gid === item.gid.toString() ? 'active' : ''" @click="toChannel(item)" > - icon + {{ item.title }} @@ -18,25 +18,30 @@ diff --git a/src/plugins/Mys/request/doCaptchaLogin.ts b/src/plugins/Mys/request/doCaptchaLogin.ts index a43cf750..12302ae4 100644 --- a/src/plugins/Mys/request/doCaptchaLogin.ts +++ b/src/plugins/Mys/request/doCaptchaLogin.ts @@ -7,9 +7,9 @@ import showSnackbar from "@comp/func/snackbar.js"; import { JSEncrypt } from "jsencrypt"; +import TGBbs from "@/utils/TGBbs.js"; import TGHttp from "@/utils/TGHttp.js"; import { getDeviceInfo } from "@/utils/toolFunc.js"; -import TGConstant from "@/web/constant/TGConstant.js"; const PUB_KEY_STR: Readonly = `-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNKqdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs @@ -53,14 +53,14 @@ export async function getCaptcha( const body = { area_code: rsaEncrypt("+86"), mobile: rsaEncrypt(phone) }; const header: Record = { "x-rpc-aigis": aigis || "", - "x-rpc-app_version": TGConstant.BBS.VERSION, + "x-rpc-app_version": TGBbs.version, "x-rpc-client_type": "2", "x-rpc-app_id": "bll8iq97cem8", "x-rpc-device_fp": device_fp, "x-rpc-device_name": device_name, "x-rpc-device_id": device_id, "x-rpc-device_model": device_model, - "user-agent": TGConstant.BBS.UA_MOBILE, + "user-agent": TGBbs.ua, "content-type": "application/json", referer: "https://user.miyoushe.com/", "x-rpc-game_biz": "hk4e_cn", @@ -115,14 +115,14 @@ export async function doCaptchaLogin( }; const header = { "x-rpc-aigis": aigis || "", - "x-rpc-app_version": TGConstant.BBS.VERSION, + "x-rpc-app_version": TGBbs.version, "x-rpc-client_type": "2", "x-rpc-app_id": "bll8iq97cem8", "x-rpc-device_fp": device_fp, "x-rpc-device_name": device_name, "x-rpc-device_id": device_id, "x-rpc-device_model": device_model, - "user-agent": TGConstant.BBS.UA_MOBILE, + "user-agent": TGBbs.ua, }; const resp = await TGHttp( url, diff --git a/src/types/BBS/Game.d.ts b/src/types/BBS/Game.d.ts new file mode 100644 index 00000000..42ae7698 --- /dev/null +++ b/src/types/BBS/Game.d.ts @@ -0,0 +1,52 @@ +/** + * @file types/BBS/Game.d.ts + * @description 游戏相关的类型定义 + * @since Beta v0.6.8 + */ + +declare namespace TGApp.BBS.Game { + /** + * @description 游戏列表返回 + * @since Beta v0.6.8 + * @interface ListResp + * @extends TGApp.BBS.Response.BaseWithData + * @property {Array} data.list 游戏列表 + * @return ListResp + */ + type ListResp = TGApp.BBS.Response.BaseWithData & { data: { list: Array } }; + + /** + * @description 游戏列表项 + * @since Beta v0.6.8 + * @interface Item + * @property {number} id 游戏 ID + * @property {string} name 游戏名称 + * @property {string} en_name 游戏英文名称 + * @property {string} app_icon 游戏图标 + * @property {string} icon 游戏图标 + * @property {string} search_trend_word 搜索热词 + * @property {string} level_image 游戏等级图标 + * @property {string} level_text_color 游戏等级文字颜色 + * @property {number} topic_num 游戏话题数 + * @property {string} op_name 运营名称 + * @property {string} main_color 主色调 AB9756 + * @property {boolean} has_wiki 是否有百科 + * @property {Array} game_sort_config 游戏分类配置 + * @return Item + */ + type Item = { + id: number; + name: string; + en_name: string; + app_icon: string; + icon: string; + search_trend_word: string; + level_image: string; + level_text_color: string; + topic_num: number; + op_name: string; + main_color: string; + has_wiki: boolean; + game_sort_config: Array; + }; +} diff --git a/src/utils/TGBbs.ts b/src/utils/TGBbs.ts new file mode 100644 index 00000000..4a70c61b --- /dev/null +++ b/src/utils/TGBbs.ts @@ -0,0 +1,49 @@ +/** + * @file utils/TGBbs.ts + * @description 关于 BBS 的工具函数 + * @since Beta v0.6.8 + */ + +const BBS_VERSION: Readonly = "2.80.1"; +const BBS_UA_MOBILE: Readonly = `Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/${BBS_VERSION}`; + +/** + * @description 频道列表 + * @since Beta v0.6.8 + * @interface ChannelItem + * @property {string} title - 频道名称 + * @property {number} gid - 频道 gid + * @property {string} mini - 频道简称 + * @return ToChannelItem + */ +type ChannelItem = { title: string; gid: number; mini: string }; + +/** + * @description 渠道列表 + * @since Beta v0.6.8 + * @type {Array} + */ +const CHANNEL_LIST: Readonly> = [ + { title: "原神", gid: 2, mini: "ys" }, + { title: "崩坏:星穹铁道", gid: 6, mini: "sr" }, + { title: "绝区零", gid: 8, mini: "zzz" }, + { title: "崩坏3", gid: 1, mini: "bh3" }, + { title: "崩坏2", gid: 3, mini: "bh2" }, + { title: "未定事件簿", gid: 4, mini: "wd" }, + { title: "大别野", gid: 5, mini: "dby" }, +]; + +/** + * @description 获取游戏id + * @since Beta v0.6.8 + * @param {string} mini + * @returns {string} + */ +export function getGameId(mini: string): number { + const game = CHANNEL_LIST.find((item) => item.mini === mini); + return game ? game.gid : 0; +} + +const TGBbs = { version: BBS_VERSION, ua: BBS_UA_MOBILE, channels: CHANNEL_LIST }; + +export default TGBbs; diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index 89166944..2b326472 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -16,7 +16,7 @@ import { getDeviceInfo } from "./toolFunc.js"; import { useAppStore } from "@/store/modules/app.js"; import { useUserStore } from "@/store/modules/user.js"; -import TGConstant from "@/web/constant/TGConstant.js"; +import TGBbs from "@/utils/TGBbs.js"; import BBSApi from "@/web/request/bbsReq.js"; import OtherApi from "@/web/request/otherReq.js"; import PassportApi from "@/web/request/passportReq.js"; @@ -623,10 +623,10 @@ class Client { let deviceInfo = useAppStore().deviceInfo; if (localFp === "0000000000000") deviceInfo = await OtherApi.fp(deviceInfo); const data = { - "user-agent": TGConstant.BBS.UA_MOBILE, + "user-agent": TGBbs.ua, "x-rpc-client_type": "2", "x-rpc-device_id": deviceInfo.device_id, - "x-rpc-app_version": TGConstant.BBS.VERSION, + "x-rpc-app_version": TGBbs.version, "x-rpc-device_fp": deviceInfo.device_fp, }; await this.callback(arg.callback, data); diff --git a/src/utils/linkParser.ts b/src/utils/linkParser.ts index fd271dbf..e7476fd7 100644 --- a/src/utils/linkParser.ts +++ b/src/utils/linkParser.ts @@ -11,7 +11,7 @@ import { emit } from "@tauri-apps/api/event"; import TGClient from "./TGClient.js"; import { createPost } from "./TGWindow.js"; -import { getGameId } from "@/utils/toolFunc.js"; +import TGBbs from "@/utils/TGBbs.js"; /** * @function parsePost @@ -124,7 +124,7 @@ export async function parseLink( const result = url.pathname.match(regex); if (!result) return false; const [, game, topicId] = result; - const id = getGameId(game); + const id = TGBbs.channels.find((item) => item.mini === game)?.gid; await emit("active_deep_link", `router?path=/posts/topic/${id}/${topicId}`); return true; } diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index 53d7d6d6..df67bb56 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -12,7 +12,6 @@ import { v4 } from "uuid"; import { score } from "wcag-color"; import { AppCharacterData, AppWeaponData } from "@/data/index.js"; -import TGConstant from "@/web/constant/TGConstant.js"; /** * @description 时间戳转换为时间字符串 @@ -273,39 +272,6 @@ export function decodeRegExp(data: string): string { return res; } -/** - * @description 根据 gid 获取游戏名称 - * @since Beta v0.6.7 - * @param {number} gid - * @returns {string} - */ -export function getGameName(gid: number): string { - const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString()); - return game ? game.title : "未知游戏"; -} - -/** - * @description 获取游戏id - * @since Beta v0.6.7 - * @param {string} mini - * @returns {string} - */ -export function getGameId(mini: string): string { - const game = TGConstant.BBS.CHANNELS.find((item) => item.mini === mini); - return game ? game.gid : "0"; -} - -/** - * @description 根据id获取游戏图标 - * @since Beta v0.6.8 - * @param {number|string} gid - * @returns {string|undefined} - */ -export function getGameIcon(gid: number | string): string | undefined { - const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString()); - return game ? game.icon : undefined; -} - /** * @description 根据id获取对应角色/武器数据 * @since Beta v0.6.8 diff --git a/src/views/t-post.vue b/src/views/t-post.vue index 0e23c3ad..48cfa933 100644 --- a/src/views/t-post.vue +++ b/src/views/t-post.vue @@ -101,10 +101,9 @@ import { onMounted, onUnmounted, ref, shallowRef } from "vue"; import { useRoute } from "vue-router"; import { useAppStore } from "@/store/modules/app.js"; +import TGBbs from "@/utils/TGBbs.js"; import TGLogger from "@/utils/TGLogger.js"; import { createTGWindow } from "@/utils/TGWindow.js"; -import { CHANNEL_LIST } from "@/web/constant/bbs.js"; -import TGConstant from "@/web/constant/TGConstant.js"; const appVersion = ref(); const postId = Number(useRoute().params.post_id); @@ -117,8 +116,8 @@ const postData = shallowRef(); let shareTimer: NodeJS.Timeout | null = null; function getGameIcon(gameId: number): string { - const find = TGConstant.BBS.CHANNELS.find((item) => item.gid === gameId.toString()); - if (find) return find.icon; + const find = TGBbs.channels.find((item) => item.gid === gameId); + if (find) return `/platforms/mhy/${find.mini}.webp`; return "/platforms/mhy/mys.webp"; } @@ -229,6 +228,7 @@ async function parseContent(content: string): Promise { break; default: await TGLogger.Warn(`[t-post][${postId}][parseContent] Unknown key: ${key}`); + // @ts-expect-error unknown key result.push({ insert: data[key] }); break; } @@ -243,7 +243,7 @@ async function createPostJson(postId: number): Promise { } function toPost(): void { - const channel = CHANNEL_LIST.find((item) => item.gid === postData.value?.post.game_id.toString()); + const channel = TGBbs.channels.find((item) => item.gid === postData.value?.post.game_id); if (channel) { window.open(`https://miyoushe.com/${channel.mini}/#/article/${postId}`); } else { diff --git a/src/web/constant/TGConstant.ts b/src/web/constant/TGConstant.ts deleted file mode 100644 index b4f22f12..00000000 --- a/src/web/constant/TGConstant.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @file web/constant/TGConstant.ts - * @description 常量 - * @since Beta v0.6.3 - */ - -import { BBS_UA_MOBILE, BBS_VERSION, CHANNEL_LIST } from "./bbs.js"; - -const TGConstant = { - BBS: { VERSION: BBS_VERSION, UA_MOBILE: BBS_UA_MOBILE, CHANNELS: CHANNEL_LIST }, -}; - -export default TGConstant; diff --git a/src/web/constant/bbs.ts b/src/web/constant/bbs.ts deleted file mode 100644 index 230d48ae..00000000 --- a/src/web/constant/bbs.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file web/constant/bbs.ts - * @description 常量-应用数据 - * @since Beta v0.6.8 - */ - -export const BBS_VERSION: Readonly = "2.80.1"; -export const BBS_UA_MOBILE: Readonly = `Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/${BBS_VERSION}`; - -/** - * @description 频道列表 - * @since Beta v0.6.5 - * @interface ToChannelItem - * @property {string} title - 频道名称 - * @property {string} icon - 频道图标 - * @property {string} gid - 频道 gid - * @property {string} mini - 频道简称 - * @return ToChannelItem - */ -export interface ToChannelItem { - title: string; - icon: string; - gid: string; - mini: string; -} - -/** - * @description 渠道列表 - * @since Beta v0.6.5 - * @type {Array} - */ -export const CHANNEL_LIST: Readonly> = [ - { - title: "原神", - icon: "/platforms/mhy/ys.webp", - gid: "2", - mini: "ys", - }, - { - title: "崩坏:星穹铁道", - icon: "/platforms/mhy/sr.webp", - gid: "6", - mini: "sr", - }, - { - title: "绝区零", - icon: "/platforms/mhy/zzz.webp", - gid: "8", - mini: "zzz", - }, - { - title: "崩坏3", - icon: "/platforms/mhy/bh3.webp", - gid: "1", - mini: "bh3", - }, - { - title: "崩坏2", - icon: "/platforms/mhy/bh2.webp", - gid: "3", - mini: "bh2", - }, - { - title: "未定事件簿", - icon: "/platforms/mhy/wd.webp", - gid: "4", - mini: "wd", - }, - { - title: "大别野", - icon: "/platforms/mhy/dby.webp", - gid: "5", - mini: "dby", - }, -]; diff --git a/src/web/request/apiHubReq.ts b/src/web/request/apiHubReq.ts index 78ff2956..ffba44b5 100644 --- a/src/web/request/apiHubReq.ts +++ b/src/web/request/apiHubReq.ts @@ -26,6 +26,20 @@ async function getAllGamesForums(): Promise> { ).data.list; } +/** + * @description 获取所有分区 + * @since Beta v0.6.8 + * @return {Promise>} + */ +async function getGameList(): Promise> { + return ( + await TGHttp(`${Mahwbu}getGameList`, { + method: "GET", + headers: { "Content-Type": "application/json", referer: Referer }, + }) + ).data.list; +} + /** * @description 获取投票信息 * @since Beta v0.6.2 @@ -80,6 +94,7 @@ const apiHubReq = { vote: { info: getVotes, result: getVoteResult }, home: homeNew, forum: getAllGamesForums, + game: getGameList, }; export default apiHubReq; diff --git a/src/web/request/otherReq.ts b/src/web/request/otherReq.ts index 8d75cf4a..6bbc46e1 100644 --- a/src/web/request/otherReq.ts +++ b/src/web/request/otherReq.ts @@ -1,13 +1,13 @@ /** * @file web/request/otherReq.ts * @description Other API - * @since Beta v0.6.3 + * @since Beta v0.6.8 */ +import TGBbs from "@/utils/TGBbs.js"; import TGHttp from "@/utils/TGHttp.js"; import TGLogger from "@/utils/TGLogger.js"; import { getInitDeviceInfo } from "@/utils/toolFunc.js"; -import TGConstant from "@/web/constant/TGConstant.js"; /** * @description 获取设备指纹 @@ -85,8 +85,8 @@ async function getDeviceFp( device_fp: info.device_fp, }; const header: Record = { - "user-agent": TGConstant.BBS.UA_MOBILE, - "x-rpc-app_version": TGConstant.BBS.VERSION, + "user-agent": TGBbs.ua, + "x-rpc-app_version": TGBbs.version, "x-rpc-client_type": "5", "x-requested-with": "com.mihoyo.hyperion", Referer: "https://webstatic.mihoyo.com/", diff --git a/src/web/utils/getRequestHeader.ts b/src/web/utils/getRequestHeader.ts index 32336248..29bca0f5 100644 --- a/src/web/utils/getRequestHeader.ts +++ b/src/web/utils/getRequestHeader.ts @@ -6,8 +6,8 @@ import Md5 from "js-md5"; +import TGBbs from "@/utils/TGBbs.js"; import { getDeviceInfo, getRandomString } from "@/utils/toolFunc.js"; -import { BBS_VERSION } from "@/web/constant/bbs.js"; /** * @description salt 类型 @@ -34,7 +34,7 @@ const Salt: Readonly> = { X6: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v", PROD: "t0qEgfub6cvueAPgR5m9aQWWVciEer7v", }; -const UserAgent: Readonly = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/${BBS_VERSION}`; +const UserAgent: Readonly = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/${TGBbs.version}`; /** * @description 获取随机数 @@ -126,7 +126,7 @@ export function getRequestHeader( ): Record { return { "user-agent": UserAgent, - "x-rpc-app_version": BBS_VERSION, + "x-rpc-app_version": TGBbs.version, "x-rpc-client_type": "5", "x-requested-with": "com.mihoyo.hyperion", referer: "https://webstatic.mihoyo.com",