From a832e97109a87c6f3da44f1c6a67c4692ca4cb71 Mon Sep 17 00:00:00 2001 From: Rongrong Date: Mon, 24 Jul 2023 10:17:17 +0800 Subject: [PATCH] fix(route/twitter): media t.co links not purged (#12864) --- lib/v2/twitter/utils.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/v2/twitter/utils.js b/lib/v2/twitter/utils.js index 9064e6654..fbbf1e2fd 100644 --- a/lib/v2/twitter/utils.js +++ b/lib/v2/twitter/utils.js @@ -29,10 +29,16 @@ const getOriginalImg = (url) => { }; const replaceBreak = (text) => text.replace(/

|
/g, ' '); -const formatText = (text, urls) => { +const formatText = (item) => { + let text = item.full_text; + const urls = item.entities.urls || []; urls.forEach((url) => { text = text.replaceAll(url.url, url.expanded_url); }); + const media = item.extended_entities?.media || []; + media.forEach((m) => { + text = text.replaceAll(m.url, ''); + }); return text.trim().replace(/\n/g, '
'); }; @@ -179,7 +185,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { const originalItem = item; item = item.retweeted_status || item; item.full_text = item.full_text || item.text; - item.full_text = formatText(item.full_text, item.entities.urls); + item.full_text = formatText(item); const img = formatMedia(item); let picsPrefix = generatePicsPrefix(item); let quote = ''; @@ -223,7 +229,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { } quote += `: `; - quote += formatText(quoteData.full_text, quoteData.entities.urls); + quote += formatText(quoteData); if (!readable) { quote += '
'; @@ -231,7 +237,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { quote += formatMedia(quoteData); picsPrefix += generatePicsPrefix(quoteData); quoteInTitle += showEmojiForRetweetAndReply ? ' 💬 ' : showSymbolForRetweetAndReply ? ' RT ' : ''; - quoteInTitle += `${author.name}: ${formatText(quoteData.full_text, quoteData.entities.urls)}`; + quoteInTitle += `${author.name}: ${formatText(quoteData)}`; if (readable) { quote += `
Link: https://twitter.com/${author.screen_name}/status/${quoteData.id_str}`;