feat(sidebar): 支持各种游戏咨讯获取

Signed-off-by: BTMuli <BT-Muli@outlook.com>
This commit is contained in:
BTMuli
2023-04-05 12:20:40 +08:00
parent f8a2343d28
commit 1fafbd4612
8 changed files with 173 additions and 90 deletions

View File

@@ -2,7 +2,7 @@
* @file plugins Mys request news.ts
* @description Mys 插件咨讯请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
@@ -10,7 +10,7 @@ import { NewsData, NewsResponse } from "../interface/news";
// 咨讯 API
const NEWS_LIST_API =
"https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&page_size={page_size}&type={news_type}&last_id={last_id}";
"https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids={gid}&page_size={page_size}&type={news_type}&last_id={last_id}";
/**
* @description 咨讯类型
@@ -29,16 +29,19 @@ enum NewsType {
/**
* @description 获取 Notice 列表
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getNoticeList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NOTICE)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
@@ -46,16 +49,19 @@ export async function getNoticeList(
/**
* @description 获取 Activity 列表
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getActivityList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.ACTIVITY)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
@@ -63,13 +69,19 @@ export async function getActivityList(
/**
* @description 获取 News 列表
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getNewsList(page_size: number = 20, last_id: number = 0): Promise<NewsData> {
export async function getNewsList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NEWS)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);

View File

@@ -2,19 +2,19 @@
* @file plugins Mys request post.ts
* @description Mys帖子请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { PostResponse, PostData } from "../interface/post";
// 帖子 API
const POST_API = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id={post_id}";
const POST_REFERER = "https://bbs.mihoyo.com/ys/article/{post_id}";
const POST_API = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?post_id={post_id}";
const POST_REFERER = "https://bbs.mihoyo.com/";
/**
* @description 获取帖子信息
* @since Alpha
* @since Alpha v0.1.2
* @param {number} post_id 帖子 ID
* @return {Promise<PostData>}
*/
@@ -24,7 +24,7 @@ export async function getPostData(post_id: number): Promise<PostData> {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: POST_REFERER.replace("{post_id}", post_id.toString()),
Referer: POST_REFERER,
},
})
.then(res => {