♻️ Mys 类型重构,优化目录结构

This commit is contained in:
BTMuli
2023-06-27 21:01:24 +08:00
parent dc51257e6b
commit 99a6f38c5c
45 changed files with 1864 additions and 1902 deletions

View File

@@ -1,31 +0,0 @@
/**
* @file plugins Mys request gacha.ts
* @description Mys抽卡请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { http } from "@tauri-apps/api";
import { type GachaResponse, type 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;
});
}

View File

@@ -0,0 +1,29 @@
/**
* @file plugins Mys request getGachaData.ts
* @description Mys 抽卡请求
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取卡池信息
* @since Alpha v0.2.1
* @return {Promise<TGApp.Plugins.Mys.Gacha.Data[]>}
*/
async function getGachaData(): Promise<TGApp.Plugins.Mys.Gacha.Data[]> {
return await http
.fetch<TGApp.Plugins.Mys.Gacha.Response>(MysApi.Gacha, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
}
export default getGachaData;

View File

@@ -0,0 +1,30 @@
/**
* @file plugins Mys interface getLotteryData.ts
* @description Mys 插件抽奖接口
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取抽奖信息
* @since Alpha v0.2.1
* @param {string} lotteryId 抽奖 ID
* @return {Promise<TGApp.Plugins.Mys.Lottery.FullData>}
*/
async function getLotteryData(lotteryId: string): Promise<TGApp.Plugins.Mys.Lottery.FullData> {
return await http
.fetch<TGApp.Plugins.Mys.Lottery.Response>(MysApi.Lottery.replace("{lotteryId}", lotteryId), {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.show_lottery;
});
}
export default getLotteryData;

View File

@@ -0,0 +1,33 @@
/**
* @file plugins Mys request getNewsList.ts
* @description Mys 插件咨讯请求
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取 News 列表
* @since Alpha v0.2.1
* @param {string} gid GID
* @param {string} newsType 咨讯类型: 1 为公告2 为活动3 为咨讯
* @param {number} pageSize 返回数量
* @param {number} lastId 上一次请求的最后一条数据的 id
* @return {Promise<TGApp.Plugins.Mys.News.FullData>}
*/
async function getNewsList(
gid: string = "2",
newsType: string = "1",
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);
}
export default getNewsList;

View File

@@ -0,0 +1,49 @@
/**
* @file plugins Mys request getPositionData.ts
* @description Mys 插件热点追踪请求
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 深度优先遍历
* @since Alpha v0.2.1
* @param {TGApp.Plugins.Mys.Position.ObcItem[]} list 列表
* @returns {TGApp.Plugins.Mys.Position.Data[]} 返回列表
*/
function DfsObc(list: TGApp.Plugins.Mys.Position.ObcItem[]): TGApp.Plugins.Mys.Position.Data[] {
const res: TGApp.Plugins.Mys.Position.Data[] = [];
for (const item of list) {
if (item.name === "近期活动") {
res.push(...item.list);
}
if (item.children) {
res.push(...DfsObc(<TGApp.Plugins.Mys.Position.ObcItem[]>item.children));
}
}
return res;
}
/**
* @description 获取热点追踪信息
* @since Alpha v0.2.1
* @return {Promise<TGApp.Plugins.Mys.Position.Data[]>}
*/
async function getPositionData(): Promise<TGApp.Plugins.Mys.Position.Data[]> {
const res = await http
.fetch<TGApp.Plugins.Mys.Position.Response>(MysApi.Position, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
return DfsObc(res);
}
export default getPositionData;

View File

@@ -0,0 +1,32 @@
/**
* @file plugins Mys request getPostData.ts
* @description Mys帖子请求
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
*/
import { http } from "@tauri-apps/api";
import MysApi from "../api";
/**
* @description 获取帖子信息
* @since Alpha v0.2.1
* @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());
return await http
.fetch<TGApp.Plugins.Mys.Post.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.Post.Referer,
},
})
.then((res) => {
return res.data.data.post;
});
}
export default getPostData;

View File

@@ -1,32 +0,0 @@
/**
* @file plugins Mys interface lottery.ts
* @description Mys 插件抽奖接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { type LotteryResponse, type LotteryData } from "../interface/lottery";
// 抽奖 API
const LOTTERY_API =
"https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show?gids=2&id={lottery_id}";
/**
* @description 获取抽奖信息
* @since Alpha v0.1.2
* @param {string} lotteryId 抽奖 ID
* @return {Promise<LotteryData>}
*/
export async function getLotteryData(lotteryId: string): Promise<LotteryData> {
return await http
.fetch<LotteryResponse>(LOTTERY_API.replace("{lottery_id}", lotteryId), {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.show_lottery;
});
}

View File

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

View File

@@ -1,33 +0,0 @@
/**
* @file plugins Mys request position.ts
* @description Mys 插件热点追踪请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { type PositionResponse, type PositionData } from "../interface/position";
import { dfs } from "../utils/position";
// 热点追踪 API
const POSITION_API =
"https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/position?app_sn=ys_obc";
/**
* @description 获取热点追踪信息
* @since Alpha v0.1.1
* @return {Promise<PositionData[]>}
*/
export async function getPositionData(): Promise<PositionData[]> {
const res = await http
.fetch<PositionResponse>(POSITION_API, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
return dfs(res);
}

View File

@@ -1,33 +0,0 @@
/**
* @file plugins Mys request post.ts
* @description Mys帖子请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { type PostResponse, type PostData } from "../interface/post";
// 帖子 API
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 v0.1.2
* @param {number} postId 帖子 ID
* @return {Promise<PostData>}
*/
export async function getPostData(postId: number): Promise<PostData> {
return await http
.fetch<PostResponse>(POST_API.replace("{post_id}", postId.toString()), {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: POST_REFERER,
},
})
.then((res) => {
return res.data.data.post;
});
}