refactor(Mys): 重构Mys相关接口,把页面用到的接口也给加进来了

This commit is contained in:
BTMuli
2023-03-29 00:23:36 +08:00
parent 055d3e5d7f
commit 57bf249839
10 changed files with 779 additions and 566 deletions

View File

@@ -0,0 +1,21 @@
/**
* @file plugins Mys interface base.ts
* @description Mys 插件基础接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
/**
* @description Mys Response 统一接口
* @since Alpha
* @interface MysResponse
* @property {number} retcode 状态码
* @property {string} message 状态信息
* @property {any} data 数据
* @return {MysResponse}
*/
export interface MysResponse {
retcode: number;
message: string;
data: any;
}

View File

@@ -0,0 +1,106 @@
/**
* @file plugins Mys interface gacha.ts
* @description Mys 插件抽卡接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { MysResponse } from "./base";
// 卡池 API
/**
* @description 获取卡池信息的返回类型
* @since Alpha
* @see GachaResponse
* @return {string}
*/
export const GACHA_POOL_API =
"https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
// 卡池接口
/**
* @description 获取卡池信息的返回类型
* @since Alpha
* @interface GachaResponse
* @extends MysResponse
* @property {GachaData[]} data.list 卡池数据
* @return {GachaResponse}
*/
export interface GachaResponse extends MysResponse {
data: {
list: GachaData[];
};
}
/**
* @description 获取卡池信息的返回类型
* @since Alpha
* @interface GachaData
* @property {string} id 卡池ID
* @property {string} title 卡池标题
* @property {string} activity_url 卡池对应帖子
* @property {string} content_before_act 卡池内容
* @property {GachaPool[]} pool 卡池包含的角色
* @property {string} voice_icon 卡池角色语音头像
* @property {string} voice_url 卡池角色语音URL
* @property {string} voice_status 卡池角色语音状态
* @description 如下时间示例2023-03-21 17:59:59
* @property {string} start_time 卡池开始时间
* @property {string} end_time 卡池结束时间
* @return {GachaData}
*/
export interface GachaData {
id: string;
title: string;
activity_url: string;
content_before_act: string;
pool: GachaPool[];
voice_icon: string;
voice_url: string;
voice_status: string;
start_time: string;
end_time: string;
}
/**
* @description 获取卡池信息的返回类型
* @since Alpha
* @interface GachaPool
* @property {string} icon 卡池角色头像
* @property {string} url 卡池角色URL
* @return {GachaPool}
*/
export interface GachaPool {
icon: string;
url: string;
}
/**
* @description 用于渲染的卡池数据
* @since Alpha
* @interface GachaPoolRender
* @property {string} title 卡池标题
* @property {string} subtitle 卡池副标题
* @property {string} cover 卡池封面
* @property {string} post_id 卡池对应帖子ID
* @property {GachaPool[]} characters 卡池包含的角色
* @property {GachaPool} voice 卡池角色语音
* @property time 卡池时间
* @property {string} time.start 卡池开始时间
* @property {string} time.end 卡池结束时间
* @return {GachaPoolRender}
*/
export interface GachaPoolRender {
title: string;
subtitle: string;
cover: string;
post_id: string;
characters: GachaPool[];
voice: GachaPool;
time: {
start: string;
end: string;
};
}

View File

