From 670f6f3ca7f1b6208293c9b3767d925ae7f0d89f Mon Sep 17 00:00:00 2001
From: tmr <32825326+ttttmr@users.noreply.github.com>
Date: Thu, 1 Feb 2024 10:20:39 +0800
Subject: [PATCH] fix: replace weibo a href img (#14354)
---
lib/middleware/anti-hotlink.js | 1 +
lib/v2/weibo/utils.js | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/middleware/anti-hotlink.js b/lib/middleware/anti-hotlink.js
index 9a216126a..82c56de4f 100644
--- a/lib/middleware/anti-hotlink.js
+++ b/lib/middleware/anti-hotlink.js
@@ -70,6 +70,7 @@ const process = (html, image_hotlink_template, multimedia_hotlink_template, wrap
if (image_hotlink_template) {
replaceUrls($, 'img, picture > source', image_hotlink_template);
replaceUrls($, 'video[poster]', image_hotlink_template, 'poster');
+ replaceUrls($, '*[data-rsshub-image="href"]', image_hotlink_template, 'href');
}
if (multimedia_hotlink_template) {
replaceUrls($, 'video, video > source, audio, audio > source', multimedia_hotlink_template);
diff --git a/lib/v2/weibo/utils.js b/lib/v2/weibo/utils.js
index 18d953847..aa9c8fc50 100644
--- a/lib/v2/weibo/utils.js
+++ b/lib/v2/weibo/utils.js
@@ -82,7 +82,10 @@ const weiboUtils = {
htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/全文<\/a>/g, '');
// 处理外部链接
- htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/https:\/\/weibo\.cn\/sinaurl\/.*?&u=(http.*?")/g, (match, p1) => decodeURIComponent(p1));
+ htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/"https:\/\/weibo\.cn\/sinaurl.*?[&?]u=(http.*?)"/g, (match, p1) => `"${decodeURIComponent(p1)}"`);
+
+ // 处理图片的链接
+ htmlNewLineUnreplaced = htmlNewLineUnreplaced.replaceAll(/ `${match} data-rsshub-image="href"`);
let html = htmlNewLineUnreplaced.replaceAll('\n', '
');