♻️ 米社请求重构

This commit is contained in:
目棃
2024-04-04 15:14:19 +08:00
parent 54e941504d
commit 623d137457
11 changed files with 109 additions and 76 deletions

View File

@@ -1,23 +1,12 @@
/**
* @file plugins/Mys/api/index.ts
* @description Mys API
* @since Beta v0.3.9
* @since Beta v0.4.5
*/
const MysApi = {
Obc: "https://bbs.mihoyo.com/ys/obc/content/{contentId}/detail?bbs_presentation_style=no_header",
Gacha: "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc",
Lottery: "https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show?id={lotteryId}",
News: "https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids={gid}&page_size={pageSize}&type={newsType}&last_id={lastId}",
Forum:
"https://bbs-api.miyoushe.com/post/wapi/getForumPostList?forum_id={forum}&sort_type={type}",
Feed: "https://bbs-api.miyoushe.com/post/api/feeds/posts?gids={gid}",
Navigator: "https://bbs-api.miyoushe.com/apihub/api/home/new?gids={gid}",
Position: "https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/position?app_sn=ys_obc",
Post: {
Api: "https://bbs-api.mihoyo.com/post/wapi/getPostFull?post_id={postId}",
Referer: "https://bbs.mihoyo.com/",
},
PostReferer: "https://bbs.mihoyo.com/",
};
export default MysApi;

View File