@@ -0,0 +1,169 @@
/**
* @file plugins Mys interface news.ts
* @description Mys 插件咨讯接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { MysResponse } from "./base";
import { Post, Forum, Topic, PostStat } from "./post";
import { User, SelfOperation } from "./user";
import { ImageData, HelpSys } from "./utils";
// 咨讯 API
/**
* @description 咨讯列表 API
* @since Alpha
* @param {number} ews_type 咨讯类型
* @see NewsType
* @return {string}
*/
export const NEWS_LIST_API =
"https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&type={news_type}";
// 咨讯相关枚举数据
/**
* @description 咨讯类型
* @enum NewsType
* @since Alpha
* @property {number} NOTICE 公告
* @property {number} ACTIVITY 活动
* @property {number} NEWS 咨讯
* @return {NewsType}
*/
export enum NewsType {
NOTICE = 1,
ACTIVITY = 2,
NEWS = 3,
}
/**
* @description 活动状态
* @enum ActivityStatus
* @since Alpha
* @property {number} STARTED 进行中
* @property {number} FINISHED 已结束
* @property {number} SELECTION 评选中
* @return {ActivityStatus}
*/
export enum ActivityStatus {
STARTED = 1,
FINISHED = 2,
SELECTION = 3,
}
// 咨讯接口
/**
* @description 咨讯返回数据
* @since Alpha
* @interface NewsResponse
* @extends {MysResponse}
* @property {NewsData} data 咨讯数据
* @return {NewsResponse}
*/
export interface NewsResponse extends MysResponse {
data: NewsData;
}
/**
* @description 咨讯数据
* @since Alpha
* @interface NewsData
* @property {number} last_id 最后一条咨讯 ID
* @property {boolean} is_last 是否最后一页
* @property {NewsItem[]} list 咨讯列表
* @return {NewsData}
*/
export interface NewsData {
last_id: number;
is_last: boolean;
list: NewsItem[];
}
/**
* @description 咨讯列表项
* @since Alpha
* @interface NewsItem
* @property {Post} post 帖子
* @property {Forum} forum 版块
* @property {Topic[]} topics 话题
* @property {User} user 发帖用户
* @property {SelfOperation} self_operation 用户操作
* @property {PostStat} stat 帖子统计
* @property {HelpSys} help_sys 帮助系统,可能为 null
* @property {ImageData} cover 封面图片 URL
* @property {ImageData[]} image_list 图片列表
* @property {boolean} is_official_master 是否为官方
* @property {boolean} is_user_master 是否用户
* @property {boolean} hot_reply_exist 是否热门回复
* @property {number} vote_count 投票数
* @property {number} last_modify_time 最后修改时间
* @property {string} recommend_type 推荐类型
* @property {unknown} collection 合集, 可能为 null // TODO: 未知
* @property {unknown[]} vod_list 视频列表
* @property {boolean} is_block_on 是否屏蔽
* @property {unknown} forum_rank_info 版块排名信息,可能为 null // TODO: 未知
* @property {unknown[]} link_card_list 链接卡片列表,可能为 null // TODO: 未知
* @property {NewsMeta} news_meta 元数据
* @return {NewsItem}
*/
export interface NewsItem {
post: Post;
forum: Forum;
topics: Topic[];
user: User;
self_operation: SelfOperation;
stat: PostStat;
help_sys: HelpSys;
cover: ImageData;
image_list: ImageData[];
is_official_master: boolean;
is_user_master: boolean;
hot_reply_exist: boolean;
vote_count: number;
last_modify_time: number;
recommend_type: string;
collection: unknown;
vod_list: unknown[];
is_block_on: boolean;
forum_rank_info: unknown;
link_card_list: unknown[];
news_meta: NewsMeta;
}
/**
* @description 咨讯元数据,只有活动咨讯才有
* @since Alpha
* @interface NewsMeta
* @property {number} activity_status 活动状态 // ActivityStatus
* @property {string} start_at_sec 活动开始时间戳,单位秒
* @property {string} end_at_sec 活动结束时间戳,单位秒
* @return {NewsMeta}
*/
export interface NewsMeta {
activity_status: number;
start_at_sec: string;
end_at_sec: string;
}
/**
* @description 用于渲染的咨讯卡片
* @since Alpha
* @interface NewsCard
* @property {string} title 标题
* @property {string} cover 封面图片 URL
* @property {string} post_id 帖子 ID
* @property {string} subtitle 副标题
* @property {number} status 活动状态,仅活动咨讯有
* @return {NewsCard}
*/
export interface NewsCard {
title: string;
cover: string;
post_id: string;
subtitle: string;
status?: number;
}

View File

