🌱 浏览帖子

This commit is contained in:
目棃
2025-02-24 13:42:48 +08:00
parent 1da157abbd
commit 0f278ad25e

View File

@@ -1,10 +1,11 @@
/** /**
* @file plugins/Mys/request/postReq.ts * @file plugins/Mys/request/postReq.ts
* @description 帖子相关的获取 * @description 帖子相关的获取
* @since Beta v0.6.7 * @since Beta v0.6.10/v0.7.0
*/ */
import TGHttp from "@/utils/TGHttp.js"; import TGHttp from "@/utils/TGHttp.js";
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
// MysPostApiBaseUrl => Mpabu // MysPostApiBaseUrl => Mpabu
const Mpabu: Readonly<string> = "https://bbs-api.mihoyo.com/post/wapi/"; const Mpabu: Readonly<string> = "https://bbs-api.mihoyo.com/post/wapi/";
@@ -14,17 +15,23 @@ const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
/** /**
* @description 获取单个帖子信息 * @description 获取单个帖子信息
* @since Beta v0.6.3 * @since Beta v0.6.10/v0.7.0
* @param {number} postId 帖子 ID * @param {number} postId 帖子 ID
* @param {Record<string, string>} cookie Cookie
* @return {Promise<TGApp.Plugins.Mys.Post.FullData|TGApp.BBS.Response.Base>} * @return {Promise<TGApp.Plugins.Mys.Post.FullData|TGApp.BBS.Response.Base>}
*/ */
export async function getPostFull( export async function getPostFull(
postId: number, postId: number,
cookie?: Record<string, string>,
): Promise<TGApp.Plugins.Mys.Post.FullData | TGApp.BBS.Response.Base> { ): Promise<TGApp.Plugins.Mys.Post.FullData | TGApp.BBS.Response.Base> {
const param = { post_id: postId };
let header;
if (cookie) header = getRequestHeader(cookie, "GET", param);
else header = { referer: Referer };
const resp = await TGHttp<TGApp.Plugins.Mys.Post.Response>(`${Mpabu}getPostFull`, { const resp = await TGHttp<TGApp.Plugins.Mys.Post.Response>(`${Mpabu}getPostFull`, {
method: "GET", method: "GET",
headers: { referer: Referer }, headers: header,
query: { post_id: postId }, query: param,
}); });
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp; if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data.post; return resp.data.post;