From 4523d37cbdabe033abf7bc153dcaaa36e976bc52 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 1 Sep 2025 13:18:51 +0800 Subject: [PATCH] feat: add img width height for bilibili/dynamic weibo/user xiaohongshu/user routes --- lib/routes/bilibili/dynamic.ts | 34 ++++++++++++++++++++++++++++------ lib/routes/weibo/utils.ts | 14 +++++++------- lib/routes/xiaohongshu/user.ts | 2 +- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/lib/routes/bilibili/dynamic.ts b/lib/routes/bilibili/dynamic.ts index d9e533e2d..39567f9fa 100644 --- a/lib/routes/bilibili/dynamic.ts +++ b/lib/routes/bilibili/dynamic.ts @@ -126,26 +126,48 @@ const getIframe = (data?: Modules, embed: boolean = true) => { }; const getImgs = (data?: Modules) => { - const imgUrls: string[] = []; + const imgUrls: { + url: string; + width?: number; + height?: number; + }[] = []; const major = data?.module_dynamic?.major; if (!major) { return ''; } // 动态图片 if (major.opus?.pics?.length) { - imgUrls.push(...major.opus.pics.map((e) => e.url)); + imgUrls.push( + ...major.opus.pics.map((e) => ({ + url: e.url, + width: e.width, + height: e.height, + })) + ); } // 专栏封面 if (major.article?.covers?.length) { - imgUrls.push(...major.article.covers); + imgUrls.push( + ...major.article.covers.map((e) => ({ + url: e, + })) + ); } // 相簿 if (major.draw?.items?.length) { - imgUrls.push(...major.draw.items.map((e) => e.src)); + imgUrls.push( + ...major.draw.items.map((e) => ({ + url: e.src, + width: e.width, + height: e.height, + })) + ); } // 正在直播的动态 if (major.live_rcmd?.content) { - imgUrls.push(JSON.parse(major.live_rcmd.content)?.live_play_info?.cover); + imgUrls.push({ + url: JSON.parse(major.live_rcmd.content)?.live_play_info?.cover, + }); } const type = major.type.replace('MAJOR_TYPE_', '').toLowerCase(); if (major[type]?.cover) { @@ -153,7 +175,7 @@ const getImgs = (data?: Modules) => { } return imgUrls .filter(Boolean) - .map((url) => ``) + .map((img) => ``) .join(''); }; diff --git a/lib/routes/weibo/utils.ts b/lib/routes/weibo/utils.ts index 9d1453884..a86e0cdbf 100644 --- a/lib/routes/weibo/utils.ts +++ b/lib/routes/weibo/utils.ts @@ -36,7 +36,7 @@ const weiboUtils = { widthOfPics: fallback(params.widthOfPics, queryToInteger(routeParams.widthOfPics), -1), heightOfPics: fallback(params.heightOfPics, queryToInteger(routeParams.heightOfPics), -1), sizeOfAuthorAvatar: fallback(params.sizeOfAuthorAvatar, queryToInteger(routeParams.sizeOfAuthorAvatar), 48), - showEmojiInDescription: fallback(params.showEmojiInDescription, queryToInteger(routeParams.showEmojiInDescription), true), + showEmojiInDescription: fallback(params.showEmojiInDescription, queryToInteger(routeParams.showEmojiInDescription), false), showLinkIconInDescription: fallback(params.showLinkIconInDescription, queryToInteger(routeParams.showLinkIconInDescription), true), preferMobileLink: fallback(params.preferMobileLink, queryToBoolean(routeParams.preferMobileLink), false), }; @@ -157,13 +157,13 @@ const weiboUtils = { let style = ''; html += '= 0) { - html += ` width="${widthOfPics}"`; - style += `width: ${widthOfPics}px;`; + if (item.large.geo.width || widthOfPics >= 0) { + html += ` width="${item.large.geo.width || widthOfPics}"`; + style += `width: ${item.large.geo.width || widthOfPics}px;`; } - if (heightOfPics >= 0) { - html += ` height="${heightOfPics}"`; - style += `height: ${heightOfPics}px;`; + if (item.large.geo.height || heightOfPics >= 0) { + html += ` height="${item.large.geo.height || heightOfPics}"`; + style += `height: ${item.large.geo.height || heightOfPics}px;`; } html += ` style="${style}"` + ' src="' + item.large.url + '">'; diff --git a/lib/routes/xiaohongshu/user.ts b/lib/routes/xiaohongshu/user.ts index 2f9d95b6f..3a71e5910 100644 --- a/lib/routes/xiaohongshu/user.ts +++ b/lib/routes/xiaohongshu/user.ts @@ -99,7 +99,7 @@ async function getUserFeeds(url: string, category: string) { title: noteCard.displayTitle, link: new URL(noteCard.noteId || id, url).toString(), guid: noteCard.displayTitle, - description: `
${noteCard.displayTitle}`, + description: `
${noteCard.displayTitle}`, author: noteCard.user.nickname, upvotes: noteCard.interactInfo.likedCount, }))