♻️ 部分分区动态获取,重构部分调用

This commit is contained in:
目棃
2025-01-17 16:06:36 +08:00
parent da78d27239
commit c9f74537b0
18 changed files with 216 additions and 185 deletions

49
src/utils/TGBbs.ts Normal file
View File

@@ -0,0 +1,49 @@
/**
* @file utils/TGBbs.ts
* @description 关于 BBS 的工具函数
* @since Beta v0.6.8
*/
const BBS_VERSION: Readonly<string> = "2.80.1";
const BBS_UA_MOBILE: Readonly<string> = `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<ChannelItem>}
*/
const CHANNEL_LIST: Readonly<Array<ChannelItem>> = [
{ 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;

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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