From 7b68554168bfc149891009b626f3459df0395899 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 8 Apr 2023 01:40:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fix(parser):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20insert.mention=20=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/Mys/interface/post.ts | 12 ++++++++++-- src/plugins/Mys/utils/parser.ts | 32 ++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/plugins/Mys/interface/post.ts b/src/plugins/Mys/interface/post.ts index c93f7d39..96a89baf 100644 --- a/src/plugins/Mys/interface/post.ts +++ b/src/plugins/Mys/interface/post.ts @@ -2,7 +2,7 @@ * @file plugins Mys interface post.ts * @description Mys 插件帖子接口 * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ import { type MysResponse } from "./base"; @@ -242,7 +242,7 @@ export interface PostContent { /** * @description 帖子结构化内容 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface PostStructuredContent * @property {string|object} insert 插入内容 * @property {string} insert.image 图片 URL @@ -257,6 +257,9 @@ export interface PostContent { * @property {string} insert.fold.content 折叠文本,反序列化后为 PostStructuredContent[] * @property {PostStructuredContentLinkCard} insert.link_card 链接卡片 * @property {string} insert.divider 分割线 + * @property {object} insert.mention 提及 + * @property {string} insert.mention.uid 用户 ID + * @property {string} insert.mention.nickname 用户昵称 * @property {object} attributes 属性 * @property {number} attributes.height 高度 * @property {number} attributes.width 宽度 @@ -268,6 +271,7 @@ export interface PostContent { * @returns {PostStructuredContent} */ export interface PostStructuredContent { + insert: | { image?: string @@ -284,6 +288,10 @@ export interface PostStructuredContent { } link_card?: PostStructuredContentLinkCard divider?: string + mention?: { + uid: string + nickname: string + } } | string attributes?: { diff --git a/src/plugins/Mys/utils/parser.ts b/src/plugins/Mys/utils/parser.ts index b429377a..01321497 100644 --- a/src/plugins/Mys/utils/parser.ts +++ b/src/plugins/Mys/utils/parser.ts @@ -99,7 +99,7 @@ export function PostParser (post: PostData): string { /** * @description 解析中转 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @param {PostStructuredContent} data Mys数据 * @returns {HTMLDivElement | HTMLSpanElement} 解析后的中转 */ @@ -118,6 +118,8 @@ function ParserTransfer (data: PostStructuredContent): HTMLDivElement | HTMLSpan return LinkCardParser(data); } else if (data.insert.divider) { return DividerParser(data); + } else if (data.insert.mention) { + return MentionParser(data); } else { return UnknownParser(data); } @@ -483,3 +485,31 @@ function LinkCardParser (data: PostStructuredContent): HTMLDivElement { div.classList.add("mys-post-link-card"); return div; } + +/** + * @description 解析 Mention + * @since Alpha v0.1.2 + * @param {PostStructuredContent} data Mys数据 + * @returns {HTMLAnchorElement} 解析后的 Mention + */ +function MentionParser (data: PostStructuredContent): HTMLAnchorElement { + // 检查数据 + if (typeof data.insert === "string") { + throw new Error("data.insert is a string"); + } + if (!data.insert.mention) { + throw new Error("data.insert.mention is not defined"); + } + // 创建图标 + const icon = document.createElement("i"); + icon.classList.add("mdi", "mdi-account-circle-outline"); + // 创建链接 + const link = document.createElement("a"); + link.classList.add("mys-post-link"); + link.href = `https://www.miyoushe.com/ys/accountCenter/postList?id=${data.insert.mention.uid}`; + link.target = "_blank"; + link.innerText = data.insert.mention.nickname; + // 插入图标 + link.prepend(icon); + return link; +}