@@ -0,0 +1,249 @@
/**
* @file plugins Mys interface post.ts
* @description Mys 插件帖子接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { MysResponse } from "./base";
import { NewsMeta } from "./news";
import { User, SelfOperation } from "./user";
import { ImageData, HelpSys } from "./utils";
// Post API
/**
* @description 帖子完整信息 API
* @since Alpha
* @see PostResponse
* @param {number} post_id 帖子 ID
* @return {string}
*/
export const POST_FULL_API =
"https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id={post_id}";
/**
* @description 帖子完整信息 Referer
* @since Alpha
* @param {number} post_id 帖子 ID
* @return {string}
*/
export const POST_FULL_REFERER = "https://bbs.mihoyo.com/ys/article/{post_id}"; // 与 POST_FULL_API 中的 post_id 对应, 用于伪造 Referer
// Post Interface
/**
* @description 帖子返回数据
* @since Alpha
* @interface PostResponse
* @extends {MysResponse}
* @property {PostData} data.post 帖子数据
* @return {PostResponse}
*/
export interface PostResponse extends MysResponse {
data: {
post: PostData;
};
}
/**
* @description 帖子数据
* @since Alpha
* @interface PostData
* @property {Post} post 帖子信息
* @property {Forum} forum 所属版块
* @property {Topic[]} topics 所属话题
* @property {User} user 发帖人
* @property {SelfOperation} self_operation 当前用户操作
* @property {PostStat} stat 帖子统计
* @property {HelpSys} help_sys 帮助系统,可能为 null
* @property {ImageData} cover 封面图,可能为 null
* @property {ImageData[]} image_list 图片列表
* @property {boolean} is_official_master 是否为官方帖
* @property {boolean} is_user_master 是否为用户帖
* @property {boolean} hot_reply_exist 是否存在热门回复
* @property {number} vot_count 投票数
* @property {number} last_modify_time 最后修改时间
* @property {string} recommend_type 推荐类型
* @property {unknown} collection 合集,可能为 null // TODO: 未知
* @property {unknown[]} vod_list 视频列表,可能为空 // TODO: 未知
* @property {boolean} is_block_on 是否被屏蔽
* @property {unknown} forum_rank_info 版块排行信息,可能为 null // TODO: 未知
* @property {unknown[]} link_card_list 链接卡片列表,可能为空 // TODO: 未知
* @property {NewsMeta} news_meta 咨讯元数据,可能为 null
* @return {PostData}
*/
export interface PostData {
post: Post;
forum: Forum;
topics: Topic[];
user: User;
self_operation: SelfOperation;
stat: PostStat;
help_sys: HelpSys | null;
cover: ImageData | null;
image_list: ImageData[];
is_official_master: boolean;
is_user_master: boolean;
hot_reply_exist: boolean;
vot_count: number;
last_modify_time: number;
recommend_type: string;
collection: unknown | null;
vod_list: unknown[];
is_block_on: boolean;
forum_rank_info: unknown | null;
link_card_list: unknown[];
news_meta: NewsMeta | null;
}
/**
* @description 帖子信息
* @since Alpha
* @interface Post
* @property {number} game_id 游戏 ID // 2 为原神
* @property {string} post_id 帖子 ID
* @property {number} f_forum_id 所属版块 ID
* @property {string} uid 发帖人 UID
* @property {string} subject 帖子标题
* @property {string} content 帖子内容,为 html 格式
* @property {string} cover 封面图 URL可能为 ""
* @property {number} view_type 浏览类型 // TODO: 未知
* @property {number} created_at 发帖时间
* @property {string[]} images 图片列表,可能为空
* @property post_status 帖子状态
* @property {boolean} post_status.is_top 是否置顶
* @property {boolean} post_status.is_good 是否加精
* @property {boolean} post_status.is_official 是否官方
* @property {number[]} topic_ids 所属话题 ID 列表
* @property {number} view_status 浏览状态
* @property {number} max_floor 最大楼层
* @property {number} is_original 是否原创
* @property {number} republish_authorization 是否授权转载
* @property {string} reply_time 最后回复时间 // "2023-03-05 20:26:54"
* @property {number} is_deleted 是否删除
* @property {boolean} is_interactive 是否互动
* @property {string} structured_content 结构化内容 // 反序列化后为 PostStructuredContent
* @property {string[]} structured_content_rows 结构化内容原始数据
* @property {number} review_id 审核ID
* @property {boolean} is_profit 是否盈利
* @property {boolean} is_in_profit 是否在盈利
* @property {number} updated_at 更新时间
* @property {number} deleted_at 删除时间
* @property {number} pre_pub_status 预发布状态
* @property {number} cate_id 分类ID
* @property {number} profit_post_status 盈利帖子状态 // TODO: 未知
* @property {number} audit_status 审核状态
* @property {string} meta_content 元内容,可能为 "" // TODO: 未知
* @property {boolean} is_missing 是否缺失 // TODO: 未知
* @property {number} block_reply_img 是否屏蔽回复图片 // TODO: 未知
* @property {boolean} is_showing_missing 是否显示缺失 // TODO: 未知
* @property {number} block_latest_reply_time 是否屏蔽最新回复时间 // TODO: 未知
* @property {number} selected_comment 是否选择评论 // TODO: 未知
* @return {Post}
*/
export interface Post {
game_id: number;
post_id: string;
f_forum_id: number;
uid: string;
subject: string;
content: string;
cover: string;
view_type: number;
created_at: number;
images: string[];
post_status: {
is_top: boolean;
is_good: boolean;
is_official: boolean;
};
topic_ids: number[];
view_status: number;
max_floor: number;
is_original: number;
republish_authorization: number;
reply_time: string;
is_deleted: number;
is_interactive: boolean;
structured_content: string;
structured_content_rows: string[];
review_id: number;
is_profit: boolean;
is_in_profit: boolean;
updated_at: number;
deleted_at: number;
pre_pub_status: number;
cate_id: number;
profit_post_status: number;
audit_status: number;
meta_content: string;
is_missing: boolean;
block_reply_img: number;
is_showing_missing: boolean;
block_latest_reply_time: number;
selected_comment: number;
}
/**
* @description 版块信息
* @since Alpha
* @interface Forum
* @property {number} id 版块 ID
* @property {string} name 版块名称
* @property {string} icon 版块图标 URL
* @property {number} game_id 游戏 ID // 2 为原神
* @property {unknown} forum_cate 版块分类,可能为 null
* @return {Forum}
*/
export interface Forum {
id: number;
name: string;
icon: string;
game_id: number;
forum_cate: unknown | null;
}
/**
* @description 话题信息
* @since Alpha
* @interface Topic
* @property {number} id 话题 ID
* @property {string} name 话题名称
* @property {string} cover 话题封面图 URL
* @property {boolean} is_top 是否置顶
* @property {boolean} is_good 是否加精
* @property {boolean} is_interactive 是否互动
* @property {number} game_id 游戏 ID
* @property {number} content_type 内容类型
* @return {Topic}
*/
export interface Topic {
id: number;
name: string;
cover: string;
is_top: boolean;
is_good: boolean;
is_interactive: boolean;
game_id: number;
content_type: number;
}
/**
* @description 帖子状态
* @since Alpha
* @interface PostStat
* @property {number} view_num 浏览数
* @property {number} reply_num 回复数
* @property {number} like_num 点赞数
* @property {number} bookmark_num 收藏数
* @property {number} forward_num 转发数
* @return {PostStat}
*/
export interface PostStat {
view_num: number;
reply_num: number;
like_num: number;
bookmark_num: number;
forward_num: number;
}

