mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
refactor(Mys): request 跟 utils 拿出来了
This commit is contained in:
31
src/plugins/Mys/request/gacha.ts
Normal file
31
src/plugins/Mys/request/gacha.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @file plugins Mys request gacha.ts
|
||||
* @description Mys抽卡请求
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { GachaResponse, GachaData } from "../interface/gacha";
|
||||
|
||||
// 卡池 API
|
||||
const GACHA_POOL_API =
|
||||
"https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
|
||||
|
||||
/**
|
||||
* @description 获取卡池信息
|
||||
* @since Alpha
|
||||
* @return {Promise<GachaData[]>}
|
||||
*/
|
||||
export async function getGachaData(): Promise<GachaData[]> {
|
||||
return await http
|
||||
.fetch<GachaResponse>(GACHA_POOL_API, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.list;
|
||||
});
|
||||
}
|
||||
70
src/plugins/Mys/request/news.ts
Normal file
70
src/plugins/Mys/request/news.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @file plugins Mys request news.ts
|
||||
* @description Mys 插件咨讯请求
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
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}";
|
||||
|
||||
/**
|
||||
* @description 咨讯类型
|
||||
* @enum NewsType
|
||||
* @since Alpha
|
||||
* @property {string} NOTICE 公告
|
||||
* @property {string} ACTIVITY 活动
|
||||
* @property {string} NEWS 咨讯
|
||||
* @return {NewsType}
|
||||
*/
|
||||
enum NewsType {
|
||||
NOTICE = "1",
|
||||
ACTIVITY = "2",
|
||||
NEWS = "3",
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 Notice 列表
|
||||
* @since Alpha
|
||||
* @param {number} page_size 返回数量
|
||||
* @return {Promise<NewsData>}
|
||||
*/
|
||||
export async function getNoticeList(page_size: number = 20): Promise<NewsData> {
|
||||
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString()).replace(
|
||||
"{news_type}",
|
||||
NewsType.NOTICE
|
||||
);
|
||||
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 Activity 列表
|
||||
* @since Alpha
|
||||
* @param {number} page_size 返回数量
|
||||
* @return {Promise<NewsData>}
|
||||
*/
|
||||
export async function getActivityList(page_size: number = 20): Promise<NewsData> {
|
||||
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString()).replace(
|
||||
"{news_type}",
|
||||
NewsType.ACTIVITY
|
||||
);
|
||||
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 News 列表
|
||||
* @since Alpha
|
||||
* @param {number} page_size 返回数量
|
||||
* @return {Promise<NewsData>}
|
||||
*/
|
||||
export async function getNewsList(page_size: number = 20): Promise<NewsData> {
|
||||
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString()).replace(
|
||||
"{news_type}",
|
||||
NewsType.NEWS
|
||||
);
|
||||
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
|
||||
}
|
||||
33
src/plugins/Mys/request/post.ts
Normal file
33
src/plugins/Mys/request/post.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file plugins Mys request post.ts
|
||||
* @description Mys帖子请求
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha
|
||||
*/
|
||||
|
||||
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}";
|
||||
|
||||
/**
|
||||
* @description 获取帖子信息
|
||||
* @since Alpha
|
||||
* @param {number} post_id 帖子 ID
|
||||
* @return {Promise<PostData>}
|
||||
*/
|
||||
export async function getPostData(post_id: number): Promise<PostData> {
|
||||
return await http
|
||||
.fetch<PostResponse>(POST_API.replace("{post_id}", post_id.toString()), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Referer: POST_REFERER.replace("{post_id}", post_id.toString()),
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.post;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user