mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-03 06:55:06 +08:00
♻️ 重构部分请求
This commit is contained in:
@@ -28,7 +28,7 @@ async function getUserFullInfo(
|
||||
|
||||
/**
|
||||
* @description 根据gid和id获取用户信息
|
||||
* @since Beta v0.6.7
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} gid - gid
|
||||
* @param {string} userId - 用户 id
|
||||
* @returns {Promise<TGApp.BBS.Response.Base | TGApp.Plugins.Mys.User.Info>}
|
||||
@@ -46,41 +46,6 @@ async function getOtherUserInfo(
|
||||
return resp.data.user_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户发布帖子
|
||||
* @since Beta v0.6.7
|
||||
* @param {string} uid - 用户 uid
|
||||
* @param [string] offset - 偏移量
|
||||
* @returns {Promise<TGApp.BBS.Collection.PostRespData|TGApp.BBS.Response.Base>} 用户发布帖子
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description 获取用户收藏帖子
|
||||
* @since Beta v0.6.3
|
||||
* @param {TGApp.App.Account.Cookie} cookie - 用户 cookie
|
||||
* @param {string} uid - 用户 uid
|
||||
* @param {string} offset - 偏移量
|
||||
* @returns {Promise<TGApp.BBS.Collection.PostRespData|TGApp.BBS.Response.Base>} 用户收藏帖子
|
||||
*/
|
||||
async function userFavouritePost(
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
uid: string,
|
||||
offset: string = "",
|
||||
): Promise<TGApp.BBS.Collection.PostRespData | TGApp.BBS.Response.Base> {
|
||||
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
|
||||
const params = { size: "20", uid, offset };
|
||||
const resp = await TGHttp<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>(
|
||||
"https://bbs-api.miyoushe.com/post/wapi/userFavouritePost",
|
||||
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
const BBSApi = {
|
||||
userInfo: getUserFullInfo,
|
||||
otherUserInfo: getOtherUserInfo,
|
||||
lovePost: userFavouritePost,
|
||||
};
|
||||
const BBSApi = { userInfo: getUserFullInfo, otherUserInfo: getOtherUserInfo };
|
||||
|
||||
export default BBSApi;
|
||||
|
||||
143
src/web/request/painterReq.ts
Normal file
143
src/web/request/painterReq.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* @file web/request/painterReq.ts
|
||||
* @description painter 下的请求
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
import TGHttp from "@/utils/TGHttp.js";
|
||||
|
||||
// BBSApiPainterBaseUrl => bapBu
|
||||
const bapBu: Readonly<string> = "https://bbs-api.miyoushe.com/painter/wapi/";
|
||||
|
||||
/**
|
||||
* @description 获取 News 列表
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} gid GID
|
||||
* @param {string} newsType 咨讯类型: 1 为公告,2 为活动,3 为咨讯
|
||||
* @param {number} pageSize 返回数量
|
||||
* @param {number} lastId 上一次请求的最后一条数据的 id
|
||||
* @return {Promise<TGApp.BBS.News.Res>}
|
||||
*/
|
||||
async function getNewsList(
|
||||
gid: string = "2",
|
||||
newsType: string = "1",
|
||||
pageSize: number = 20,
|
||||
lastId: number = 0,
|
||||
): Promise<TGApp.BBS.News.Res> {
|
||||
return (
|
||||
await TGHttp<TGApp.BBS.News.Resp>(`${bapBu}getNewsList`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
query: { gids: gid, page_size: pageSize, type: newsType, last_id: lastId },
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取最近版块热门帖子列表
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} forumId 版块 ID
|
||||
* @param {number} gid 社区 ID
|
||||
* @param {number} pageSize 每页数量
|
||||
* @param {string} lastId 最后 ID
|
||||
* @return {Promise<TGApp.BBS.Forum.PostForumRes>}
|
||||
*/
|
||||
async function getHotForumPostList(
|
||||
forumId: number,
|
||||
gid: number,
|
||||
lastId?: string,
|
||||
pageSize: number = 20,
|
||||
): Promise<TGApp.BBS.Forum.PostForumRes> {
|
||||
type ReqParams = {
|
||||
forum_id: number;
|
||||
gids: number;
|
||||
page_size: number;
|
||||
is_good: boolean;
|
||||
last_id?: string;
|
||||
};
|
||||
const params: ReqParams = {
|
||||
forum_id: forumId,
|
||||
gids: gid,
|
||||
page_size: pageSize,
|
||||
is_good: false,
|
||||
};
|
||||
if (lastId) params.last_id = lastId;
|
||||
return (
|
||||
await TGHttp<TGApp.BBS.Forum.PostForumResp>(`${bapBu}getHotForumPostList`, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取最近版块帖子列表
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} forumId 版块 ID
|
||||
* @param {number} gid 社区 ID
|
||||
* @param {number} type 排序方式: 1-最新回复,2-最新发布
|
||||
* @param {string} lastId 最后 ID
|
||||
* @param {number} pageSize 每页数量
|
||||
* @return {Promise<TGApp.BBS.Forum.PostForumRes>}
|
||||
*/
|
||||
async function getRecentForumPostList(
|
||||
forumId: number,
|
||||
gid: number,
|
||||
type: number = 1,
|
||||
lastId?: string,
|
||||
pageSize: number = 20,
|
||||
): Promise<TGApp.BBS.Forum.PostForumRes> {
|
||||
type ReqParams = {
|
||||
forum_id: number;
|
||||
gids: number;
|
||||
sort_type: number;
|
||||
is_good: boolean;
|
||||
page_size: number;
|
||||
last_id?: string;
|
||||
};
|
||||
const params: ReqParams = {
|
||||
forum_id: forumId,
|
||||
gids: gid,
|
||||
sort_type: type,
|
||||
is_good: false,
|
||||
page_size: pageSize,
|
||||
};
|
||||
if (lastId) params.last_id = lastId;
|
||||
return (
|
||||
await TGHttp<TGApp.BBS.Forum.PostForumResp>(`${bapBu}getRecentForumPostList`, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取抽奖信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} lotteryId 抽奖 ID
|
||||
* @return {Promise<TGApp.BBS.Response.Base|TGApp.BBS.Lottery.FullData>}
|
||||
*/
|
||||
async function lotteryUserShow(
|
||||
lotteryId: string,
|
||||
): Promise<TGApp.BBS.Response.Base | TGApp.BBS.Lottery.FullData> {
|
||||
const resp = await TGHttp<TGApp.BBS.Response.Base | TGApp.BBS.Lottery.Resp>(
|
||||
`${bapBu}lottery/user/show`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
query: { id: lotteryId },
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.show_lottery;
|
||||
}
|
||||
|
||||
const painterReq = {
|
||||
forum: {
|
||||
hot: getHotForumPostList,
|
||||
recent: getRecentForumPostList,
|
||||
},
|
||||
lottery: lotteryUserShow,
|
||||
news: getNewsList,
|
||||
};
|
||||
|
||||
export default painterReq;
|
||||
194
src/web/request/postReq.ts
Normal file
194
src/web/request/postReq.ts
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* @file web/request/postReq.ts
|
||||
* @description 帖子相关的请求
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
import TGHttp from "@/utils/TGHttp.js";
|
||||
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
|
||||
|
||||
// BBSApiPostBaseUrl => bapBu
|
||||
const bapBu: Readonly<string> = "https://bbs-api.miyoushe.com/post/wapi/";
|
||||
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
|
||||
|
||||
/**
|
||||
* @description 获取单个帖子信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {number|string} postId 帖子 ID
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @return {Promise<TGApp.Plugins.Mys.Post.FullData|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getPostFull(
|
||||
postId: number | string,
|
||||
cookie?: Record<string, string>,
|
||||
): Promise<TGApp.Plugins.Mys.Post.FullData | TGApp.BBS.Response.Base> {
|
||||
const param = { post_id: postId, read: 1 };
|
||||
let header;
|
||||
if (cookie) {
|
||||
header = {
|
||||
...getRequestHeader(cookie, "GET", param, "K2", true),
|
||||
"x-rpc-client_type": "2",
|
||||
};
|
||||
} else header = { referer: Referer };
|
||||
const resp = await TGHttp<TGApp.Plugins.Mys.Post.Response>(`${bapBu}getPostFull`, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: param,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.post;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取合集帖子
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} collectionId 合集 ID
|
||||
* @returns {Promise<TGApp.Plugins.Mys.Post.FullData[]>}
|
||||
*/
|
||||
async function getPostFullInCollection(
|
||||
collectionId: string,
|
||||
): Promise<Array<TGApp.Plugins.Mys.Post.FullData>> {
|
||||
return (
|
||||
await TGHttp<TGApp.BBS.Collection.PostsResp>(`${bapBu}getPostFullInCollection`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json", referer: Referer },
|
||||
query: { collection_id: collectionId },
|
||||
})
|
||||
).data.posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取帖子回复信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} postId 帖子 ID
|
||||
* @param {number} gid 社区 ID
|
||||
* @param {boolean} isHot 是否热门
|
||||
* @param {boolean} onlyMaster 是否只看楼主
|
||||
* @param {number} orderType 排序类型
|
||||
* @param {string} lastId 最后 ID
|
||||
* @param {number} size 每页大小
|
||||
* @return {Promise<TGApp.BBS.Reply.MainRes|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getPostReplies(
|
||||
postId: string,
|
||||
gid: number,
|
||||
isHot: boolean = true,
|
||||
lastId?: string,
|
||||
onlyMaster: boolean = false,
|
||||
orderType?: 1 | 2,
|
||||
size: number = 20,
|
||||
): Promise<TGApp.BBS.Reply.MainRes | TGApp.BBS.Response.Base> {
|
||||
type GprParam = {
|
||||
post_id: string;
|
||||
gids: number;
|
||||
is_hot: boolean;
|
||||
size: number;
|
||||
last_id?: string;
|
||||
order_type?: 1 | 2;
|
||||
only_master?: boolean;
|
||||
};
|
||||
const params: GprParam = { post_id: postId, gids: gid, is_hot: isHot, size: size };
|
||||
if (lastId) params.last_id = lastId;
|
||||
if (orderType) params.order_type = orderType;
|
||||
if (onlyMaster) {
|
||||
params.is_hot = false;
|
||||
params.only_master = onlyMaster;
|
||||
params.order_type = 1;
|
||||
}
|
||||
const resp = await TGHttp<TGApp.BBS.Reply.MainResp>(`${bapBu}getPostReplies`, {
|
||||
method: "GET",
|
||||
headers: { referer: Referer },
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取帖子子回复信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} floorId 楼层 ID
|
||||
* @param {number} gid 社区 ID
|
||||
* @param {string} postId 帖子 ID
|
||||
* @param {string} lastId 最后 ID
|
||||
* @param {number} size 每页大小
|
||||
* @return {Promise<TGApp.BBS.Reply.SubRes|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getSubReplies(
|
||||
floorId: number,
|
||||
gid: number,
|
||||
postId: string,
|
||||
lastId?: string,
|
||||
size: number = 20,
|
||||
): Promise<TGApp.BBS.Reply.SubRes | TGApp.BBS.Response.Base> {
|
||||
type GsrParam = {
|
||||
floor_id: number;
|
||||
gids: number;
|
||||
post_id: string;
|
||||
size: number;
|
||||
last_id?: string;
|
||||
};
|
||||
const params: GsrParam = { floor_id: floorId, gids: gid, post_id: postId, size: size };
|
||||
if (lastId) params.last_id = lastId;
|
||||
const resp = await TGHttp<TGApp.BBS.Reply.SubResp>(`${bapBu}getSubReplies`, {
|
||||
method: "GET",
|
||||
headers: { referer: Referer },
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 搜索帖子
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} gid 游戏分区 ID
|
||||
* @param {string} keyword 关键词
|
||||
* @param {string} lastId 最后一条帖子 ID
|
||||
* @return {Promise<TGApp.BBS.Search.PostsRes>} 返回帖子列表
|
||||
*/
|
||||
async function searchPosts(
|
||||
gid: string = "2",
|
||||
keyword: string,
|
||||
lastId: string,
|
||||
): Promise<TGApp.BBS.Search.PostsRes> {
|
||||
return (
|
||||
await TGHttp<TGApp.BBS.Search.PostsResp>(`${bapBu}searchPosts`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
query: { gids: gid, keyword, last_id: lastId, size: 20 },
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户收藏帖子
|
||||
* @since Beta v0.6.3
|
||||
* @param {TGApp.App.Account.Cookie} cookie - 用户 cookie
|
||||
* @param {string} uid - 用户 uid
|
||||
* @param {string} offset - 偏移量
|
||||
* @returns {Promise<TGApp.BBS.Collection.UserPostRes|TGApp.BBS.Response.Base>} 用户收藏帖子
|
||||
*/
|
||||
async function userFavouritePost(
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
uid: string,
|
||||
offset: string = "",
|
||||
): Promise<TGApp.BBS.Collection.UserPostRes | TGApp.BBS.Response.Base> {
|
||||
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
|
||||
const params = { size: "20", uid, offset };
|
||||
const resp = await TGHttp<TGApp.BBS.Collection.UserPostResp | TGApp.BBS.Response.Base>(
|
||||
`${bapBu}/userFavouritePost`,
|
||||
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
const postReq = {
|
||||
collection: getPostFullInCollection,
|
||||
post: getPostFull,
|
||||
reply: { main: getPostReplies, sub: getSubReplies },
|
||||
search: searchPosts,
|
||||
userFavourite: userFavouritePost,
|
||||
};
|
||||
|
||||
export default postReq;
|
||||
67
src/web/request/topicReq.ts
Normal file
67
src/web/request/topicReq.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* @file web/request/topicReq.ts
|
||||
* @description 话题相关的请求
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
import TGHttp from "@/utils/TGHttp.js";
|
||||
|
||||
// BBSApiTopicBaseUrl => batBu
|
||||
const batBu: Readonly<string> = "https://bbs-api.miyoushe.com/topic/wapi/";
|
||||
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
|
||||
|
||||
/**
|
||||
* @description 获取特定话题信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {string} gid 游戏分区 ID
|
||||
* @param {string} topicId 话题 ID
|
||||
* @return {Promise<TGApp.BBS.Topic.InfoRes|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getTopicFullInfo(
|
||||
gid: string,
|
||||
topicId: string,
|
||||
): Promise<TGApp.BBS.Topic.InfoRes | TGApp.BBS.Response.Base> {
|
||||
const resp = await TGHttp<TGApp.BBS.Topic.InfoResp>(`${batBu}getTopicFullInfo`, {
|
||||
method: "GET",
|
||||
headers: { referer: Referer },
|
||||
query: { gids: gid, id: topicId },
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取特定话题帖子列表
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} gid 游戏分区 ID
|
||||
* @param {string} topicId 话题 ID
|
||||
* @param {string} orderType 排序方式
|
||||
* @param {string} lastId 最后一条帖子 ID
|
||||
* @param {number} size 每页大小
|
||||
* @return {Promise<TGApp.BBS.Topic.PostRes|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getTopicPostList(
|
||||
gid: number,
|
||||
topicId: string,
|
||||
orderType: number = 0,
|
||||
lastId?: string,
|
||||
size: number = 20,
|
||||
): Promise<TGApp.BBS.Topic.PostRes | TGApp.BBS.Response.Base> {
|
||||
const resp = await TGHttp<TGApp.BBS.Topic.PostResp>(`${batBu}getTopicPostList`, {
|
||||
method: "GET",
|
||||
headers: { referer: Referer },
|
||||
query: {
|
||||
gids: gid,
|
||||
game_id: gid,
|
||||
topic_id: topicId,
|
||||
list_type: orderType,
|
||||
last_id: lastId ?? "",
|
||||
page_size: size,
|
||||
},
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
const topicReq = { info: getTopicFullInfo, posts: getTopicPostList };
|
||||
|
||||
export default topicReq;
|
||||
Reference in New Issue
Block a user