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

@@ -1,475 +0,0 @@
/**
* @file interface MysPost
* @description interface MysPost
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
export const MysNewsApi = "https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&type=";
export const MysPostApi = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id=";
export const MysGachaInfo =
"https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
export const MysContent =
"https://bbs.mihoyo.com/ys/obc/content/content_id/detail?bbs_presentation_style=no_header";
/**
* @description 获取 News 的返回类型
* @see https://bbs-api.mihoyo.com/post/wapi/getNewsList?gids=2&type={EnumPostType}
* @interface ResponseNewsList
* @property {number} retcode 返回码
* @property {string} message 返回信息
* @property data 返回数据
* @property data.list {ResponseListType[]} 返回列表
* @property {number} data.last_id 最后ID
* @property {boolean} data.is_last 是否最后
* @return ResponseNewsList
*/
export interface ResponseNewsList {
retcode: number;
message: string;
data: {
list: ResponseNews[];
last_id: number;
is_last: boolean;
};
}
/**
* @description 获取 Post 的返回类型
* @see https://bbs-api.mihoyo.com/post/wapi/getPostFull?gids=2&post_id={post_id}
* @interface ResponsePost
* @property {number} retcode 返回码
* @property {string} message 返回信息
* @property data 返回数据
* @property data.post 帖子
* @property {string} data.post.collection 是否收藏
* @property {string} data.post.cover 封面 URL
* @property {MysForumType} data.post.forum 板块
* @property {string} data.post.forum_rank_info 板块等级信息
* @property {string} data.post.help_sys 是否有帮助系统
* @property {boolean} data.post.hot_reply_exist 是否有热门回复
* @property {ImageType[]} data.post.iamge_list 图片列表
* @property {boolean} data.post.is_block_on 是否被屏蔽
* @property {boolean} data.post.is_official_master 是否官方
* @property {boolean} data.post.is_user_master 是否用户
* @property {number} data.post.last_modify_time 最后修改时间
* @property {string[]} data.post.like_card_list 点赞卡片列表
* @property {NewsMetaType} data.post.news_meta 新闻元数据
* @property {MysPostType} data.post.post 帖子
* @property {string} data.post.recommend_type 推荐类型
* @property {SelfOperationType} data.post.self_operation 自己的操作
* @property {StatType} data.post.stat 统计
* @property {MysTopicType[]} data.post.topics 话题
* @property {MysUserType} data.post.user 用户
* @property {string[]} data.post.vod_list 视频列表
* @property {number} data.post.vod_count 视频数量
* @return ResponsePost
*/
export interface ResponsePost {
retcode: number;
message: string;
data: {
post: {
collection: string;
cover: string;
forum: MysForumType;
forum_rank_info: string;
help_sys: string;
hot_reply_exist: boolean;
image_list: ImageType[];
is_block_on: boolean;
is_official_master: boolean;
is_user_master: boolean;
last_modify_time: number;
like_card_list: string[];
news_meta: NewsMetaType;
post: MysPostType;
recommend_type: string;
self_operation: SelfOperationType;
stat: StatType;
topics: MysTopicType[];
user: MysUserType;
vod_list: string[];
vod_count: number;
};
};
}
/**
* @description 获取卡池信息的返回类型
* @see https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc
* @interface ResponseGachaPool
* @property {number} retcode 返回码
* @property {string} message 返回信息
* @property data 返回数据
* @property data.list 卡池列表
* @property {string} data.list[].id 卡池ID
* @property {string} data.list[].title 卡池标题
* @property {string} data.list[].activity_url 卡池对应帖子
* @property {string} data.list[].content_before_act 卡池内容
* @property {string} data.list[].pool 卡池包含的角色
* @property {string} data.list[].pool[].icon 卡池角色头像
* @property {string} data.list[].pool[].url 卡池角色URL
* @property {string} data.list[].voice_icon 卡池角色语音头像
* @property {string} data.list[].voice_url 卡池角色语音URL
* @property {string} data.list[].voice_status 卡池角色语音状态
* @description 如下时间示例2023-03-21 17:59:59
* @property {string} data.list[].start_time 卡池开始时间
* @property {string} data.list[].end_time 卡池结束时间
* @return ResponseGachaPool
*/
export interface ResponseGachaPool {
retcode: number;
message: string;
data: {
list: {
id: string;
title: string;
activity_url: string;
content_before_act: string;
pool: {
icon: string;
url: string;
}[];
voice_icon: string;
voice_url: string;
voice_status: string;
start_time: string;
end_time: string;
}[];
};
}
/**
* @description 官方动态类型
* @description 参考米游社官方页面
* @enum {number}
* @return {number}
*/
export enum EnumPostType {
/**
* @description 活动
* @description 这个有 news_meta
*/
Activity = 2,
/**
* @description 公告
*/
Notice = 1,
/**
* @description 咨讯
*/
News = 3,
}
/**
* @description 帖子状态
* @interface PostStatusType
* @property {boolean} is_top 是否置顶
* @property {boolean} is_good 是否精华
* @property {boolean} is_official 是否官方
* @return PostStatusType
*/
interface PostStatusType {
is_top: boolean;
is_good: boolean;
is_official: boolean;
}
/**
* @description Post类型
* @interface MysPostType
* @property {number} game_id 游戏ID 2为原神
* @property {string} post_id 帖子ID
* @property {number} f_forum_id 论坛ID
* @property {string} uid 用户ID
* @property {string} subject 标题
* @property {string} content 内容
* @property {string} cover 封面
* @property {number} view_type 浏览类型
* @property {number} created_at 创建时间
* @property {string[]} images 图片 URL
* @property {PostStatusType} post_status 帖子状态
* @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 结构化内容
* @property {string[]} structured_content_raws 结构化内容原始数据
* @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 盈利帖子状态
* @property {number} audit_status 审核状态
* @property {string} meta_content 元内容
* @property {boolean} is_missing 是否缺失
* @property {number} block_reply_img 是否屏蔽回复图片
* @property {boolean} is_showing_missing 是否显示缺失
* @property {number} block_latest_reply_time 是否屏蔽最新回复时间
* @return MysPostType
*/
export interface MysPostType {
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: PostStatusType;
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_raws: 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;
}
/**
* @description Forum类型
* @interface MysForumType
* @property {number} id 论坛ID
* @property {string} name 论坛名称
* @property {string} icon 论坛图标
* @property {number} game_id 游戏ID
* @property {number} forum_cate 论坛分类 // todo 这边目前看到的都是 null
* @return MysForumType
*/
interface MysForumType {
id: number;
name: string;
icon: string;
game_id: number;
forum_cate: number;
}
/**
* @description Topic类型
* @interface MysTopicType
* @property {number} id 话题ID
* @property {string} name 话题名称
* @property {string} cover 话题封面
* @property {boolean} is_top 是否置顶
* @property {boolean} is_good 是否精华
* @property {boolean} is_interactive 是否互动
* @property {number} game_id 游戏ID
* @property {number} content_type 话题内容类型
* @see EnumPostType
* @return MysTopicType
*/
interface MysTopicType {
id: number;
name: string;
cover: string;
is_top: boolean;
is_good: boolean;
is_interactive: boolean;
game_id: number;
content_type: number;
}
/**
* @description 认证类型
* @interface CertificationType
* @property {number} type 认证类型
* @property {string} label 认证标签
* @return CertificationType
*/
interface CertificationType {
type: number;
label: string;
}
/**
* @description User类型
* @interface MysUserType
* @property {string} uid 用户ID
* @property {string} nickname 用户昵称
* @property {string} introduce 用户简介
* @property {string} avatar 用户头像
* @property {number} gender 用户性别
* @property {CertificationType} certification 认证
* @property level_exp
* @property {number} level_exp.level 用户等级
* @property {number} level_exp.exp 用户经验
* @property {boolean} is_following 是否关注
* @property {boolean} is_followed 是否被关注
* @property {string} avatar_url 用户头像
* @property {string} pendant 用户注册时间
* @return MysUserType
*/
interface MysUserType {
uid: string;
nickname: string;
introduce: string;
avatar: string;
gender: number;
certification: CertificationType;
level_exp: {
level: number;
exp: number;
};
is_following: boolean;
is_followed: boolean;
avatar_url: string;
pendant: string;
}
/**
* @description 用户操作
* @interface SelfOperationType
* @property {number} attitude 点赞
* @property {boolean} is_collected 是否收藏
* @return SelfOperationType
*/
interface SelfOperationType {
attitude: number;
is_collected: boolean;
}
/**
* @description 状态数据
* @interface StatType
* @property {number} view_num 浏览量
* @property {number} reply_num 回复量
* @property {number} like_num 点赞量
* @property {number} bookmark_num 收藏量
* @property {number} forward_num 转发量
* @return StatType
*/
interface StatType {
view_num: number;
reply_num: number;
like_num: number;
bookmark_num: number;
forward_num: number;
}
/**
* @description 图片类型
* @interface ImageType
* @property {string} url 图片 URL
* @property {number} height 图片高度
* @property {number} width 图片宽度
* @property {string} format 图片格式
* @property {string} size 图片大小
* @property {string} crop
* @property {boolean} is_user_set_cover 是否作为封面
* @property {string} image_id 图片 id
* @property {string} entity_type
* @property {string} entity_id
* @return ImageType
*/
interface ImageType {
url: string;
height: number;
width: number;
format: string;
size: string;
crop: string;
is_user_set_cover: boolean;
iamge_id: string;
entity_type: string;
entity_id: string;
}
/**
* @description 元数据
* @interface NewsMetaType
* @property {number} activity_status
* @property {string} start_at_sec
* @property {string} end_at_sec
* @return NewsMetaType
*/
interface NewsMetaType {
activity_status: number;
start_at_sec: string;
end_at_sec: string;
}
/**
* @description 单个 News 的返回类型
* @interface ResponseNews
* @property {MysPostType} post 帖子
* @property {MysForumType} forum 论坛
* @property {MysTopicType} topics 话题
* @property {MysUserType} user 用户
* @property {SelfOperationType} self_operation 用户操作
* @property {StatType} stat 状态数据
* @property help_sys // todo 不清楚这个是什么
* @property {number} help_sys.top_up
* @property {number[]} help_sys.top_n
* @property {number} help_sys.answer_num
* @property {string} cover 封面
* @property {ImageType[]} 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 {string} collection 推荐类型
* @property {string[]} vod_list 视频列表
* @property {boolean} is_block_on 是否屏蔽
* @property {string} forum_rank_info 论坛排名信息
* @property {string[]} link_card_list 链接卡片列表
* @property {NewsMetaType} news_meta 元数据
* @return ResponseNews
*/
export interface ResponseNews {
post: MysPostType;
forum: MysForumType;
topics: MysTopicType;
user: MysUserType;
self_operation: SelfOperationType;
stat: StatType;
help_sys: {
top_up: number;
top_n: number[];
answer_num: number;
};
cover: string;
image_list: ImageType[];
is_official_master: boolean;
is_user_master: boolean;
hot_reply_exist: boolean;
vote_count: number;
last_modify_time: number;
recommend_type: string;
collection: string;
vod_list: string[];
is_block_on: boolean;
forum_rank_info: string;
link_card_list: string[];
news_meta: NewsMetaType;
}

