Skip to content

Commit

Permalink
fix(route): 优化 bilibili 动态 转发带图评论时的图片显示 (#15503)
Browse files Browse the repository at this point in the history
* fix(route): 优化 bilibili 动态 转发带图评论时的图片显示

* fix(route): 修复 deepscan issue
  • Loading branch information
CaoMeiYouRen authored May 7, 2024
1 parent 936e703 commit 6807143
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/routes/bilibili/api-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ interface Richtextnode {
type: string;
jump_url?: string;
emoji?: Emoji;
pics?: Pic2[];
}
interface Pic2 {
height: number;
size: number;
src: string;
width: number;
}

interface Desc {
rich_text_nodes: Richtextnode[];
text: string;
Expand Down
22 changes: 18 additions & 4 deletions lib/routes/bilibili/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,28 @@ async function handler(ctx) {
const title = getTitle(data) || description; // 没有 title 的时候使用 desc 填充

// emoji
if (data.module_dynamic?.desc?.rich_text_nodes?.length && showEmoji) {
const nodes = data.module_dynamic?.desc?.rich_text_nodes;
if (data.module_dynamic?.desc?.rich_text_nodes?.length) {
const nodes = data.module_dynamic.desc.rich_text_nodes;
for (const node of nodes) {
if (node?.emoji) {
// 处理 emoji 的情况
if (showEmoji && node?.emoji) {
const emoji = node.emoji;
description = description.replaceAll(
emoji.text,
`<img alt="${emoji.text}" src="${emoji.icon_url}"style="margin: -1px 1px 0px; display: inline-block; width: 20px; height: 20px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
`<img alt="${emoji.text}" src="${emoji.icon_url}" style="margin: -1px 1px 0px; display: inline-block; width: 20px; height: 20px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
);
}
// 处理转发带图评论的情况
if (node?.pics?.length) {
const { pics, text } = node;
description = description.replaceAll(
text,
pics
.map(
(pic) =>
`<img alt="${text}" src="${pic.src}" style="margin: 0px 0px 0px; display: inline-block; width: ${pic.width}px; height: ${pic.height}px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
)
.join('<br>')
);
}
}
Expand Down

0 comments on commit 6807143

Please sign in to comment.