From e43b6fda846fdddcf4eeba57f8984f002f83f3ff Mon Sep 17 00:00:00 2001 From: tmr <32825326+ttttmr@users.noreply.github.com> Date: Tue, 12 Mar 2024 00:05:41 +0800 Subject: [PATCH] fix: weibo image regex (#14739) * fix: weibo image regex * fix: return handlers --------- --- lib/routes/weibo/friends.ts | 13 +++++-------- lib/routes/weibo/group.ts | 15 ++++++--------- lib/routes/weibo/keyword.ts | 34 ++++++++++++++++----------------- lib/routes/weibo/oasis/user.ts | 29 +++++++++++++--------------- lib/routes/weibo/super-index.ts | 15 ++++++--------- lib/routes/weibo/timeline.ts | 17 +++++++---------- lib/routes/weibo/user.ts | 17 +++++++---------- lib/routes/weibo/utils.ts | 2 +- 8 files changed, 61 insertions(+), 81 deletions(-) diff --git a/lib/routes/weibo/friends.ts b/lib/routes/weibo/friends.ts index 6707d4c0f..6be1e2101 100644 --- a/lib/routes/weibo/friends.ts +++ b/lib/routes/weibo/friends.ts @@ -146,12 +146,9 @@ async function handler(ctx) { }) ); - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title, - link: `https://weibo.com`, - item: resultItems, - }) - ); + return weiboUtils.sinaimgTvax({ + title, + link: `https://weibo.com`, + item: resultItems, + }); } diff --git a/lib/routes/weibo/group.ts b/lib/routes/weibo/group.ts index 630bc0549..ad2a16117 100644 --- a/lib/routes/weibo/group.ts +++ b/lib/routes/weibo/group.ts @@ -103,13 +103,10 @@ async function handler(ctx) { }) ); - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title: groupName, - link: `https://weibo.com/mygroups?gid=${gid}`, - description: '微博自定义分组', - item: resultItems, - }) - ); + return weiboUtils.sinaimgTvax({ + title: groupName, + link: `https://weibo.com/mygroups?gid=${gid}`, + description: '微博自定义分组', + item: resultItems, + }); } diff --git a/lib/routes/weibo/keyword.ts b/lib/routes/weibo/keyword.ts index 9d6ed9261..b56e926c2 100644 --- a/lib/routes/weibo/keyword.ts +++ b/lib/routes/weibo/keyword.ts @@ -48,22 +48,20 @@ async function handler(ctx) { ); const routeParams = querystring.parse(ctx.req.param('routeParams')); - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title: `又有人在微博提到${keyword}了`, - link: `http://s.weibo.com/weibo/${encodeURIComponent(keyword)}&b=1&nodup=1`, - description: `又有人在微博提到${keyword}了`, - item: data.map((item) => { - item.mblog.created_at = timezone(item.mblog.created_at, +8); - if (item.mblog.retweeted_status && item.mblog.retweeted_status.created_at) { - item.mblog.retweeted_status.created_at = timezone(item.mblog.retweeted_status.created_at, +8); - } - return weiboUtils.formatExtended(ctx, item.mblog, undefined, { - showAuthorInTitle: fallback(undefined, queryToBoolean(routeParams.showAuthorInTitle), true), - showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.showAuthorInDesc), true), - }); - }), - }) - ); + + return weiboUtils.sinaimgTvax({ + title: `又有人在微博提到${keyword}了`, + link: `http://s.weibo.com/weibo/${encodeURIComponent(keyword)}&b=1&nodup=1`, + description: `又有人在微博提到${keyword}了`, + item: data.map((item) => { + item.mblog.created_at = timezone(item.mblog.created_at, +8); + if (item.mblog.retweeted_status && item.mblog.retweeted_status.created_at) { + item.mblog.retweeted_status.created_at = timezone(item.mblog.retweeted_status.created_at, +8); + } + return weiboUtils.formatExtended(ctx, item.mblog, undefined, { + showAuthorInTitle: fallback(undefined, queryToBoolean(routeParams.showAuthorInTitle), true), + showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.showAuthorInDesc), true), + }); + }), + }); } diff --git a/lib/routes/weibo/oasis/user.ts b/lib/routes/weibo/oasis/user.ts index 863d32711..aa490b536 100644 --- a/lib/routes/weibo/oasis/user.ts +++ b/lib/routes/weibo/oasis/user.ts @@ -27,21 +27,18 @@ export const route: Route = { async function handler(ctx) { const userid = ctx.req.param('userid'); const link = `https://oasis.weibo.cn/v1/h5/share?uid=${userid}`; - ctx.set( - 'data', - weiboUtils.sinaimgTvax( - await buildData({ - link, - url: link, - title: `$('.name-main').text().trim() + ' - 用户 - 绿洲'`, - description: `$('.desc').text().trim()`, - item: { - item: '.container .status-item', - title: `$('.status-item-title').clone().children().remove().end().text()`, - description: `$('.status-item-title').clone().children().remove().end().text() + '
' + $('.status-img').html()`, - link: `'https://oasis.weibo.cn/v1/h5/share?sid=' + $('.status-item-title').parent().data('id')`, - }, - }) - ) + return weiboUtils.sinaimgTvax( + await buildData({ + link, + url: link, + title: `$('.name-main').text().trim() + ' - 用户 - 绿洲'`, + description: `$('.desc').text().trim()`, + item: { + item: '.container .status-item', + title: `$('.status-item-title').clone().children().remove().end().text()`, + description: `$('.status-item-title').clone().children().remove().end().text() + '
' + $('.status-img').html()`, + link: `'https://oasis.weibo.cn/v1/h5/share?sid=' + $('.status-item-title').parent().data('id')`, + }, + }) ); } diff --git a/lib/routes/weibo/super-index.ts b/lib/routes/weibo/super-index.ts index 5cdac7392..a52113d61 100644 --- a/lib/routes/weibo/super-index.ts +++ b/lib/routes/weibo/super-index.ts @@ -76,13 +76,10 @@ async function handler(ctx) { } } - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title: `微博超话 - ${containerData.pageInfo.page_title}`, - link: `https://weibo.com/p/${id}/super_index`, - description: `#${containerData.pageInfo.page_title}# 的超话`, - item: resultItems, - }) - ); + return weiboUtils.sinaimgTvax({ + title: `微博超话 - ${containerData.pageInfo.page_title}`, + link: `https://weibo.com/p/${id}/super_index`, + description: `#${containerData.pageInfo.page_title}# 的超话`, + item: resultItems, + }); } diff --git a/lib/routes/weibo/timeline.ts b/lib/routes/weibo/timeline.ts index 84caf1817..10aebac2f 100644 --- a/lib/routes/weibo/timeline.ts +++ b/lib/routes/weibo/timeline.ts @@ -142,16 +142,13 @@ async function handler(ctx) { }) ); - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title: `个人微博时间线--${name}`, - link: `http://weibo.com/${uid}/`, - description, - image: profileImageUrl, - item: resultItem, - }) - ); + return weiboUtils.sinaimgTvax({ + title: `个人微博时间线--${name}`, + link: `http://weibo.com/${uid}/`, + description, + image: profileImageUrl, + item: resultItem, + }); } else if (uid === '0' || ctx.req.query()) { const { app_key = '', redirect_url = ctx.req.origin + '/weibo/timeline/0', app_secret = '' } = config.weibo; diff --git a/lib/routes/weibo/user.ts b/lib/routes/weibo/user.ts index 24a029524..9ab4651ce 100644 --- a/lib/routes/weibo/user.ts +++ b/lib/routes/weibo/user.ts @@ -169,14 +169,11 @@ async function handler(ctx) { } } - ctx.set( - 'data', - weiboUtils.sinaimgTvax({ - title: `${name}的微博`, - link: `https://weibo.com/${uid}/`, - description, - image: profileImageUrl, - item: resultItems, - }) - ); + return weiboUtils.sinaimgTvax({ + title: `${name}的微博`, + link: `https://weibo.com/${uid}/`, + description, + image: profileImageUrl, + item: resultItems, + }); } diff --git a/lib/routes/weibo/utils.ts b/lib/routes/weibo/utils.ts index 84b4f7202..4efa0a31e 100644 --- a/lib/routes/weibo/utils.ts +++ b/lib/routes/weibo/utils.ts @@ -86,7 +86,7 @@ const weiboUtils = { htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/"https:\/\/weibo\.cn\/sinaurl.*?[&?]u=(http.*?)"/g, (match, p1) => `"${decodeURIComponent(p1)}"`); // 处理图片的链接 - htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/ `${match} data-rsshub-image="href"`); + htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/ `${match} data-rsshub-image="href"`); let html = htmlNewLineUnreplaced.replaceAll('\n', '
');