View File

@@ -0,0 +1,62 @@
/**
* @file plugins Mys interface user.ts
* @description Mys 插件用户接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
// 用户接口
/**
* @description 用户信息
* @since Alpha
* @interface User
* @property {string} uid 用户 ID
* @property {string} nickname 用户昵称
* @property {string} introduce 用户简介
* @property {string} avatar 用户头像 // TODO: 转换为图片链接
* @property {number} gender 用户性别 // TODO: 未知
* @property certification 用户认证信息
* @property {number} certification.type 认证类型
* @property {string} certification.label 认证标签
* @property level_exp 用户等级经验
* @property {number} level_exp.level 用户等级
* @property {number} level_exp.exp 用户经验
* @property {boolean} is_following 是否关注
* @property {boolean} is_follower 是否被关注
* @property {string} avatar_url 用户头像链接
* @property {string} pendant 用户挂件 URL可能为 ""
* @return {User}
*/
export interface User {
uid: string;
nickname: string;
introduce: string;
avatar: string;
gender: number;
certification: {
type: number;
label: string;
};
level_exp: {
level: number;
exp: number;
};
is_following: boolean;
is_follower: boolean;
avatar_url: string;
pendant: string;
}
/**
* @description 用户操作
* @since Alpha
* @interface SelfOperation
* @property {number} attitude 操作类型 // TODO: 未知
* @property {boolean} is_collected 是否收藏
* @return {SelfOperation}
*/
export interface SelfOperation {
attitude: number;
is_collected: boolean;
}

View File

@@ -0,0 +1,77 @@
/**
* @file plugins Mys interface utils.ts
* @description Mys 插件工具接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
// 杂项 API
/**
* @description 观测枢 content API
* @since Alpha
* @param {string} content_id 内容 ID
* @return {string} API
*/
export const OBC_CONTENT_API =
"https://bbs.mihoyo.com/ys/obc/content/{content_id}/detail?bbs_presentation_style=no_header";
// 杂项接口
/**
* @description 图片数据
* @since Alpha
* @interface ImageData
* @property {string} url 图片 URL
* @property {number} height 图片高度
* @property {string} width 图片宽度
* @property {string} format 图片格式 // jpg
* @property {string} size 图片大小 // 281428
* @property crop 图片裁剪信息,可能为 null
* @property {number} crop.x 裁剪 X 轴
* @property {number} crop.y 裁剪 Y 轴
* @property {number} crop.w 裁剪宽度
* @property {number} crop.h 裁剪高度
* @property {string} crop.url 裁剪图片 URL
* @property {boolean} is_user_set_cover 是否为封面
* @property {string} image_id 图片 ID
* @property {string} entity_type 图片类型 // IMG_ENTITY_POST, IMG_ENTITY_UNKOWN
* @property {string} entity_id 图片 ID
* @property {boolean} is_deleted 是否已删除
* @return {ImageData}
*/
export interface ImageData {
url: string;
height: number;
width: number;
format: string;
size: string;
crop: {
x: number;
y: number;
w: number;
h: number;
url: string;
} | null;
is_user_set_cover: boolean;
image_id: string;
entity_type: string;
entity_id: string;
is_deleted: boolean;
}
/**
* @description help_sys 信息
* @since Alpha
* @todo 用处未知
* @interface HelpSys
* @property {unknown} top_up 置顶, 可能为 null // TODO: 未知
* @property {unknown[]} top_n 置顶, 可能为空
* @property {number} answer_num 回答数
* @return {HelpSys}
*/
export interface HelpSys {
top_up: unknown | null;
top_n: unknown[];
answer_num: number;
}