@@ -12,7 +12,7 @@ import getGachaData from "./request/getGachaData";
import getHomeNavigator from "./request/getHomeNavigator";
import getLotteryData from "./request/getLotteryData";
import getNewsList from "./request/getNewsList";
import getPositionData from "./request/getPositionData";
import { getPositionData } from "./request/getPositionData";
import getPostData from "./request/getPostData";
import { getVoteInfo, getVoteResult } from "./request/getVoteData";
import { getGachaCard } from "./utils/getGachaCard";

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/request/getCollectionPosts.ts
* @description Mys 获取合集帖子
* @since Beta v0.3.9
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
@@ -10,7 +10,7 @@ import MysApi from "../api";
/**
* @description 获取合集信息
* @since Beta v0.3.9
* @since Beta v0.4.5
* @todo invalid request
* @param {number} collectionId 合集 ID
* @returns {Promise<TGApp.Plugins.Mys.Collection.ResponseData>} 合集信息
@@ -18,15 +18,18 @@ import MysApi from "../api";
export async function getCollectionData(
collectionId: number,
): Promise<TGApp.Plugins.Mys.Collection.ResponseData> {
const url = `https://bbs-api.miyoushe.com/collection/wapi/collection/detail?id=${collectionId}`;
console.log(url);
const url = "https://bbs-api.miyoushe.com/collection/wapi/collection/detail";
const params = {
id: collectionId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.Collection.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
Referer: MysApi.PostReferer,
},
query: params,
})
.then((res) => {
console.log(res.data);
@@ -36,21 +39,25 @@ export async function getCollectionData(
/**
* @description 获取合集帖子
* @since Beta v0.3.9
* @since Beta v0.4.5
* @param {string} collectionId 合集 ID
* @returns {Promise<TGApp.Plugins.Mys.Post.FullData[]>}
*/
export async function getCollectionPosts(
collectionId: string,
): Promise<TGApp.Plugins.Mys.Collection.Data[]> {
const url = `https://bbs-api.miyoushe.com/post/wapi/getPostFullInCollection?collection_id=${collectionId}`;
const url = "https://bbs-api.miyoushe.com/post/wapi/getPostFullInCollection";
const params = {
collection_id: collectionId,
};
return await http
.fetch<TGApp.Plugins.Mys.Collection.ResponsePosts>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
Referer: MysApi.PostReferer,
},
query: params,
})
.then((res) => {
return res.data.data.posts;

View File

@@ -1,16 +1,14 @@
/**
* @file plugins/Mys/request/getForumList.ts
* @description Mys 插件特定论坛请求
* @since Beta v0.3.7
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取特定论坛列表
* @since Beta v0.3.9
* @since Beta v0.4.5
* @param {number} forumId 特定论坛 ID
* @param {number} type 排序方式: 0-按热度排序1-最新回复2-按时间排序
* @return {Promise<TGApp.Plugins.Mys.Forum.FullData>}
@@ -19,11 +17,20 @@ async function getForumList(
forumId: number,
type: number = 0,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
const url = MysApi.Forum.replace("{forum}", forumId.toString()).replace(
"{type}",
type.toString(),
);
return await http.fetch<TGApp.Plugins.Mys.Forum.Response>(url).then((res) => res.data.data);
const url = "https://bbs-api.miyoushe.com/post/wapi/getForumPostList";
const params = {
forum_id: forumId.toString(),
sort_type: type.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.Forum.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data);
}
export default getForumList;

View File

@@ -1,21 +1,20 @@
/**
* @file plugins Mys request getGachaData.ts
* @file plugins/Mys/request/getGachaData.ts
* @description Mys 抽卡请求
* @since Alpha v0.2.1
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取卡池信息
* @since Alpha v0.2.1
* @since Beta v0.4.5
* @return {Promise<TGApp.Plugins.Mys.Gacha.Data[]>}
*/
async function getGachaData(): Promise<TGApp.Plugins.Mys.Gacha.Data[]> {
const url = "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
return await http
.fetch<TGApp.Plugins.Mys.Gacha.Response>(MysApi.Gacha, {
.fetch<TGApp.Plugins.Mys.Gacha.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",

View File

@@ -1,23 +1,30 @@
/**
* @file plugins/Mys/request/getHomeNavigator.ts
* @description Mys 插件首页导航请求
* @since Beta v0.3.7
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取首页导航列表
* @since Beta v0.3.7
* @since Beta v0.4.5
* @param {number} gid GID
* @return {Promise<TGApp.BBS.Navigator.Navigator[]>}
*/
async function getHomeNavigator(gid: number = 2): Promise<TGApp.BBS.Navigator.Navigator[]> {
const url = MysApi.Navigator.replace("{gid}", gid.toString());
const url = "https://bbs-api.miyoushe.com/apihub/api/home/new";
const params = {
gids: gid.toString(),
};
return await http
.fetch<TGApp.BBS.Navigator.HomeResponse>(url)
.fetch<TGApp.BBS.Navigator.HomeResponse>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data.navigator);
}

View File

@@ -6,8 +6,6 @@
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取抽奖信息
* @since Beta v0.4.5
@@ -17,12 +15,17 @@ import MysApi from "../api";
async function getLotteryData(
lotteryId: string,
): Promise<TGApp.BBS.Response.Base | TGApp.Plugins.Mys.Lottery.FullData> {
const url = "https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show";
const params = {
id: lotteryId,
};
return await http
.fetch<TGApp.Plugins.Mys.Lottery.Response>(MysApi.Lottery.replace("{lotteryId}", lotteryId), {
.fetch<TGApp.Plugins.Mys.Lottery.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;

View File

@@ -1,16 +1,14 @@
/**
* @file plugins Mys request getNewsList.ts
* @file plugins/Mys/request/getNewsList.ts
* @description Mys 插件咨讯请求
* @since Alpha v0.2.1
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取 News 列表
* @since Alpha v0.2.1
* @since Beta v0.4.5
* @param {string} gid GID
* @param {string} newsType 咨讯类型: 1 为公告2 为活动3 为咨讯
* @param {number} pageSize 返回数量
@@ -23,11 +21,22 @@ async function getNewsList(
pageSize: number = 20,
lastId: number = 0,
): Promise<TGApp.Plugins.Mys.News.FullData> {
const url = MysApi.News.replace("{pageSize}", pageSize.toString())
.replace("{gid}", gid)
.replace("{newsType}", newsType)
.replace("{lastId}", lastId.toString());
return await http.fetch<TGApp.Plugins.Mys.News.Response>(url).then((res) => res.data.data);
const url = "https://bbs-api.mihoyo.com/post/wapi/getNewsList";
const params = {
gids: gid,
page_size: pageSize.toString(),
type: newsType,
last_id: lastId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.News.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data);
}
export default getNewsList;

View File

@@ -1,13 +1,11 @@
/**
* @file plugins Mys request getPositionData.ts
* @file plugins/Mys/request/getPositionData.ts
* @description Mys 插件热点追踪请求
* @since Alpha v0.2.1
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 深度优先遍历
* @since Alpha v0.2.1
@@ -29,12 +27,14 @@ function DfsObc(list: TGApp.Plugins.Mys.Position.ObcItem[]): TGApp.Plugins.Mys.P
/**
* @description 获取热点追踪信息
* @since Alpha v0.2.1
* @since Beta v0.4.5
* @return {Promise<TGApp.Plugins.Mys.Position.Data[]>}
*/
async function getPositionData(): Promise<TGApp.Plugins.Mys.Position.Data[]> {
export async function getPositionData(): Promise<TGApp.Plugins.Mys.Position.Data[]> {
const url =
"https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/position?app_sn=ys_obc";
const res = await http
.fetch<TGApp.Plugins.Mys.Position.Response>(MysApi.Position, {
.fetch<TGApp.Plugins.Mys.Position.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -45,5 +45,3 @@ async function getPositionData(): Promise<TGApp.Plugins.Mys.Position.Data[]> {
});
return DfsObc(res);
}
export default getPositionData;

View File

@@ -1,7 +1,7 @@
/**
* @file plugins Mys request getPostData.ts
* @description Mys帖子请求
* @since Alpha v0.2.1
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
@@ -10,19 +10,23 @@ import MysApi from "../api";
/**
* @description 获取帖子信息
* @since Alpha v0.2.1
* @since Beta v0.4.5
* @param {number} postId 帖子 ID
* @return {Promise<TGApp.Plugins.Mys.Post.FullData>}
*/
async function getPostData(postId: number): Promise<TGApp.Plugins.Mys.Post.FullData> {
const url = MysApi.Post.Api.replace("{postId}", postId.toString());
const url = "https://bbs-api.mihoyo.com/post/wapi/getPostFull";
const params = {
post_id: postId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.Post.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
Referer: MysApi.PostReferer,
},
query: params,
})
.then((res) => {
return res.data.data.post;

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/request/getVoteData.ts
* @description Mys 插件投票请求
* @since Beta v0.3.9
* @since Beta v0.4.5
*/
import { http } from "@tauri-apps/api";
@@ -10,20 +10,25 @@ import MysApi from "../api";
/**
* @description 获取投票信息
* @since Beta v0.3.9
* @since Beta v0.4.5
* @param {string} id 投票 ID
* @param {string} uid 用户 ID
* @return {Promise<TGApp.Plugins.Mys.Vote.Info>}
*/
export async function getVoteInfo(id: string, uid: string): Promise<TGApp.Plugins.Mys.Vote.Info> {
const url = `https://bbs-api.miyoushe.com/apihub/api/getVotes?owner_uid=${uid}&vote_ids=${id}`;
const url = "https://bbs-api.miyoushe.com/apihub/api/getVotes";
const params = {
owner_uid: uid,
vote_ids: id,
};
return await http
.fetch<TGApp.Plugins.Mys.Vote.InfoResponse>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
Referer: MysApi.PostReferer,
},
query: params,
})
.then((res) => {
return res.data.data.data[0];
@@ -32,7 +37,7 @@ export async function getVoteInfo(id: string, uid: string): Promise<TGApp.Plugin
/**
* @description 获取投票结果
* @since Beta v0.3.9
* @since Beta v0.4.5
* @param {string} id 投票 ID
* @param {string} uid 用户 ID
* @return {Promise<TGApp.Plugins.Mys.Vote.Result>}
@@ -41,14 +46,19 @@ export async function getVoteResult(
id: string,
uid: string,
): Promise<TGApp.Plugins.Mys.Vote.Result> {
const url = `https://bbs-api.miyoushe.com/apihub/api/getVotesResult?owner_uid=${uid}&vote_ids=${id}`;
const url = "https://bbs-api.miyoushe.com/apihub/api/getVotesResult";
const params = {
owner_uid: uid,
vote_ids: id,
};
return await http
.fetch<TGApp.Plugins.Mys.Vote.ResultResponse>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
Referer: MysApi.PostReferer,
},
query: params,
})
.then((res) => {
return res.data.data.data[0];