mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-07 00:15:48 +08:00
🌈 style(eslint): 第一次过 eslint
姑且先把能过的 ts 文件给过了,明天再过其余的 ts 文件跟 vue Signed-off-by: BTMuli <BT-Muli@outlook.com> (cherry picked from commit b7392bddea895b8b8cc1cad5ba0403d2dc738643)
This commit is contained in:
@@ -25,41 +25,41 @@ import { getCalendarData } from "./request/calendar";
|
||||
import { getCalendarCard } from "./utils/calendar";
|
||||
|
||||
const MysOper = {
|
||||
Post: {
|
||||
get: getPostData,
|
||||
parser: PostParser,
|
||||
},
|
||||
Gacha: {
|
||||
get: getGachaData,
|
||||
card: getGachaCard,
|
||||
},
|
||||
Position: {
|
||||
get: getPositionData,
|
||||
card: getPositionCard,
|
||||
},
|
||||
News: {
|
||||
get: {
|
||||
notice: getNoticeList,
|
||||
activity: getActivityList,
|
||||
news: getNewsList,
|
||||
},
|
||||
card: {
|
||||
notice: getNoticeCard,
|
||||
activity: getActivityCard,
|
||||
news: getNewsCard,
|
||||
},
|
||||
},
|
||||
Lottery: {
|
||||
get: getLotteryData,
|
||||
card: {
|
||||
lottery: getLotteryCard,
|
||||
reward: getLotteryRewardCard,
|
||||
},
|
||||
},
|
||||
Calendar: {
|
||||
get: getCalendarData,
|
||||
card: getCalendarCard,
|
||||
},
|
||||
Post: {
|
||||
get: getPostData,
|
||||
parser: PostParser,
|
||||
},
|
||||
Gacha: {
|
||||
get: getGachaData,
|
||||
card: getGachaCard,
|
||||
},
|
||||
Position: {
|
||||
get: getPositionData,
|
||||
card: getPositionCard,
|
||||
},
|
||||
News: {
|
||||
get: {
|
||||
notice: getNoticeList,
|
||||
activity: getActivityList,
|
||||
news: getNewsList,
|
||||
},
|
||||
card: {
|
||||
notice: getNoticeCard,
|
||||
activity: getActivityCard,
|
||||
news: getNewsCard,
|
||||
},
|
||||
},
|
||||
Lottery: {
|
||||
get: getLotteryData,
|
||||
card: {
|
||||
lottery: getLotteryCard,
|
||||
reward: getLotteryRewardCard,
|
||||
},
|
||||
},
|
||||
Calendar: {
|
||||
get: getCalendarData,
|
||||
card: getCalendarCard,
|
||||
},
|
||||
};
|
||||
|
||||
export default MysOper;
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
* @property {number} retcode 状态码
|
||||
* @property {string} message 状态信息
|
||||
* @property {any} data 数据
|
||||
* @return {MysResponse}
|
||||
* @returns {MysResponse}
|
||||
*/
|
||||
export interface MysResponse {
|
||||
retcode: number;
|
||||
message: string;
|
||||
data: any;
|
||||
retcode: number
|
||||
message: string
|
||||
data: any
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,12 +26,12 @@ export interface MysResponse {
|
||||
* @interface MysObcResponse
|
||||
* @extends MysResponse
|
||||
* @property {MysObc[]} data.list obc 列表
|
||||
* @return {MysObcResponse}
|
||||
* @returns {MysObcResponse}
|
||||
*/
|
||||
export interface MysObcResponse extends MysResponse {
|
||||
data: {
|
||||
list: MysObc[];
|
||||
};
|
||||
data: {
|
||||
list: MysObc[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,16 +45,16 @@ export interface MysObcResponse extends MysResponse {
|
||||
* @property {string} ch_ext 结构化扩展信息
|
||||
* @property {any[]} children 子节点
|
||||
* @property {unknown[]} list 列表
|
||||
* @return {MysObc}
|
||||
* @returns {MysObc}
|
||||
*/
|
||||
export interface MysObc {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_id: number;
|
||||
depth: number;
|
||||
ch_ext: string;
|
||||
children: MysObc[];
|
||||
list: unknown[];
|
||||
id: number
|
||||
name: string
|
||||
parent_id: number
|
||||
depth: number
|
||||
ch_ext: string
|
||||
children: MysObc[]
|
||||
list: unknown[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,14 +69,14 @@ export interface MysObc {
|
||||
* @property {number} 5 大别野
|
||||
* @property {number} 6 崩坏:星穹铁道
|
||||
* @property {number} 8 绝区零
|
||||
* @return {MysGid}
|
||||
* @returns {MysGid}
|
||||
*/
|
||||
export enum MysGid {
|
||||
BH3 = 1,
|
||||
YS = 2,
|
||||
BH2 = 3,
|
||||
WD = 4,
|
||||
DBY = 5,
|
||||
SR = 6,
|
||||
ZZZ = 8,
|
||||
BH3 = 1,
|
||||
YS = 2,
|
||||
BH2 = 3,
|
||||
WD = 4,
|
||||
DBY = 5,
|
||||
SR = 6,
|
||||
ZZZ = 8,
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { Map } from "../../../interface/Base";
|
||||
import { type MysResponse } from "./base";
|
||||
import { type Map } from "../../../interface/Base";
|
||||
|
||||
/**
|
||||
* @description 日历返回数据
|
||||
@@ -14,12 +14,12 @@ import { Map } from "../../../interface/Base";
|
||||
* @interface CalendarResponse
|
||||
* @extends {MysResponse}
|
||||
* @property {CalendarData[]} data.list 日历数据
|
||||
* @return {CalendarResponse}
|
||||
* @returns {CalendarResponse}
|
||||
*/
|
||||
export interface CalendarResponse extends MysResponse {
|
||||
data: {
|
||||
list: CalendarData[];
|
||||
};
|
||||
data: {
|
||||
list: CalendarData[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,26 +43,26 @@ export interface CalendarResponse extends MysResponse {
|
||||
* @property {CalendarContent[]} contentInfos 材料内容,kind 为 2 时不为空
|
||||
* @property {string} sort 排序,kind 为 2 时不为空,反序列化后为 Map<number, number>,前者为星期,后者为排序
|
||||
* @property {CalendarContent[]} contentSource 材料来源,kind 为 2 时不为空
|
||||
* @return {CalendarData}
|
||||
* @returns {CalendarData}
|
||||
*/
|
||||
export interface CalendarData {
|
||||
id: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
img_url: string;
|
||||
jump_type: string;
|
||||
jump_url: string;
|
||||
content_id: string;
|
||||
style: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
font_color: string;
|
||||
padding_color: string;
|
||||
drop_day: string[];
|
||||
break_type: string;
|
||||
contentInfos: CalendarContent[];
|
||||
sort: string;
|
||||
contentSource: CalendarContent[];
|
||||
id: string
|
||||
title: string
|
||||
kind: string
|
||||
img_url: string
|
||||
jump_type: string
|
||||
jump_url: string
|
||||
content_id: string
|
||||
style: string
|
||||
start_time: string
|
||||
end_time: string
|
||||
font_color: string
|
||||
padding_color: string
|
||||
drop_day: string[]
|
||||
break_type: string
|
||||
contentInfos: CalendarContent[]
|
||||
sort: string
|
||||
contentSource: CalendarContent[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,13 +73,13 @@ export interface CalendarData {
|
||||
* @property {string} title 材料/秘境 名称
|
||||
* @property {string} icon 材料/秘境 图片 URL
|
||||
* @property {string} bbs_url 链接,一般为空
|
||||
* @return {CalendarContent}
|
||||
* @returns {CalendarContent}
|
||||
*/
|
||||
export interface CalendarContent {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
bbs_url: string;
|
||||
id: string
|
||||
title: string
|
||||
icon: string
|
||||
bbs_url: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,15 +94,15 @@ export interface CalendarContent {
|
||||
* @property {string[]} drop_day 掉落日
|
||||
* @property {Map<number>} sort_day 排序
|
||||
* @property {CalendarContent[]} contentInfos 材料内容
|
||||
* @return {CalendarCard}
|
||||
* @returns {CalendarCard}
|
||||
*/
|
||||
export interface CalendarCard {
|
||||
id: number;
|
||||
type: number;
|
||||
title: string;
|
||||
cover: string;
|
||||
url: string;
|
||||
drop_day: string[];
|
||||
sort_day: Map<number>;
|
||||
contentInfos: CalendarContent[];
|
||||
id: number
|
||||
type: number
|
||||
title: string
|
||||
cover: string
|
||||
url: string
|
||||
drop_day: string[]
|
||||
sort_day: Map<number>
|
||||
contentInfos: CalendarContent[]
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @since Alpha
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { type MysResponse } from "./base";
|
||||
|
||||
/**
|
||||
* @description 获取卡池信息的返回类型
|
||||
@@ -13,12 +13,12 @@ import { MysResponse } from "./base";
|
||||
* @interface GachaResponse
|
||||
* @extends MysResponse
|
||||
* @property {GachaData[]} data.list 卡池数据
|
||||
* @return {GachaResponse}
|
||||
* @returns {GachaResponse}
|
||||
*/
|
||||
export interface GachaResponse extends MysResponse {
|
||||
data: {
|
||||
list: GachaData[];
|
||||
};
|
||||
data: {
|
||||
list: GachaData[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,19 +36,19 @@ export interface GachaResponse extends MysResponse {
|
||||
* @description 如下时间示例:2023-03-21 17:59:59
|
||||
* @property {string} start_time 卡池开始时间
|
||||
* @property {string} end_time 卡池结束时间
|
||||
* @return {GachaData}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,11 +57,11 @@ export interface GachaData {
|
||||
* @interface GachaPool
|
||||
* @property {string} icon 卡池角色头像
|
||||
* @property {string} url 卡池角色URL
|
||||
* @return {GachaPool}
|
||||
* @returns {GachaPool}
|
||||
*/
|
||||
export interface GachaPool {
|
||||
icon: string;
|
||||
url: string;
|
||||
icon: string
|
||||
url: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,19 +79,19 @@ export interface GachaPool {
|
||||
* @property {string} time.start_stamp 卡池开始时间戳
|
||||
* @property {string} time.end 卡池结束时间
|
||||
* @property {string} time.end_stamp 卡池结束时间戳
|
||||
* @return {GachaCard}
|
||||
* @returns {GachaCard}
|
||||
*/
|
||||
export interface GachaCard {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
cover: string;
|
||||
post_id: number;
|
||||
characters: GachaPool[];
|
||||
voice: GachaPool;
|
||||
time: {
|
||||
start: string;
|
||||
start_stamp: number;
|
||||
end: string;
|
||||
end_stamp: number;
|
||||
};
|
||||
title: string
|
||||
subtitle: string
|
||||
cover: string
|
||||
post_id: number
|
||||
characters: GachaPool[]
|
||||
voice: GachaPool
|
||||
time: {
|
||||
start: string
|
||||
start_stamp: number
|
||||
end: string
|
||||
end_stamp: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* @file plugins Mys interface lottery.ts
|
||||
* @description Mys 插件抽奖接口
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { User } from "./user";
|
||||
import { type MysResponse } from "./base";
|
||||
import { type User } from "./user";
|
||||
|
||||
/**
|
||||
* @description 抽奖返回数据
|
||||
@@ -14,12 +14,12 @@ import { User } from "./user";
|
||||
* @interface LotteryResponse
|
||||
* @extends {MysResponse}
|
||||
* @property {LotteryData} data.show_lottery 抽奖数据
|
||||
* @return {LotteryResponse}
|
||||
* @returns {LotteryResponse}
|
||||
*/
|
||||
export interface LotteryResponse extends MysResponse {
|
||||
data: {
|
||||
show_lottery: LotteryData;
|
||||
};
|
||||
data: {
|
||||
show_lottery: LotteryData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,24 +41,24 @@ export interface LotteryResponse extends MysResponse {
|
||||
* @property {string} entity_id 实体 ID // 若为帖子,则为帖子 ID
|
||||
* @property {string} entity_type 实体类型 // Post: 帖子
|
||||
* @property {string} now_time 当前时间
|
||||
* @return {LotteryData}
|
||||
* @returns {LotteryData}
|
||||
*/
|
||||
export interface LotteryData {
|
||||
id: string;
|
||||
creator: User;
|
||||
draw_time: string;
|
||||
participant_way: string;
|
||||
is_expect_unfocus_user: boolean;
|
||||
is_expect_non_real_name_user: boolean;
|
||||
user_rewards: LotteryReward[];
|
||||
status: string;
|
||||
is_blocked: boolean;
|
||||
user_status: string;
|
||||
is_upload_address: boolean;
|
||||
lottery_entity_summary: string;
|
||||
entity_id: string;
|
||||
entity_type: string;
|
||||
now_time: string;
|
||||
id: string
|
||||
creator: User
|
||||
draw_time: string
|
||||
participant_way: string
|
||||
is_expect_unfocus_user: boolean
|
||||
is_expect_non_real_name_user: boolean
|
||||
user_rewards: LotteryReward[]
|
||||
status: string
|
||||
is_blocked: boolean
|
||||
user_status: string
|
||||
is_upload_address: boolean
|
||||
lottery_entity_summary: string
|
||||
entity_id: string
|
||||
entity_type: string
|
||||
now_time: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,15 +71,15 @@ export interface LotteryData {
|
||||
* @property {boolean} is_send_by_post 是否通过帖子发放
|
||||
* @property {User[]} users 用户列表
|
||||
* @property {string} id 奖励 ID
|
||||
* @return {LotteryReward}
|
||||
* @returns {LotteryReward}
|
||||
*/
|
||||
export interface LotteryReward {
|
||||
reward_name: string;
|
||||
winner_number: number;
|
||||
scheduled_winner_number: number;
|
||||
is_send_by_post: boolean;
|
||||
users: User[];
|
||||
id: string;
|
||||
reward_name: string
|
||||
winner_number: number
|
||||
scheduled_winner_number: number
|
||||
is_send_by_post: boolean
|
||||
users: User[]
|
||||
id: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,29 +92,30 @@ export interface LotteryReward {
|
||||
* @property {User} creator 创建者
|
||||
* @property {string} drawTime 开奖时间
|
||||
* @property {LotteryRewardCard[]} rewards 奖励列表
|
||||
* @return {LotteryCard}
|
||||
* @returns {LotteryCard}
|
||||
*/
|
||||
export interface LotteryCard {
|
||||
id: string;
|
||||
participantWay: string;
|
||||
status: string;
|
||||
creator: User;
|
||||
drawTime: string;
|
||||
rewards: LotteryRewardCard[];
|
||||
id: string
|
||||
participantWay: string
|
||||
status: string
|
||||
creator: User
|
||||
drawTime: string
|
||||
rewards: LotteryRewardCard[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 渲染用的奖励信息
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
* @interface LotteryRewardCard
|
||||
* @property {string} rewardName 奖励名称
|
||||
* @property {number} winnerNumber 获奖人数
|
||||
* @property {number} scheduledWinnerNumber 预计获奖人数
|
||||
* @property {User[]} users 用户列表
|
||||
* @returns {LotteryRewardCard}
|
||||
*/
|
||||
export interface LotteryRewardCard {
|
||||
rewardName: string;
|
||||
winnerNumber: number;
|
||||
scheduledWinnerNumber: number;
|
||||
users: User[];
|
||||
rewardName: string
|
||||
winnerNumber: number
|
||||
scheduledWinnerNumber: number
|
||||
users: User[]
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
* @since Alpha
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { Post, Forum, Topic, PostStat } from "./post";
|
||||
import { User, SelfOperation } from "./user";
|
||||
import { ImageData, HelpSys } from "./utils";
|
||||
import { type MysResponse } from "./base";
|
||||
import { type Post, type Forum, type Topic, type PostStat } from "./post";
|
||||
import { type User, type SelfOperation } from "./user";
|
||||
import { type ImageData, type HelpSys } from "./utils";
|
||||
|
||||
/**
|
||||
* @description 咨讯返回数据
|
||||
@@ -16,10 +16,10 @@ import { ImageData, HelpSys } from "./utils";
|
||||
* @interface NewsResponse
|
||||
* @extends {MysResponse}
|
||||
* @property {NewsData} data 咨讯数据
|
||||
* @return {NewsResponse}
|
||||
* @returns {NewsResponse}
|
||||
*/
|
||||
export interface NewsResponse extends MysResponse {
|
||||
data: NewsData;
|
||||
data: NewsData
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,12 +29,12 @@ export interface NewsResponse extends MysResponse {
|
||||
* @property {number} last_id 最后一条咨讯 ID
|
||||
* @property {boolean} is_last 是否最后一页
|
||||
* @property {NewsItem[]} list 咨讯列表
|
||||
* @return {NewsData}
|
||||
* @returns {NewsData}
|
||||
*/
|
||||
export interface NewsData {
|
||||
last_id: number;
|
||||
is_last: boolean;
|
||||
list: NewsItem[];
|
||||
last_id: number
|
||||
is_last: boolean
|
||||
list: NewsItem[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,30 +62,30 @@ export interface NewsData {
|
||||
* @property {unknown} forum_rank_info 版块排名信息,可能为 null // TODO: 未知
|
||||
* @property {unknown[]} link_card_list 链接卡片列表,可能为 null // TODO: 未知
|
||||
* @property {NewsMeta} news_meta 元数据
|
||||
* @return {NewsItem}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +95,12 @@ export interface NewsItem {
|
||||
* @property {number} activity_status 活动状态 // ActivityStatus
|
||||
* @property {string} start_at_sec 活动开始时间戳,单位秒
|
||||
* @property {string} end_at_sec 活动结束时间戳,单位秒
|
||||
* @return {NewsMeta}
|
||||
* @returns {NewsMeta}
|
||||
*/
|
||||
export interface NewsMeta {
|
||||
activity_status: number;
|
||||
start_at_sec: string;
|
||||
end_at_sec: string;
|
||||
activity_status: number
|
||||
start_at_sec: string
|
||||
end_at_sec: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,14 +112,14 @@ export interface NewsMeta {
|
||||
* @property {number} post_id 帖子 ID
|
||||
* @property {string} subtitle 副标题
|
||||
* @property {ActivityStatus} status 活动状态,仅活动咨讯有
|
||||
* @return {NewsCard}
|
||||
* @returns {NewsCard}
|
||||
*/
|
||||
export interface NewsCard {
|
||||
title: string;
|
||||
cover: string;
|
||||
post_id: number;
|
||||
subtitle: string;
|
||||
status?: ActivityStatus;
|
||||
title: string
|
||||
cover: string
|
||||
post_id: number
|
||||
subtitle: string
|
||||
status?: ActivityStatus
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,9 +127,9 @@ export interface NewsCard {
|
||||
* @since Alpha
|
||||
* @property {string} status 活动状态
|
||||
* @property {string} colorCss 活动状态按钮背景色
|
||||
* @return {ActivityStatus}
|
||||
* @returns {ActivityStatus}
|
||||
*/
|
||||
export interface ActivityStatus {
|
||||
status: string;
|
||||
colorCss: string;
|
||||
status: string
|
||||
colorCss: string
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { MysObcResponse, MysObc } from "./base";
|
||||
import { type MysObcResponse, type MysObc } from "./base";
|
||||
|
||||
/**
|
||||
* @description 获取热点追踪信息的返回类型
|
||||
@@ -13,12 +13,12 @@ import { MysObcResponse, MysObc } from "./base";
|
||||
* @interface PositionResponse
|
||||
* @extends MysObcResponse
|
||||
* @property {PositionObc[]} data.list obc 列表
|
||||
* @return {PositionResponse}
|
||||
* @returns {PositionResponse}
|
||||
*/
|
||||
export interface PositionResponse extends MysObcResponse {
|
||||
data: {
|
||||
list: PositionObc[];
|
||||
};
|
||||
data: {
|
||||
list: PositionObc[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,10 +27,10 @@ export interface PositionResponse extends MysObcResponse {
|
||||
* @interface PositionObc
|
||||
* @extends MysObc
|
||||
* @property {PositionData[]} list 列表
|
||||
* @return {PositionObc}
|
||||
* @returns {PositionObc}
|
||||
*/
|
||||
export interface PositionObc extends MysObc {
|
||||
list: PositionData[];
|
||||
list: PositionData[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,22 +50,22 @@ export interface PositionObc extends MysObc {
|
||||
* @property {string} article_time 时间
|
||||
* @property {string} create_time 创建时间 // 2023-03-31 11:16:57
|
||||
* @property {string} end_time 结束时间 // 1680465599000
|
||||
* @return {PositionData}
|
||||
* @returns {PositionData}
|
||||
*/
|
||||
export interface PositionData {
|
||||
recommend_id: number;
|
||||
content_id: number;
|
||||
title: string;
|
||||
ext: string;
|
||||
type: number;
|
||||
url: string;
|
||||
icon: string;
|
||||
abstract: string;
|
||||
article_user_name: string;
|
||||
avatar_url: string;
|
||||
article_time: string;
|
||||
create_time: string;
|
||||
end_time: string;
|
||||
recommend_id: number
|
||||
content_id: number
|
||||
title: string
|
||||
ext: string
|
||||
type: number
|
||||
url: string
|
||||
icon: string
|
||||
abstract: string
|
||||
article_user_name: string
|
||||
avatar_url: string
|
||||
article_time: string
|
||||
create_time: string
|
||||
end_time: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,17 +81,17 @@ export interface PositionData {
|
||||
* @property {number} time.start_stamp 开始时间戳
|
||||
* @property {string} time.end 结束时间
|
||||
* @property {number} time.end_stamp 结束时间戳
|
||||
* @return {PositionCard}
|
||||
* @returns {PositionCard}
|
||||
*/
|
||||
export interface PositionCard {
|
||||
title: string;
|
||||
post_id: number;
|
||||
icon: string;
|
||||
abstract: string;
|
||||
time: {
|
||||
start: string;
|
||||
start_stamp: number;
|
||||
end: string;
|
||||
end_stamp: number;
|
||||
};
|
||||
title: string
|
||||
post_id: number
|
||||
icon: string
|
||||
abstract: string
|
||||
time: {
|
||||
start: string
|
||||
start_stamp: number
|
||||
end: string
|
||||
end_stamp: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { NewsMeta } from "./news";
|
||||
import { User, SelfOperation } from "./user";
|
||||
import { ImageData, HelpSys } from "./utils";
|
||||
import { type MysResponse } from "./base";
|
||||
import { type NewsMeta } from "./news";
|
||||
import { type User, type SelfOperation } from "./user";
|
||||
import { type ImageData, type HelpSys } from "./utils";
|
||||
|
||||
/**
|
||||
* @description 帖子返回数据
|
||||
@@ -16,12 +16,12 @@ import { ImageData, HelpSys } from "./utils";
|
||||
* @interface PostResponse
|
||||
* @extends {MysResponse}
|
||||
* @property {PostData} data.post 帖子数据
|
||||
* @return {PostResponse}
|
||||
* @returns {PostResponse}
|
||||
*/
|
||||
export interface PostResponse extends MysResponse {
|
||||
data: {
|
||||
post: PostData;
|
||||
};
|
||||
data: {
|
||||
post: PostData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,30 +49,30 @@ export interface PostResponse extends MysResponse {
|
||||
* @property {unknown} forum_rank_info 版块排行信息,可能为 null // TODO: 未知
|
||||
* @property {unknown[]} link_card_list 链接卡片列表,可能为空 // TODO: 未知
|
||||
* @property {NewsMeta} news_meta 咨讯元数据,可能为 null
|
||||
* @return {PostData}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,49 +118,49 @@ export interface PostData {
|
||||
* @property {boolean} is_showing_missing 是否显示缺失 // TODO: 未知
|
||||
* @property {number} block_latest_reply_time 是否屏蔽最新回复时间 // TODO: 未知
|
||||
* @property {number} selected_comment 是否选择评论 // TODO: 未知
|
||||
* @return {Post}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,14 +172,14 @@ export interface Post {
|
||||
* @property {string} icon 版块图标 URL
|
||||
* @property {number} game_id 游戏 ID // 2 为原神
|
||||
* @property {unknown} forum_cate 版块分类,可能为 null
|
||||
* @return {Forum}
|
||||
* @returns {Forum}
|
||||
*/
|
||||
export interface Forum {
|
||||
id: number;
|
||||
name: string;
|
||||
icon: string;
|
||||
game_id: number;
|
||||
forum_cate: unknown | null;
|
||||
id: number
|
||||
name: string
|
||||
icon: string
|
||||
game_id: number
|
||||
forum_cate: unknown | null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,17 +194,17 @@ export interface Forum {
|
||||
* @property {boolean} is_interactive 是否互动
|
||||
* @property {number} game_id 游戏 ID
|
||||
* @property {number} content_type 内容类型
|
||||
* @return {Topic}
|
||||
* @returns {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;
|
||||
id: number
|
||||
name: string
|
||||
cover: string
|
||||
is_top: boolean
|
||||
is_good: boolean
|
||||
is_interactive: boolean
|
||||
game_id: number
|
||||
content_type: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,14 +216,14 @@ export interface Topic {
|
||||
* @property {number} like_num 点赞数
|
||||
* @property {number} bookmark_num 收藏数
|
||||
* @property {number} forward_num 转发数
|
||||
* @return {PostStat}
|
||||
* @returns {PostStat}
|
||||
*/
|
||||
export interface PostStat {
|
||||
view_num: number;
|
||||
reply_num: number;
|
||||
like_num: number;
|
||||
bookmark_num: number;
|
||||
forward_num: number;
|
||||
view_num: number
|
||||
reply_num: number
|
||||
like_num: number
|
||||
bookmark_num: number
|
||||
forward_num: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,11 +233,11 @@ export interface PostStat {
|
||||
* @interface PostContent
|
||||
* @property {string} describe 描述
|
||||
* @property {string[]} imgs 图片 URL
|
||||
* @return {PostContent}
|
||||
* @returns {PostContent}
|
||||
*/
|
||||
export interface PostContent {
|
||||
describe: string;
|
||||
imgs?: string[];
|
||||
describe: string
|
||||
imgs?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,36 +265,36 @@ export interface PostContent {
|
||||
* @property {boolean} attributes.bold 是否加粗
|
||||
* @property {string} attributes.color 颜色
|
||||
* @property {string} attributes.link 链接
|
||||
* @return {PostStructuredContent}
|
||||
* @returns {PostStructuredContent}
|
||||
*/
|
||||
export interface PostStructuredContent {
|
||||
insert:
|
||||
| {
|
||||
image?: string;
|
||||
video?: string;
|
||||
vod?: PostStructuredContentVod;
|
||||
backup_text?: string;
|
||||
lottery?: {
|
||||
id: string;
|
||||
toast: string;
|
||||
};
|
||||
fold?: {
|
||||
title: string;
|
||||
content: string;
|
||||
};
|
||||
link_card?: PostStructuredContentLinkCard;
|
||||
divider?: string;
|
||||
}
|
||||
| string;
|
||||
attributes?: {
|
||||
height?: number;
|
||||
width?: number;
|
||||
size?: number;
|
||||
ext?: string;
|
||||
bold?: boolean;
|
||||
color?: string;
|
||||
link?: string;
|
||||
};
|
||||
insert:
|
||||
| {
|
||||
image?: string
|
||||
video?: string
|
||||
vod?: PostStructuredContentVod
|
||||
backup_text?: string
|
||||
lottery?: {
|
||||
id: string
|
||||
toast: string
|
||||
}
|
||||
fold?: {
|
||||
title: string
|
||||
content: string
|
||||
}
|
||||
link_card?: PostStructuredContentLinkCard
|
||||
divider?: string
|
||||
}
|
||||
| string
|
||||
attributes?: {
|
||||
height?: number
|
||||
width?: number
|
||||
size?: number
|
||||
ext?: string
|
||||
bold?: boolean
|
||||
color?: string
|
||||
link?: string
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,25 +316,25 @@ export interface PostStructuredContent {
|
||||
* @property {number} view_num 浏览数
|
||||
* @property {number} transcode_status 转码状态
|
||||
* @property {number} review_status 审核状态
|
||||
* @return {PostStructuredContentVod}
|
||||
* @returns {PostStructuredContentVod}
|
||||
*/
|
||||
export interface PostStructuredContentVod {
|
||||
id: number;
|
||||
duration: number;
|
||||
cover: string;
|
||||
resolutions: {
|
||||
url: string;
|
||||
definition: string;
|
||||
height: number;
|
||||
width: number;
|
||||
bitrate: number;
|
||||
size: number;
|
||||
format: string;
|
||||
label: string;
|
||||
}[];
|
||||
view_num: number;
|
||||
transcoding_status: number;
|
||||
review_status: number;
|
||||
id: number
|
||||
duration: number
|
||||
cover: string
|
||||
resolutions: Array<{
|
||||
url: string
|
||||
definition: string
|
||||
height: number
|
||||
width: number
|
||||
bitrate: number
|
||||
size: number
|
||||
format: string
|
||||
label: string
|
||||
}>
|
||||
view_num: number
|
||||
transcoding_status: number
|
||||
review_status: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,18 +352,18 @@ export interface PostStructuredContentVod {
|
||||
* @property {string} price 价格
|
||||
* @property {string} button_text 按钮文本
|
||||
* @property {number} landing_url_type 落地链接类型 // TODO: 未知
|
||||
* @return {PostStructuredContentLinkCard}
|
||||
* @returns {PostStructuredContentLinkCard}
|
||||
*/
|
||||
export interface PostStructuredContentLinkCard {
|
||||
link_type: number;
|
||||
origin_url: string;
|
||||
landing_url: string;
|
||||
cover: string;
|
||||
title: string;
|
||||
card_id: string;
|
||||
card_status: number;
|
||||
market_price: string;
|
||||
price: string;
|
||||
button_text: string;
|
||||
landing_url_type: number;
|
||||
link_type: number
|
||||
origin_url: string
|
||||
landing_url: string
|
||||
cover: string
|
||||
title: string
|
||||
card_id: string
|
||||
card_status: number
|
||||
market_price: string
|
||||
price: string
|
||||
button_text: string
|
||||
landing_url_type: number
|
||||
}
|
||||
|
||||
@@ -26,26 +26,26 @@
|
||||
* @property {boolean} is_follower 是否被关注
|
||||
* @property {string} avatar_url 用户头像链接
|
||||
* @property {string} pendant 用户挂件 URL,可能为 ""
|
||||
* @return {User}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,9 +54,9 @@ export interface User {
|
||||
* @interface SelfOperation
|
||||
* @property {number} attitude 操作类型 // TODO: 未知
|
||||
* @property {boolean} is_collected 是否收藏
|
||||
* @return {SelfOperation}
|
||||
* @returns {SelfOperation}
|
||||
*/
|
||||
export interface SelfOperation {
|
||||
attitude: number;
|
||||
is_collected: boolean;
|
||||
attitude: number
|
||||
is_collected: boolean
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* @description 观测枢 content API
|
||||
* @since Alpha
|
||||
* @param {string} content_id 内容 ID
|
||||
* @return {string} API
|
||||
* @returns {string} API
|
||||
*/
|
||||
export const OBC_CONTENT_API =
|
||||
"https://bbs.mihoyo.com/ys/obc/content/{content_id}/detail?bbs_presentation_style=no_header";
|
||||
@@ -38,26 +38,26 @@ export const OBC_CONTENT_API =
|
||||
* @property {string} entity_type 图片类型 // IMG_ENTITY_POST, IMG_ENTITY_UNKOWN
|
||||
* @property {string} entity_id 图片 ID
|
||||
* @property {boolean} is_deleted 是否已删除
|
||||
* @return {ImageData}
|
||||
* @returns {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;
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +68,10 @@ export interface ImageData {
|
||||
* @property {unknown} top_up 置顶, 可能为 null // TODO: 未知
|
||||
* @property {unknown[]} top_n 置顶, 可能为空
|
||||
* @property {number} answer_num 回答数
|
||||
* @return {HelpSys}
|
||||
* @returns {HelpSys}
|
||||
*/
|
||||
export interface HelpSys {
|
||||
top_up: unknown | null;
|
||||
top_n: unknown[];
|
||||
answer_num: number;
|
||||
top_up: unknown | null
|
||||
top_n: unknown[]
|
||||
answer_num: number
|
||||
}
|
||||
|
||||
@@ -6,27 +6,26 @@
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { CalendarResponse, CalendarData } from "../interface/calendar";
|
||||
import { type CalendarResponse, type CalendarData } from "../interface/calendar";
|
||||
|
||||
// 日历 API
|
||||
const CALENDAR_API =
|
||||
"https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/get_activity_calendar?app_sn=ys_obc";
|
||||
const CALENDAR_API = "https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/get_activity_calendar?app_sn=ys_obc";
|
||||
|
||||
/**
|
||||
* @description 日历请求
|
||||
* @since Alpha v0.1.1
|
||||
* @return {Promise<CalendarData[]>}
|
||||
*/
|
||||
export async function getCalendarData(): Promise<CalendarData[]> {
|
||||
const res = await http
|
||||
.fetch<CalendarResponse>(CALENDAR_API, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.list;
|
||||
});
|
||||
return res.filter(item => item.kind === "2");
|
||||
export async function getCalendarData (): Promise<CalendarData[]> {
|
||||
const res = await http
|
||||
.fetch<CalendarResponse>(CALENDAR_API, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
return res.data.data.list;
|
||||
});
|
||||
return res.filter((item) => item.kind === "2");
|
||||
}
|
||||
|
||||
@@ -6,26 +6,25 @@
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { GachaResponse, GachaData } from "../interface/gacha";
|
||||
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";
|
||||
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;
|
||||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
* @file plugins Mys interface lottery.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";
|
||||
import { LotteryResponse, LotteryData } from "../interface/lottery";
|
||||
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}";
|
||||
const LOTTERY_API = "https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show?gids=2&id={lottery_id}";
|
||||
|
||||
/**
|
||||
* @description 获取抽奖信息
|
||||
* @since Alpha v0.1.1
|
||||
* @param {string} lottery_id 抽奖 ID
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} lotteryId 抽奖 ID
|
||||
* @return {Promise<LotteryData>}
|
||||
*/
|
||||
export async function getLotteryData(lottery_id: string): Promise<LotteryData> {
|
||||
return await http
|
||||
.fetch<LotteryResponse>(LOTTERY_API.replace("{lottery_id}", lottery_id), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.show_lottery;
|
||||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { NewsData, NewsResponse } from "../interface/news";
|
||||
import { type NewsData, type NewsResponse } from "../interface/news";
|
||||
|
||||
// 咨讯 API
|
||||
const NEWS_LIST_API =
|
||||
@@ -22,67 +22,61 @@ const NEWS_LIST_API =
|
||||
* @return {NewsType}
|
||||
*/
|
||||
enum NewsType {
|
||||
NOTICE = "1",
|
||||
ACTIVITY = "2",
|
||||
NEWS = "3",
|
||||
NOTICE = "1",
|
||||
ACTIVITY = "2",
|
||||
NEWS = "3",
|
||||
}
|
||||
|
||||
// todo: 考虑使用泛型
|
||||
|
||||
/**
|
||||
* @description 获取 Notice 列表
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} gid gid: 1 为崩坏3, 2 为原神,3 为崩坏2,4 为未定事件簿,5 为大别野,6 为崩坏:星穹铁道,8 为绝区零
|
||||
* @param {number} page_size 返回数量
|
||||
* @param {number} last_id 上一次请求的最后一条数据的 id
|
||||
* @param {number} pageSize 返回数量
|
||||
* @param {number} lastId 上一次请求的最后一条数据的 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);
|
||||
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 为崩坏2,4 为未定事件簿,5 为大别野,6 为崩坏:星穹铁道,8 为绝区零
|
||||
* @param {number} page_size 返回数量
|
||||
* @param {number} last_id 上一次请求的最后一条数据的 id
|
||||
* @param {number} pageSize 返回数量
|
||||
* @param {number} lastId 上一次请求的最后一条数据的 id
|
||||
* @return {Promise<NewsData>}
|
||||
*/
|
||||
export async function getActivityList(
|
||||
gid: string = "2",
|
||||
page_size: number = 20,
|
||||
last_id: number = 0
|
||||
export async function getActivityList (
|
||||
gid: string = "2",
|
||||
pageSize: number = 20,
|
||||
lastId: 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);
|
||||
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 为崩坏2,4 为未定事件簿,5 为大别野,6 为崩坏:星穹铁道,8 为绝区零
|
||||
* @param {number} page_size 返回数量
|
||||
* @param {number} last_id 上一次请求的最后一条数据的 id
|
||||
* @param {number} pageSize 返回数量
|
||||
* @param {number} lastId 上一次请求的最后一条数据的 id
|
||||
* @return {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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -2,32 +2,31 @@
|
||||
* @file plugins Mys request position.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";
|
||||
import { PositionResponse, PositionData, PositionObc } from "../interface/position";
|
||||
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";
|
||||
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 as PositionObc[]);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { PostResponse, PostData } from "../interface/post";
|
||||
import { type PostResponse, type PostData } from "../interface/post";
|
||||
|
||||
// 帖子 API
|
||||
const POST_API = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?post_id={post_id}";
|
||||
@@ -15,19 +15,19 @@ const POST_REFERER = "https://bbs.mihoyo.com/";
|
||||
/**
|
||||
* @description 获取帖子信息
|
||||
* @since Alpha v0.1.2
|
||||
* @param {number} post_id 帖子 ID
|
||||
* @param {number} postId 帖子 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,
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.post;
|
||||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,27 +5,27 @@
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { CalendarData, CalendarCard } from "../interface/calendar";
|
||||
import { type CalendarData, type CalendarCard } from "../interface/calendar";
|
||||
|
||||
/**
|
||||
* @description 将日历数据转换为卡片数据
|
||||
* @since Alpha v0.1.1
|
||||
* @param {CalendarData[]} calendarData 日历数据
|
||||
* @return {CalendarCard[]}
|
||||
* @returns {CalendarCard[]}
|
||||
*/
|
||||
export function getCalendarCard(calendarData: CalendarData[]): CalendarCard[] {
|
||||
const calendarCard: CalendarCard[] = [];
|
||||
calendarData.forEach((data: CalendarData) => {
|
||||
return calendarCard.push({
|
||||
id: Number(data.id),
|
||||
type: Number(data.break_type),
|
||||
title: data.title,
|
||||
cover: data.img_url,
|
||||
url: data.jump_type === "1" ? data.jump_url : data.content_id,
|
||||
drop_day: data.drop_day,
|
||||
sort_day: JSON.parse(data.sort),
|
||||
contentInfos: data.contentInfos,
|
||||
});
|
||||
});
|
||||
return calendarCard;
|
||||
export function getCalendarCard (calendarData: CalendarData[]): CalendarCard[] {
|
||||
const calendarCard: CalendarCard[] = [];
|
||||
calendarData.forEach((data: CalendarData) => {
|
||||
return calendarCard.push({
|
||||
id: Number(data.id),
|
||||
type: Number(data.break_type),
|
||||
title: data.title,
|
||||
cover: data.img_url,
|
||||
url: data.jump_type === "1" ? data.jump_url : data.content_id,
|
||||
drop_day: data.drop_day,
|
||||
sort_day: JSON.parse(data.sort),
|
||||
contentInfos: data.contentInfos,
|
||||
});
|
||||
});
|
||||
return calendarCard;
|
||||
}
|
||||
|
||||
@@ -6,60 +6,60 @@
|
||||
*/
|
||||
|
||||
import { getPostData } from "../request/post";
|
||||
import { GachaCard, GachaData } from "../interface/gacha";
|
||||
import { Map } from "../../../interface/Base";
|
||||
import { type GachaCard, type GachaData } from "../interface/gacha";
|
||||
import { type Map } from "../../../interface/Base";
|
||||
|
||||
/**
|
||||
* @description 根据卡池信息转为渲染用的卡池信息
|
||||
* @since Alpha v0.1.2
|
||||
* @param {GachaData[]} gachaData 卡池信息
|
||||
* @param {Map<string>} poolCover 卡池封面
|
||||
* @return {Promise<GachaCard[]>}
|
||||
* @returns {Promise<GachaCard[]>}
|
||||
*/
|
||||
export async function getGachaCard(
|
||||
gachaData: GachaData[],
|
||||
poolCover: Map<string> | undefined = undefined
|
||||
export async function getGachaCard (
|
||||
gachaData: GachaData[],
|
||||
poolCover: Map<string> | undefined = undefined,
|
||||
): Promise<GachaCard[]> {
|
||||
const gachaCard: GachaCard[] = [];
|
||||
await Promise.allSettled(
|
||||
gachaData.map(async (data: GachaData) => {
|
||||
let cover = "/source/UI/empty.webp";
|
||||
const post_id: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
|
||||
if (post_id === undefined || isNaN(post_id)) {
|
||||
throw new Error("无法获取帖子 ID");
|
||||
}
|
||||
if (poolCover !== undefined) {
|
||||
cover = poolCover[post_id];
|
||||
} else {
|
||||
try {
|
||||
await console.log("调用 getPostData");
|
||||
const post = await getPostData(post_id);
|
||||
cover = post.cover?.url || post.post.images[0];
|
||||
} catch (error) {
|
||||
await console.error(error);
|
||||
}
|
||||
}
|
||||
return gachaCard.push({
|
||||
title: data.title,
|
||||
subtitle: data.content_before_act,
|
||||
cover: cover,
|
||||
post_id: post_id,
|
||||
characters: data.pool.map(character => ({
|
||||
icon: character.icon,
|
||||
url: character.url,
|
||||
})),
|
||||
voice: {
|
||||
icon: data.voice_icon,
|
||||
url: data.voice_url,
|
||||
},
|
||||
time: {
|
||||
start: data.start_time,
|
||||
start_stamp: new Date(data.start_time).getTime(),
|
||||
end: data.end_time,
|
||||
end_stamp: new Date(data.end_time).getTime(),
|
||||
},
|
||||
});
|
||||
})
|
||||
);
|
||||
return gachaCard;
|
||||
const gachaCard: GachaCard[] = [];
|
||||
await Promise.allSettled(
|
||||
gachaData.map(async (data: GachaData) => {
|
||||
let cover = "/source/UI/empty.webp";
|
||||
const postId: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
|
||||
if (postId === undefined || isNaN(postId)) {
|
||||
throw new Error("无法获取帖子 ID");
|
||||
}
|
||||
if (poolCover !== undefined) {
|
||||
cover = poolCover[postId];
|
||||
} else {
|
||||
try {
|
||||
console.log("调用 getPostData");
|
||||
const post = await getPostData(postId);
|
||||
cover = post.cover?.url ?? post.post.images[0];
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return gachaCard.push({
|
||||
title: data.title,
|
||||
subtitle: data.content_before_act,
|
||||
cover,
|
||||
post_id: postId,
|
||||
characters: data.pool.map((character) => ({
|
||||
icon: character.icon,
|
||||
url: character.url,
|
||||
})),
|
||||
voice: {
|
||||
icon: data.voice_icon,
|
||||
url: data.voice_url,
|
||||
},
|
||||
time: {
|
||||
start: data.start_time,
|
||||
start_stamp: new Date(data.start_time).getTime(),
|
||||
end: data.end_time,
|
||||
end_stamp: new Date(data.end_time).getTime(),
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
return gachaCard;
|
||||
}
|
||||
|
||||
@@ -5,38 +5,38 @@
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { LotteryData, LotteryCard, LotteryRewardCard, LotteryReward } from "../interface/lottery";
|
||||
import { type LotteryData, type LotteryCard, type LotteryRewardCard, type LotteryReward } from "../interface/lottery";
|
||||
|
||||
/**
|
||||
* @description 根据抽奖信息转为渲染用的抽奖信息
|
||||
* @since Alpha v0.1.1
|
||||
* @param {LotteryData} lotteryData 抽奖信息
|
||||
* @return {LotteryCard}
|
||||
* @returns {LotteryCard}
|
||||
*/
|
||||
export function getLotteryCard(lotteryData: LotteryData): LotteryCard {
|
||||
return {
|
||||
id: lotteryData.id,
|
||||
participantWay: lotteryData.participant_way,
|
||||
status: lotteryData.status,
|
||||
creator: lotteryData.creator,
|
||||
drawTime: lotteryData.draw_time,
|
||||
rewards: lotteryData.user_rewards.map(reward => {
|
||||
return getLotteryRewardCard(reward);
|
||||
}),
|
||||
};
|
||||
export function getLotteryCard (lotteryData: LotteryData): LotteryCard {
|
||||
return {
|
||||
id: lotteryData.id,
|
||||
participantWay: lotteryData.participant_way,
|
||||
status: lotteryData.status,
|
||||
creator: lotteryData.creator,
|
||||
drawTime: lotteryData.draw_time,
|
||||
rewards: lotteryData.user_rewards.map((reward) => {
|
||||
return getLotteryRewardCard(reward);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据抽奖奖励信息转为渲染用的抽奖奖励信息
|
||||
* @since Alpha v0.1.1
|
||||
* @param {LotteryReward} lotteryReward 抽奖奖励信息
|
||||
* @return {LotteryRewardCard}
|
||||
* @returns {LotteryRewardCard}
|
||||
*/
|
||||
export function getLotteryRewardCard(lotteryReward: LotteryReward): LotteryRewardCard {
|
||||
return {
|
||||
rewardName: lotteryReward.reward_name,
|
||||
winnerNumber: lotteryReward.winner_number,
|
||||
scheduledWinnerNumber: lotteryReward.scheduled_winner_number,
|
||||
users: lotteryReward.users,
|
||||
};
|
||||
export function getLotteryRewardCard (lotteryReward: LotteryReward): LotteryRewardCard {
|
||||
return {
|
||||
rewardName: lotteryReward.reward_name,
|
||||
winnerNumber: lotteryReward.winner_number,
|
||||
scheduledWinnerNumber: lotteryReward.scheduled_winner_number,
|
||||
users: lotteryReward.users,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { NewsData, NewsItem, NewsCard, ActivityStatus } from "../interface/news";
|
||||
import { type NewsData, type NewsItem, type NewsCard, type ActivityStatus } from "../interface/news";
|
||||
|
||||
// 默认封面图
|
||||
const defaultCover = "/source/UI/defaultCover.webp";
|
||||
@@ -17,103 +17,103 @@ const defaultCover = "/source/UI/defaultCover.webp";
|
||||
* @property {ActivityStatus} STARTED 进行中
|
||||
* @property {ActivityStatus} FINISHED 已结束
|
||||
* @property {ActivityStatus} SELECTION 评选中
|
||||
* @return {EnumStatus}
|
||||
* @returns {EnumStatus}
|
||||
*/
|
||||
const EnumStatus = {
|
||||
STARTED: {
|
||||
status: "进行中",
|
||||
colorCss: "#1EE2BA !important",
|
||||
},
|
||||
FINISHED: {
|
||||
status: "已结束",
|
||||
colorCss: "#C0C5C8 !important",
|
||||
},
|
||||
SELECTION: {
|
||||
status: "评选中",
|
||||
colorCss: "#FF983B !important",
|
||||
},
|
||||
UNKNOWN: {
|
||||
status: "未知",
|
||||
colorCss: "#3C3F41 !important",
|
||||
},
|
||||
STARTED: {
|
||||
status: "进行中",
|
||||
colorCss: "#1EE2BA !important",
|
||||
},
|
||||
FINISHED: {
|
||||
status: "已结束",
|
||||
colorCss: "#C0C5C8 !important",
|
||||
},
|
||||
SELECTION: {
|
||||
status: "评选中",
|
||||
colorCss: "#FF983B !important",
|
||||
},
|
||||
UNKNOWN: {
|
||||
status: "未知",
|
||||
colorCss: "#3C3F41 !important",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 获取活动状态
|
||||
* @since Alpha
|
||||
* @param {number} status 活动状态码
|
||||
* @return {string}
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getActivityStatus(status: number): ActivityStatus {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return EnumStatus.STARTED;
|
||||
case 2:
|
||||
return EnumStatus.SELECTION;
|
||||
case 3:
|
||||
return EnumStatus.FINISHED;
|
||||
default:
|
||||
return EnumStatus.UNKNOWN;
|
||||
}
|
||||
export function getActivityStatus (status: number): ActivityStatus {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return EnumStatus.STARTED;
|
||||
case 2:
|
||||
return EnumStatus.SELECTION;
|
||||
case 3:
|
||||
return EnumStatus.FINISHED;
|
||||
default:
|
||||
return EnumStatus.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取渲染用公告数据
|
||||
* @since Alpha
|
||||
* @since Alpha v0.1.2
|
||||
* @param {NewsData} noticeData 公告数据
|
||||
* @return {NewsCard[]}
|
||||
* @returns {NewsCard[]}
|
||||
*/
|
||||
export function getNoticeCard(noticeData: NewsData): NewsCard[] {
|
||||
const noticeCard: NewsCard[] = [];
|
||||
noticeData.list.map((item: NewsItem) => {
|
||||
noticeCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: item.post.post_id,
|
||||
});
|
||||
});
|
||||
return noticeCard;
|
||||
export function getNoticeCard (noticeData: NewsData): NewsCard[] {
|
||||
const noticeCard: NewsCard[] = [];
|
||||
noticeData.list.map((item: NewsItem) => {
|
||||
return noticeCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: item.post.post_id,
|
||||
});
|
||||
});
|
||||
return noticeCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取渲染用活动数据
|
||||
* @since Alpha
|
||||
* @since Alpha v0.1.2
|
||||
* @param {NewsData} activityData 活动数据
|
||||
* @return {NewsCard[]}
|
||||
* @returns {NewsCard[]}
|
||||
*/
|
||||
export function getActivityCard(activityData: NewsData): NewsCard[] {
|
||||
const activityCard: NewsCard[] = [];
|
||||
activityData.list.map((item: NewsItem) => {
|
||||
const start_time = new Date(Number(item.news_meta.start_at_sec) * 1000).toLocaleDateString();
|
||||
const end_time = new Date(Number(item.news_meta.end_at_sec) * 1000).toLocaleDateString();
|
||||
const status_info = getActivityStatus(item.news_meta.activity_status);
|
||||
activityCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: `${start_time} - ${end_time}`,
|
||||
status: status_info,
|
||||
});
|
||||
});
|
||||
return activityCard;
|
||||
export function getActivityCard (activityData: NewsData): NewsCard[] {
|
||||
const activityCard: NewsCard[] = [];
|
||||
activityData.list.map((item: NewsItem) => {
|
||||
const startTime = new Date(Number(item.news_meta.start_at_sec) * 1000).toLocaleDateString();
|
||||
const endTime = new Date(Number(item.news_meta.end_at_sec) * 1000).toLocaleDateString();
|
||||
const statusInfo = getActivityStatus(item.news_meta.activity_status);
|
||||
return activityCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: `${startTime} - ${endTime}`,
|
||||
status: statusInfo,
|
||||
});
|
||||
});
|
||||
return activityCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取渲染用新闻数据
|
||||
* @since Alpha
|
||||
* @since Alpha v0.1.2
|
||||
* @param {NewsData} newsData 新闻数据
|
||||
* @return {NewsCard[]}
|
||||
* @returns {NewsCard[]}
|
||||
*/
|
||||
export function getNewsCard(newsData: NewsData): NewsCard[] {
|
||||
const newsCard: NewsCard[] = [];
|
||||
newsData.list.map((item: NewsItem) => {
|
||||
newsCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: item.post.post_id,
|
||||
});
|
||||
});
|
||||
return newsCard;
|
||||
export function getNewsCard (newsData: NewsData): NewsCard[] {
|
||||
const newsCard: NewsCard[] = [];
|
||||
newsData.list.map((item: NewsItem) => {
|
||||
return newsCard.push({
|
||||
title: item.post.subject,
|
||||
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
|
||||
post_id: Number(item.post.post_id),
|
||||
subtitle: item.post.post_id,
|
||||
});
|
||||
});
|
||||
return newsCard;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
import { PostContent, PostData, PostStructuredContent } from "../interface/post";
|
||||
import { type PostData, type PostStructuredContent } from "../interface/post";
|
||||
|
||||
/**
|
||||
* @description 检测链接是否是米游社帖子
|
||||
@@ -12,47 +12,61 @@ import { PostContent, PostData, PostStructuredContent } from "../interface/post"
|
||||
* @param {string} url 链接
|
||||
* @returns {boolean} 是否是米游社帖子
|
||||
*/
|
||||
export function IsMysPost(url: string): boolean {
|
||||
const regBBS = /^https:\/\/bbs\.mihoyo\.com\/\w+\/article\/\d+$/;
|
||||
const regMYS = /^https:\/\/www\.miyoushe\.com\/\w+\/article\/\d+$/;
|
||||
return regBBS.test(url) || regMYS.test(url);
|
||||
export function IsMysPost (url: string): boolean {
|
||||
const regBBS = /^https:\/\/bbs\.mihoyo\.com\/\w+\/article\/\d+$/;
|
||||
const regMYS = /^https:\/\/www\.miyoushe\.com\/\w+\/article\/\d+$/;
|
||||
return regBBS.test(url) || regMYS.test(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据 url 获取帖子 id
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} url 链接
|
||||
* @returns {string} 帖子 id
|
||||
*/
|
||||
export function getPostId (url: string): string {
|
||||
const postId: string | undefined = url.split("/").pop();
|
||||
if (postId === undefined) {
|
||||
throw new Error("无法获取帖子 id");
|
||||
}
|
||||
return postId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 解析用户帖子,将其转换为 PostStructContent
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
* @see PostContent
|
||||
* @param {string} content 帖子内容
|
||||
* @returns {string} 解析后的内容
|
||||
*/
|
||||
export function contentParser(content: string): string {
|
||||
const data = JSON.parse(content);
|
||||
const result: PostStructuredContent[] = [];
|
||||
// 遍历 data 属性,值
|
||||
Object.keys(data).forEach(key => {
|
||||
switch (key) {
|
||||
case "describe":
|
||||
result.push({
|
||||
insert: data.describe,
|
||||
});
|
||||
break;
|
||||
case "imgs":
|
||||
for (const image of data.imgs) {
|
||||
result.push({
|
||||
insert: {
|
||||
image: image,
|
||||
},
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 如果是其他属性,就直接插入
|
||||
result.push({
|
||||
insert: JSON.stringify(data[key]),
|
||||
});
|
||||
}
|
||||
});
|
||||
return JSON.stringify(result);
|
||||
export function contentParser (content: string): string {
|
||||
const data = JSON.parse(content);
|
||||
const result: PostStructuredContent[] = [];
|
||||
// 遍历 data 属性,值
|
||||
Object.keys(data).forEach((key) => {
|
||||
switch (key) {
|
||||
case "describe":
|
||||
result.push({
|
||||
insert: data.describe,
|
||||
});
|
||||
break;
|
||||
case "imgs":
|
||||
for (const image of data.imgs) {
|
||||
result.push({
|
||||
insert: {
|
||||
image,
|
||||
},
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 如果是其他属性,就直接插入
|
||||
result.push({
|
||||
insert: JSON.stringify(data[key]),
|
||||
});
|
||||
}
|
||||
});
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,25 +76,25 @@ export function contentParser(content: string): string {
|
||||
* @description 为了安全考虑,不会解析所有的属性,只会解析几个常用的属性
|
||||
* @returns {string} 解析后的HTML,可作为 v-html 使用
|
||||
*/
|
||||
export function PostParser(post: PostData): string {
|
||||
const postContent = post.post.content;
|
||||
let parserData;
|
||||
if (postContent.startsWith("<")) {
|
||||
parserData = post.post.structured_content;
|
||||
} else {
|
||||
try {
|
||||
parserData = contentParser(post.post.content);
|
||||
} catch (error) {
|
||||
parserData = post.post.structured_content;
|
||||
}
|
||||
}
|
||||
let jsonData: PostStructuredContent[] = JSON.parse(parserData);
|
||||
const doc = document.createElement("div");
|
||||
jsonData.forEach((item: any) => {
|
||||
const parsed = ParserTransfer(item);
|
||||
doc.appendChild(parsed);
|
||||
});
|
||||
return doc.innerHTML;
|
||||
export function PostParser (post: PostData): string {
|
||||
const postContent = post.post.content;
|
||||
let parserData;
|
||||
if (postContent.startsWith("<")) {
|
||||
parserData = post.post.structured_content;
|
||||
} else {
|
||||
try {
|
||||
parserData = contentParser(post.post.content);
|
||||
} catch (error) {
|
||||
parserData = post.post.structured_content;
|
||||
}
|
||||
}
|
||||
const jsonData: PostStructuredContent[] = JSON.parse(parserData);
|
||||
const doc = document.createElement("div");
|
||||
jsonData.forEach((item: any) => {
|
||||
const parsed = ParserTransfer(item);
|
||||
doc.appendChild(parsed);
|
||||
});
|
||||
return doc.innerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,24 +103,24 @@ export function PostParser(post: PostData): string {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement | HTMLSpanElement} 解析后的中转
|
||||
*/
|
||||
function ParserTransfer(data: PostStructuredContent): HTMLDivElement | HTMLSpanElement {
|
||||
if (typeof data.insert === "string") {
|
||||
return TextParser(data);
|
||||
} else if (data.insert.image) {
|
||||
return ImageParser(data);
|
||||
} else if (data.insert.vod) {
|
||||
return VideoParser(data);
|
||||
} else if (data.insert.video) {
|
||||
return VideoParser(data);
|
||||
} else if (data.insert.backup_text) {
|
||||
return BackupTextParser(data);
|
||||
} else if (data.insert.link_card) {
|
||||
return LinkCardParser(data);
|
||||
} else if (data.insert.divider) {
|
||||
return DividerParser(data);
|
||||
} else {
|
||||
return UnknownParser(data);
|
||||
}
|
||||
function ParserTransfer (data: PostStructuredContent): HTMLDivElement | HTMLSpanElement {
|
||||
if (typeof data.insert === "string") {
|
||||
return TextParser(data);
|
||||
} else if (data.insert.image) {
|
||||
return ImageParser(data);
|
||||
} else if (data.insert.vod) {
|
||||
return VideoParser(data);
|
||||
} else if (data.insert.video) {
|
||||
return VideoParser(data);
|
||||
} else if (data.insert.backup_text) {
|
||||
return BackupTextParser(data);
|
||||
} else if (data.insert.link_card) {
|
||||
return LinkCardParser(data);
|
||||
} else if (data.insert.divider) {
|
||||
return DividerParser(data);
|
||||
} else {
|
||||
return UnknownParser(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,17 +129,17 @@ function ParserTransfer(data: PostStructuredContent): HTMLDivElement | HTMLSpanE
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的未知数据
|
||||
*/
|
||||
function UnknownParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-unknown");
|
||||
// 创建 code,将数据放入 code
|
||||
const code = document.createElement("code");
|
||||
code.innerText = JSON.stringify(data);
|
||||
// 插入 code
|
||||
div.appendChild(code);
|
||||
// 返回 div
|
||||
return div;
|
||||
function UnknownParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-unknown");
|
||||
// 创建 code,将数据放入 code
|
||||
const code = document.createElement("code");
|
||||
code.innerText = JSON.stringify(data);
|
||||
// 插入 code
|
||||
div.appendChild(code);
|
||||
// 返回 div
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,65 +148,66 @@ function UnknownParser(data: PostStructuredContent): HTMLDivElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLSpanElement} 解析后的文本
|
||||
*/
|
||||
function TextParser(data: PostStructuredContent): HTMLSpanElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert !== "string") {
|
||||
throw new Error("data.insert is not a string");
|
||||
}
|
||||
// 创建文本
|
||||
const text = document.createElement("span");
|
||||
// 设置文本属性
|
||||
if (data.attributes) {
|
||||
if (data.attributes.bold) text.style.fontWeight = "bold";
|
||||
if (data.attributes.color) text.style.color = data.attributes.color;
|
||||
if (data.attributes.link) {
|
||||
return LinkTextParser(data);
|
||||
}
|
||||
}
|
||||
// 添加 class
|
||||
text.classList.add("mys-post-span");
|
||||
// 设置 span 内容
|
||||
text.innerText = data.insert;
|
||||
// 返回文本
|
||||
return text;
|
||||
function TextParser (data: PostStructuredContent): HTMLSpanElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert !== "string") {
|
||||
throw new Error("data.insert is not a string");
|
||||
}
|
||||
// 创建文本
|
||||
const text = document.createElement("span");
|
||||
// 设置文本属性
|
||||
if (data.attributes) {
|
||||
if (data.attributes.bold) text.style.fontWeight = "bold";
|
||||
if (data.attributes.color) text.style.color = data.attributes.color;
|
||||
if (data.attributes.link) {
|
||||
return LinkTextParser(data);
|
||||
}
|
||||
}
|
||||
// 添加 class
|
||||
text.classList.add("mys-post-span");
|
||||
// 设置 span 内容
|
||||
text.innerText = data.insert;
|
||||
// 返回文本
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 解析链接
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLSpanElement} 解析后的链接
|
||||
*/
|
||||
function LinkTextParser(data: PostStructuredContent): HTMLSpanElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert !== "string") {
|
||||
throw new Error("data.insert is not a string");
|
||||
}
|
||||
if (!data.attributes) {
|
||||
throw new Error("data.attributes is not defined");
|
||||
}
|
||||
if (!data.attributes.link) {
|
||||
throw new Error("data.attributes.link is not defined");
|
||||
}
|
||||
// 创建图标
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("mdi", "mdi-link-variant");
|
||||
// 创建链接
|
||||
const link = document.createElement("a");
|
||||
const link_url = data.attributes.link;
|
||||
link.classList.add("mys-post-link");
|
||||
if (IsMysPost(link_url)) {
|
||||
link.href = "/post_detail/" + link_url.split("/").pop();
|
||||
link.target = "_self";
|
||||
} else {
|
||||
link.href = link_url;
|
||||
link.target = "view_window";
|
||||
}
|
||||
link.innerText = data.insert;
|
||||
// 插入图标作为链接前缀
|
||||
link.prepend(icon);
|
||||
// 返回链接
|
||||
return link;
|
||||
function LinkTextParser (data: PostStructuredContent): HTMLSpanElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert !== "string") {
|
||||
throw new Error("data.insert is not a string");
|
||||
}
|
||||
if (!data.attributes) {
|
||||
throw new Error("data.attributes is not defined");
|
||||
}
|
||||
if (!data.attributes.link) {
|
||||
throw new Error("data.attributes.link is not defined");
|
||||
}
|
||||
// 创建图标
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("mdi", "mdi-link-variant");
|
||||
// 创建链接
|
||||
const link = document.createElement("a");
|
||||
const linkUrl = data.attributes.link;
|
||||
link.classList.add("mys-post-link");
|
||||
if (IsMysPost(linkUrl)) {
|
||||
const postId = getPostId(linkUrl);
|
||||
link.href = `/post_detail/${postId}`;
|
||||
link.target = "_self";
|
||||
} else {
|
||||
link.href = linkUrl;
|
||||
link.target = "view_window";
|
||||
}
|
||||
link.innerText = data.insert;
|
||||
// 插入图标作为链接前缀
|
||||
link.prepend(icon);
|
||||
// 返回链接
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,39 +216,38 @@ function LinkTextParser(data: PostStructuredContent): HTMLSpanElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的分割线
|
||||
*/
|
||||
function DividerParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 数据检查
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.divider) {
|
||||
throw new Error("data.insert.divider is not defined");
|
||||
}
|
||||
// 创建分割线
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-divider");
|
||||
// 创建 img
|
||||
const img = document.createElement("img");
|
||||
if (data.insert.divider === "line_1") {
|
||||
img.src =
|
||||
function DividerParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 数据检查
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.divider) {
|
||||
throw new Error("data.insert.divider is not defined");
|
||||
}
|
||||
// 创建分割线
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-divider");
|
||||
// 创建 img
|
||||
const img = document.createElement("img");
|
||||
if (data.insert.divider === "line_1") {
|
||||
img.src =
|
||||
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/40eb5281cb24042bf34a9f1bcc61eaf5.png";
|
||||
} else if (data.insert.divider === "line_2") {
|
||||
img.src =
|
||||
} else if (data.insert.divider === "line_2") {
|
||||
img.src =
|
||||
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/477d4c535e965bec1791203aecdfa8e6.png";
|
||||
} else if (data.insert.divider === "line_3") {
|
||||
img.src =
|
||||
} else if (data.insert.divider === "line_3") {
|
||||
img.src =
|
||||
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/e7047588e912d60ff87a975e037c7606.png";
|
||||
} else if (data.insert.divider === "line_4") {
|
||||
img.src =
|
||||
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2022/07/13/line_4.png";
|
||||
} else {
|
||||
console.error("Unknown divider type", data);
|
||||
return UnknownParser(data);
|
||||
}
|
||||
// 插入 img
|
||||
div.appendChild(img);
|
||||
// 返回分割线
|
||||
return div;
|
||||
} else if (data.insert.divider === "line_4") {
|
||||
img.src = "https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2022/07/13/line_4.png";
|
||||
} else {
|
||||
console.error("Unknown divider type", data);
|
||||
return UnknownParser(data);
|
||||
}
|
||||
// 插入 img
|
||||
div.appendChild(img);
|
||||
// 返回分割线
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,35 +256,35 @@ function DividerParser(data: PostStructuredContent): HTMLDivElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的图片
|
||||
*/
|
||||
function ImageParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.image) {
|
||||
throw new Error("data.insert.image is not defined");
|
||||
}
|
||||
// if (!data.attributes) {
|
||||
// throw new Error("data.attributes is not defined");
|
||||
// }
|
||||
// if (!data.attributes.width) {
|
||||
// throw new Error("data.attributes.width is not defined");
|
||||
// }
|
||||
// if (!data.attributes.height) {
|
||||
// throw new Error("data.attributes.height is not defined");
|
||||
// }
|
||||
const div = document.createElement("div");
|
||||
// 创建图片
|
||||
const img = document.createElement("img");
|
||||
img.src = data.insert.image;
|
||||
// 添加 class
|
||||
img.classList.add("mys-post-img");
|
||||
// 插入图片
|
||||
div.appendChild(img);
|
||||
// 添加 class
|
||||
div.classList.add("mys-post-div");
|
||||
// 返回 div
|
||||
return div;
|
||||
function ImageParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.image) {
|
||||
throw new Error("data.insert.image is not defined");
|
||||
}
|
||||
// if (!data.attributes) {
|
||||
// throw new Error("data.attributes is not defined");
|
||||
// }
|
||||
// if (!data.attributes.width) {
|
||||
// throw new Error("data.attributes.width is not defined");
|
||||
// }
|
||||
// if (!data.attributes.height) {
|
||||
// throw new Error("data.attributes.height is not defined");
|
||||
// }
|
||||
const div = document.createElement("div");
|
||||
// 创建图片
|
||||
const img = document.createElement("img");
|
||||
img.src = data.insert.image;
|
||||
// 添加 class
|
||||
img.classList.add("mys-post-img");
|
||||
// 插入图片
|
||||
div.appendChild(img);
|
||||
// 添加 class
|
||||
div.classList.add("mys-post-div");
|
||||
// 返回 div
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,48 +293,48 @@ function ImageParser(data: PostStructuredContent): HTMLDivElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的视频
|
||||
*/
|
||||
function VideoParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.vod && !data.insert.video) {
|
||||
throw new Error("data.insert.vod is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-div");
|
||||
if (data.insert.vod) {
|
||||
// 创建视频
|
||||
const video = document.createElement("video");
|
||||
video.classList.add("mys-post-vod");
|
||||
// 获取 resolutions中size最大的视频
|
||||
const resolution = data.insert.vod.resolutions.reduce((prev: any, curr: any) => {
|
||||
if (prev.size > curr.size) return prev;
|
||||
return curr;
|
||||
});
|
||||
video.poster = data.insert.vod.cover; // 设置封面
|
||||
video.controls = true; // 设置 controls
|
||||
// 添加 source
|
||||
const source = document.createElement("source");
|
||||
source.src = resolution.url;
|
||||
source.type = resolution.format === ".mp4" ? "video/mp4" : "video/webm";
|
||||
// 插入 source
|
||||
video.appendChild(source);
|
||||
// 插入 video
|
||||
div.appendChild(video);
|
||||
} else if (data.insert.video) {
|
||||
// 创建 iframe
|
||||
const video = document.createElement("iframe");
|
||||
video.classList.add("mys-post-iframe");
|
||||
// 设置 iframe 属性
|
||||
video.src = data.insert.video;
|
||||
video.allowFullscreen = true;
|
||||
video.sandbox.add("allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts");
|
||||
// 插入 video
|
||||
div.appendChild(video);
|
||||
}
|
||||
return div;
|
||||
function VideoParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.vod && !data.insert.video) {
|
||||
throw new Error("data.insert.vod is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-div");
|
||||
if (data.insert.vod) {
|
||||
// 创建视频
|
||||
const video = document.createElement("video");
|
||||
video.classList.add("mys-post-vod");
|
||||
// 获取 resolutions中size最大的视频
|
||||
const resolution = data.insert.vod.resolutions.reduce((prev: any, curr: any) => {
|
||||
if (prev.size > curr.size) return prev;
|
||||
return curr;
|
||||
});
|
||||
video.poster = data.insert.vod.cover; // 设置封面
|
||||
video.controls = true; // 设置 controls
|
||||
// 添加 source
|
||||
const source = document.createElement("source");
|
||||
source.src = resolution.url;
|
||||
source.type = resolution.format === ".mp4" ? "video/mp4" : "video/webm";
|
||||
// 插入 source
|
||||
video.appendChild(source);
|
||||
// 插入 video
|
||||
div.appendChild(video);
|
||||
} else if (data.insert.video) {
|
||||
// 创建 iframe
|
||||
const video = document.createElement("iframe");
|
||||
video.classList.add("mys-post-iframe");
|
||||
// 设置 iframe 属性
|
||||
video.src = data.insert.video;
|
||||
video.allowFullscreen = true;
|
||||
video.sandbox.add("allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts");
|
||||
// 插入 video
|
||||
div.appendChild(video);
|
||||
}
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,44 +343,44 @@ function VideoParser(data: PostStructuredContent): HTMLDivElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的折叠内容
|
||||
*/
|
||||
function BackupTextParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (data.insert.backup_text === "[抽奖]") {
|
||||
return LotteryParser(data);
|
||||
}
|
||||
if (!data.insert.fold) {
|
||||
throw new Error("data.insert.fold is not defined");
|
||||
}
|
||||
// 转换
|
||||
const titleJson: PostStructuredContent[] = JSON.parse(data.insert.fold.title);
|
||||
const contentJson: PostStructuredContent[] = JSON.parse(data.insert.fold.content);
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-div");
|
||||
// 创建折叠内容
|
||||
const details = document.createElement("details");
|
||||
details.classList.add("mys-post-details");
|
||||
// 创建标题
|
||||
const title = document.createElement("summary");
|
||||
// 解析标题
|
||||
titleJson.forEach(item => {
|
||||
const parsed = ParserTransfer(item);
|
||||
title.appendChild(parsed);
|
||||
});
|
||||
// 创建内容
|
||||
const content = document.createElement("div");
|
||||
contentJson.forEach(item => {
|
||||
const parsed = ParserTransfer(item);
|
||||
content.appendChild(parsed);
|
||||
});
|
||||
details.appendChild(title);
|
||||
details.appendChild(content);
|
||||
div.appendChild(details);
|
||||
// 返回 div
|
||||
return div;
|
||||
function BackupTextParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (data.insert.backup_text === "[抽奖]") {
|
||||
return LotteryParser(data);
|
||||
}
|
||||
if (!data.insert.fold) {
|
||||
throw new Error("data.insert.fold is not defined");
|
||||
}
|
||||
// 转换
|
||||
const titleJson: PostStructuredContent[] = JSON.parse(data.insert.fold.title);
|
||||
const contentJson: PostStructuredContent[] = JSON.parse(data.insert.fold.content);
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("mys-post-div");
|
||||
// 创建折叠内容
|
||||
const details = document.createElement("details");
|
||||
details.classList.add("mys-post-details");
|
||||
// 创建标题
|
||||
const title = document.createElement("summary");
|
||||
// 解析标题
|
||||
titleJson.forEach((item) => {
|
||||
const parsed = ParserTransfer(item);
|
||||
title.appendChild(parsed);
|
||||
});
|
||||
// 创建内容
|
||||
const content = document.createElement("div");
|
||||
contentJson.forEach((item) => {
|
||||
const parsed = ParserTransfer(item);
|
||||
content.appendChild(parsed);
|
||||
});
|
||||
details.appendChild(title);
|
||||
details.appendChild(content);
|
||||
div.appendChild(details);
|
||||
// 返回 div
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,96 +389,97 @@ function BackupTextParser(data: PostStructuredContent): HTMLDivElement {
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的抽奖
|
||||
*/
|
||||
function LotteryParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.backup_text) {
|
||||
throw new Error("data.insert.backup_text is not defined");
|
||||
}
|
||||
if (data.insert.backup_text !== "[抽奖]") {
|
||||
throw new Error("data.insert.backup_text is not [抽奖]");
|
||||
}
|
||||
if (!data.insert.lottery) {
|
||||
throw new Error("data.insert.lottery is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
// 创建图标
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("mdi", "mdi-gift");
|
||||
// 创建标题
|
||||
const title = document.createElement("a");
|
||||
title.classList.add("mys-post-link");
|
||||
title.href = `/lottery/${data.insert.lottery.id}`;
|
||||
title.innerText = data.insert.lottery.toast;
|
||||
// 插入图标
|
||||
title.prepend(icon);
|
||||
// 插入标题
|
||||
div.appendChild(title);
|
||||
// 返回 div
|
||||
return div;
|
||||
function LotteryParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.backup_text) {
|
||||
throw new Error("data.insert.backup_text is not defined");
|
||||
}
|
||||
if (data.insert.backup_text !== "[抽奖]") {
|
||||
throw new Error("data.insert.backup_text is not [抽奖]");
|
||||
}
|
||||
if (!data.insert.lottery) {
|
||||
throw new Error("data.insert.lottery is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
// 创建图标
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("mdi", "mdi-gift");
|
||||
// 创建标题
|
||||
const title = document.createElement("a");
|
||||
title.classList.add("mys-post-link");
|
||||
title.href = `/lottery/${data.insert.lottery.id}`;
|
||||
title.innerText = data.insert.lottery.toast;
|
||||
// 插入图标
|
||||
title.prepend(icon);
|
||||
// 插入标题
|
||||
div.appendChild(title);
|
||||
// 返回 div
|
||||
return div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 解析链接卡片
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
* @param {PostStructuredContent} data Mys数据
|
||||
* @returns {HTMLDivElement} 解析后的链接卡片
|
||||
*/
|
||||
function LinkCardParser(data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.link_card) {
|
||||
throw new Error("data.insert.link_card is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
// 创建 cover
|
||||
const cover = document.createElement("div");
|
||||
cover.classList.add("mys-post-link-card-cover");
|
||||
// 创建 img
|
||||
const img = document.createElement("img");
|
||||
img.src = data.insert.link_card.cover;
|
||||
// 插入 img
|
||||
cover.appendChild(img);
|
||||
// 插入 cover
|
||||
div.appendChild(cover);
|
||||
// 创建 content
|
||||
const content = document.createElement("div");
|
||||
content.classList.add("mys-post-link-card-content");
|
||||
// 创建标题
|
||||
const title = document.createElement("div");
|
||||
title.classList.add("mys-post-link-card-title");
|
||||
title.innerHTML = data.insert.link_card.title;
|
||||
// 插入 title
|
||||
content.appendChild(title);
|
||||
if (data.insert.link_card.price) {
|
||||
const price = document.createElement("div");
|
||||
price.classList.add("mys-post-link-card-price");
|
||||
price.innerHTML = data.insert.link_card.price;
|
||||
content.appendChild(price);
|
||||
}
|
||||
// 创建 button
|
||||
const button = document.createElement("a");
|
||||
button.classList.add("mys-post-link-card-btn");
|
||||
button.innerHTML = (data.insert.link_card.button_text || "详情") + " >";
|
||||
const link_url = data.insert.link_card.origin_url;
|
||||
if (IsMysPost(link_url)) {
|
||||
button.href = "/post_detail/" + link_url.split("/").pop();
|
||||
button.target = "_self";
|
||||
} else {
|
||||
button.href = link_url;
|
||||
button.target = "view_window";
|
||||
}
|
||||
// 插入 button
|
||||
content.appendChild(button);
|
||||
// 插入 content
|
||||
div.appendChild(content);
|
||||
// 添加 class
|
||||
div.classList.add("mys-post-link-card");
|
||||
return div;
|
||||
function LinkCardParser (data: PostStructuredContent): HTMLDivElement {
|
||||
// 检查数据
|
||||
if (typeof data.insert === "string") {
|
||||
throw new Error("data.insert is a string");
|
||||
}
|
||||
if (!data.insert.link_card) {
|
||||
throw new Error("data.insert.link_card is not defined");
|
||||
}
|
||||
// 创建 div
|
||||
const div = document.createElement("div");
|
||||
// 创建 cover
|
||||
const cover = document.createElement("div");
|
||||
cover.classList.add("mys-post-link-card-cover");
|
||||
// 创建 img
|
||||
const img = document.createElement("img");
|
||||
img.src = data.insert.link_card.cover;
|
||||
// 插入 img
|
||||
cover.appendChild(img);
|
||||
// 插入 cover
|
||||
div.appendChild(cover);
|
||||
// 创建 content
|
||||
const content = document.createElement("div");
|
||||
content.classList.add("mys-post-link-card-content");
|
||||
// 创建标题
|
||||
const title = document.createElement("div");
|
||||
title.classList.add("mys-post-link-card-title");
|
||||
title.innerHTML = data.insert.link_card.title;
|
||||
// 插入 title
|
||||
content.appendChild(title);
|
||||
if (data.insert.link_card.price) {
|
||||
const price = document.createElement("div");
|
||||
price.classList.add("mys-post-link-card-price");
|
||||
price.innerHTML = data.insert.link_card.price;
|
||||
content.appendChild(price);
|
||||
}
|
||||
// 创建 button
|
||||
const button = document.createElement("a");
|
||||
button.classList.add("mys-post-link-card-btn");
|
||||
button.innerHTML = (data.insert.link_card.button_text || "详情") + " >";
|
||||
const linkUrl = data.insert.link_card.origin_url;
|
||||
if (IsMysPost(linkUrl)) {
|
||||
const postId = getPostId(linkUrl);
|
||||
button.href = `/post_detail/${postId}`;
|
||||
button.target = "_self";
|
||||
} else {
|
||||
button.href = linkUrl;
|
||||
button.target = "view_window";
|
||||
}
|
||||
// 插入 button
|
||||
content.appendChild(button);
|
||||
// 插入 content
|
||||
div.appendChild(content);
|
||||
// 添加 class
|
||||
div.classList.add("mys-post-link-card");
|
||||
return div;
|
||||
}
|
||||
|
||||
@@ -2,55 +2,55 @@
|
||||
* @file plugins Mys utils position.ts
|
||||
* @description Mys 插件热点追踪工具
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { PositionObc, PositionData, PositionCard } from "../interface/position";
|
||||
import { type PositionObc, type PositionData, type PositionCard } from "../interface/position";
|
||||
|
||||
/**
|
||||
* @description 深度优先遍历
|
||||
* @since Alpha v0.1.1
|
||||
* @param {PositionObc[]} list 列表
|
||||
* @return {PositionData[]} 返回列表
|
||||
* @returns {PositionData[]} 返回列表
|
||||
*/
|
||||
export function dfs(list: PositionObc[]): PositionData[] {
|
||||
const res: PositionData[] = [];
|
||||
for (const item of list) {
|
||||
if (item.name === "近期活动") {
|
||||
res.push(...item.list);
|
||||
}
|
||||
if (item.children) {
|
||||
res.push(...dfs(item.children as PositionObc[]));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
export function dfs (list: PositionObc[]): PositionData[] {
|
||||
const res: PositionData[] = [];
|
||||
for (const item of list) {
|
||||
if (item.name === "近期活动") {
|
||||
res.push(...item.list);
|
||||
}
|
||||
if (item.children) {
|
||||
res.push(...dfs(item.children as PositionObc[]));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据热点追踪信息转为渲染用的数据
|
||||
* @since Alpha v0.1.1
|
||||
* @since Alpha v0.1.2
|
||||
* @param {PositionData[]} positionData 列表
|
||||
* @return {PositionCard[]} 返回列表
|
||||
* @returns {PositionCard[]} 返回列表
|
||||
*/
|
||||
export function getPositionCard(positionData: PositionData[]): PositionCard[] {
|
||||
const res: PositionCard[] = [];
|
||||
positionData.map(position => {
|
||||
res.push({
|
||||
title: position.title,
|
||||
post_id: Number(position.url.split("/").pop()),
|
||||
icon: position.icon,
|
||||
abstract: position.abstract,
|
||||
time: {
|
||||
start: position.create_time,
|
||||
start_stamp: new Date(position.create_time).getTime(),
|
||||
end: new Date(Number(position.end_time))
|
||||
.toLocaleString("zh-CN", {
|
||||
hour12: false,
|
||||
})
|
||||
.replace(/\//g, "-"),
|
||||
end_stamp: Number(position.end_time),
|
||||
},
|
||||
});
|
||||
});
|
||||
return res;
|
||||
export function getPositionCard (positionData: PositionData[]): PositionCard[] {
|
||||
const res: PositionCard[] = [];
|
||||
positionData.map((position) => {
|
||||
return res.push({
|
||||
title: position.title,
|
||||
post_id: Number(position.url.split("/").pop()),
|
||||
icon: position.icon,
|
||||
abstract: position.abstract,
|
||||
time: {
|
||||
start: position.create_time,
|
||||
start_stamp: new Date(position.create_time).getTime(),
|
||||
end: new Date(Number(position.end_time))
|
||||
.toLocaleString("zh-CN", {
|
||||
hour12: false,
|
||||
})
|
||||
.replace(/\//g, "-"),
|
||||
end_stamp: Number(position.end_time),
|
||||
},
|
||||
});
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user