View File

@@ -91,13 +91,17 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// vue
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import TLoading from "../components/t-loading.vue";
// tauri
import { dialog } from "@tauri-apps/api";
// utils
import { createTGWindow } from "../utils/TGWindow"; import { createTGWindow } from "../utils/TGWindow";
import { ReadAllTGData } from "../utils/TGIndex"; import { ReadAllTGData } from "../utils/TGIndex";
// interface
import { BaseCard, ActionCard, CharacterCard, MonsterCard } from "../interface/GCG"; import { BaseCard, ActionCard, CharacterCard, MonsterCard } from "../interface/GCG";
import { MysContent } from "../interface/MysPost"; import { OBC_CONTENT_API } from "../plugins/Mys/interface/utils";
import { dialog } from "@tauri-apps/api";
import TLoading from "../components/t-loading.vue";
const loading = ref(true); const loading = ref(true);
const doSearch = ref(false); const doSearch = ref(false);
@@ -120,7 +124,7 @@ async function loadData() {
loading.value = false; loading.value = false;
} }
function toOuter(card_name: string, card_id: number) { function toOuter(card_name: string, card_id: number) {
const url = MysContent.replace("content_id", card_id.toString()); const url = OBC_CONTENT_API.replace("{content_id}", card_id.toString());
createTGWindow(url, "GCG", card_name, 1200, 800, true); createTGWindow(url, "GCG", card_name, 1200, 800, true);
} }
async function searchCard() { async function searchCard() {

View File

@@ -55,49 +55,40 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// vue
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import useAppStore from "../store/modules/app";
import { fs, http } from "@tauri-apps/api";
import { createTGWindow } from "../utils/TGWindow";
import {
ResponseGachaPool,
ResponsePost,
MysPostApi,
MysGachaInfo,
MysPostType,
} from "../interface/MysPost";
import { parseMys } from "../utils/MysParse";
import TLoading from "../components/t-loading.vue"; import TLoading from "../components/t-loading.vue";
// tauri
interface GachaPool { import { fs, http } from "@tauri-apps/api";
title: string; // store
subtitle: string; import useAppStore from "../store/modules/app";
cover: string; // utils
post_id: string; import { createTGWindow } from "../utils/TGWindow";
characters: { import { parseMys } from "../utils/MysParse";
icon: string; // interface
url: string; import {
}[]; GachaResponse,
voice: { GachaData,
icon: string; GachaPoolRender,
url: string; GACHA_POOL_API,
}; } from "../plugins/Mys/interface/gacha";
time: { import {
start: string; PostResponse,
end: string; Post,
}; POST_FULL_API,
} POST_FULL_REFERER,
} from "../plugins/Mys/interface/post";
const appStore = useAppStore(); const appStore = useAppStore();
const poolInfo = ref([] as GachaPool[]); const poolInfo = ref([] as GachaPoolRender[]);
const loading = ref(true); const loading = ref(true);
const empty = ref(false); const empty = ref(false);
const timeGet = ref(""); const timeGet = ref("");
const timePass = ref(0); const timePass = ref(0);
onMounted(async () => { onMounted(async () => {
const responseGachaPool = await http const responseGachaPool: GachaData[] = await http
.fetch<ResponseGachaPool>(MysGachaInfo, { .fetch<GachaResponse>(GACHA_POOL_API, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -113,15 +104,15 @@ onMounted(async () => {
return; return;
} }
empty.value = false; empty.value = false;
responseGachaPool.map(async gachaPool => { responseGachaPool.map(async (gachaPool: GachaData) => {
// 获取卡池 article post_id // 获取卡池 article post_id
const post_id = gachaPool.activity_url.split("/").pop(); const post_id = gachaPool.activity_url.split("/").pop();
if (!post_id) return; if (!post_id) return;
const gachaCover = await http const gachaCover = await http
.fetch<ResponsePost>(MysPostApi + post_id, { .fetch<PostResponse>(POST_FULL_API.replace("{post_id}", post_id), {
method: "GET", method: "GET",
headers: { headers: {
referer: `https://bbs.mihoyo.com/ys/article/${post_id}`, referer: POST_FULL_REFERER.replace("{post_id}", post_id),
}, },
}) })
.then(response => { .then(response => {
@@ -175,15 +166,15 @@ function toOuter(url: string, title: string) {
async function toPost(post_id: string) { async function toPost(post_id: string) {
// 获取帖子内容 // 获取帖子内容
const post: MysPostType = await http const post: Post = await http
.fetch(`${MysPostApi}${post_id}`, { .fetch(POST_FULL_API.replace("{post_id}", post_id), {
method: "GET", method: "GET",
headers: { headers: {
referer: `https://bbs.mihoyo.com/ys/article/${post_id}`, referer: POST_FULL_REFERER.replace("{post_id}", post_id),
}, },
}) })
.then(res => { .then(res => {
return res.data as Promise<ResponsePost>; return res.data as Promise<PostResponse>;
}) })
.then(res => { .then(res => {
return res.data.post.post; return res.data.post.post;

View File

@@ -65,9 +65,15 @@
</v-btn> </v-btn>
<v-card-subtitle>id:{{ item.post_id }}</v-card-subtitle> <v-card-subtitle>id:{{ item.post_id }}</v-card-subtitle>
<div v-show="!appStore.devMode"> <div v-show="!appStore.devMode">
<v-btn v-if="item.status === 1" color="ms-2 card-btn-0">进行中</v-btn> <v-btn v-show="item.status === ActivityStatus.STARTED" color="ms-2 card-btn-0"
<v-btn v-else-if="item.status === 2" color="ms-2 card-btn-2">已结束</v-btn> >进行中</v-btn
<v-btn v-else color="ms-2 card-btn-1">评选中</v-btn> >
<v-btn v-show="item.status === ActivityStatus.FINISHED" color="ms-2 card-btn-2"
>已结束</v-btn
>
<v-btn v-show="item.status === ActivityStatus.SELECTION" color="ms-2 card-btn-1"
>评选中</v-btn
>
</div> </div>
<v-btn @click="toJson(item.post_id)" class="ms-2 card-btn" v-show="appStore.devMode"> <v-btn @click="toJson(item.post_id)" class="ms-2 card-btn" v-show="appStore.devMode">
<template v-slot:prepend> <template v-slot:prepend>
@@ -116,23 +122,35 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// vue
import { onMounted, ref } from "vue";
import TLoading from "../components/t-loading.vue";
// tauri
import { http, fs } from "@tauri-apps/api";
// store
import useAppStore from "../store/modules/app";
// tools
// @ts-ignore // @ts-ignore
import "../tools/svg-inject.js"; import "../tools/svg-inject.js";
import { onMounted, ref } from "vue"; // utils
import useAppStore from "../store/modules/app";
import {
MysPostType,
ResponseNewsList,
ResponseNews,
EnumPostType,
ResponsePost,
MysPostApi,
MysNewsApi,
} from "../interface/MysPost";
import { http, fs } from "@tauri-apps/api";
import { createTGWindow } from "../utils/TGWindow"; import { createTGWindow } from "../utils/TGWindow";
import { parseMys } from "../utils/MysParse"; import { parseMys } from "../utils/MysParse";
import TLoading from "../components/t-loading.vue"; // interface
import {
Post,
PostResponse,
POST_FULL_API,
POST_FULL_REFERER,
PostData,
} from "../plugins/Mys/interface/post";
import {
NewsResponse,
NewsType,
NEWS_LIST_API,
ActivityStatus,
NewsCard,
NewsItem,
} from "../plugins/Mys/interface/news";
// Store // Store
const appStore = useAppStore(); const appStore = useAppStore();
@@ -142,33 +160,24 @@ const renderMode = ref(appStore.structureRender);
// loading // loading
const loading = ref(true); const loading = ref(true);
// 接口 todo考虑放到 interface 文件夹下?
interface CardDataType {
title: string;
cover: string;
post_id: string;
subtitle: string;
status?: number;
}
// 数据 // 数据
const tab = ref(""); const tab = ref("");
const postData = ref({ const postData = ref({
notice: [] as CardDataType[], notice: [] as NewsCard[],
activity: [] as CardDataType[], activity: [] as NewsCard[],
news: [] as CardDataType[], news: [] as NewsCard[],
}); });
onMounted(async () => { onMounted(async () => {
const noticeRaw: ResponseNewsList = await http const noticeRaw: NewsResponse = await http
.fetch(MysNewsApi + EnumPostType.Notice) .fetch(NEWS_LIST_API.replace("{news_type}", NewsType.NOTICE.toString()))
.then(res => res.data as Promise<ResponseNewsList>); .then(res => res.data as Promise<NewsResponse>);
const activityRaw: ResponseNewsList = await http const activityRaw: NewsResponse = await http
.fetch(MysNewsApi + EnumPostType.Activity) .fetch(NEWS_LIST_API.replace("{news_type}", NewsType.ACTIVITY.toString()))
.then(res => res.data as Promise<ResponseNewsList>); .then(res => res.data as Promise<NewsResponse>);
const newsRaw: ResponseNewsList = await http const newsRaw: NewsResponse = await http
.fetch(MysNewsApi + EnumPostType.News) .fetch(NEWS_LIST_API.replace("{news_type}", NewsType.NEWS.toString()))
.then(res => res.data as Promise<ResponseNewsList>); .then(res => res.data as Promise<NewsResponse>);
postData.value = { postData.value = {
notice: transData(noticeRaw, "notice"), notice: transData(noticeRaw, "notice"),
activity: transData(activityRaw, "activity"), activity: transData(activityRaw, "activity"),
@@ -178,11 +187,11 @@ onMounted(async () => {
loading.value = false; loading.value = false;
}); });
function transData(rawData: ResponseNewsList, dataType: string): CardDataType[] { function transData(rawData: NewsResponse, dataType: string): NewsCard[] {
const cardData: CardDataType[] = []; const cardData: NewsCard[] = [];
rawData.data.list.map((item: ResponseNews) => { rawData.data.list.map((item: NewsItem) => {
const postData: MysPostType = item.post; const postData: Post = item.post;
const card: CardDataType = { const card: NewsCard = {
title: postData.subject, title: postData.subject,
cover: postData.images.length === 0 ? postData.cover : postData.images[0], cover: postData.images.length === 0 ? postData.cover : postData.images[0],
post_id: postData.post_id, post_id: postData.post_id,
@@ -200,7 +209,7 @@ function transData(rawData: ResponseNewsList, dataType: string): CardDataType[]
} }
async function toPost(post_id: string) { async function toPost(post_id: string) {
// 获取帖子内容 // 获取帖子内容
const post: MysPostType = await getPost(post_id).then(res => { const post: Post = await getPost(post_id).then(res => {
return res.data.post.post; return res.data.post.post;
}); });
let parseDoc: Document; let parseDoc: Document;
@@ -233,16 +242,16 @@ async function toJson(post_id: string) {
// 打开窗口 // 打开窗口
createTGWindow(logUrl, "MysPostJson", post_id, 960, 720, false); createTGWindow(logUrl, "MysPostJson", post_id, 960, 720, false);
} }
async function getPost(post_id: string): Promise<ResponsePost> { async function getPost(post_id: string): Promise<PostResponse> {
return http return http
.fetch(`${MysPostApi}${post_id}`, { .fetch(POST_FULL_API.replace("{post_id}", post_id), {
method: "GET", method: "GET",
headers: { headers: {
referer: `https://bbs.mihoyo.com/ys/article/${post_id}`, referer: POST_FULL_REFERER.replace("{post_id}", post_id),
}, },
}) })
.then(res => { .then(res => {
return res.data as Promise<ResponsePost>; return res.data as Promise<PostResponse>;
}); });
} }
</script> </script>

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;
}