From 09e86f8fcc229d0d9e6e11860ad7dd68abab4cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Fri, 16 Nov 2018 16:55:24 +0800 Subject: [PATCH] Hotfix: Twitter quote (#1165) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Closes #805 - 具体逻辑应该是没问题的了,显示方面上的调整还是交给 diy 来吧 233 --- routes/twitter/user.js | 44 ++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/routes/twitter/user.js b/routes/twitter/user.js index 15367b071..3da700ebc 100644 --- a/routes/twitter/user.js +++ b/routes/twitter/user.js @@ -6,6 +6,25 @@ const T = new Twit(config.twitter); module.exports = async (ctx) => { const id = ctx.params.id; + const formatText = (text) => text.replace(/https:\/\/t\.co(.*)/g, ''); + const formatMedia = (item) => { + let img = ''; + item.extended_entities && + item.extended_entities.media.forEach((item) => { + img += `
${item.type === 'video' ? 'Video: ' : ''}`; + }); + + return img; + }; + const formatUrl = (item) => { + let url = ''; + item.entities.urls.forEach((u) => { + url += `${u.expanded_url}`; + }); + + return url; + }; + const result = await T.get('statuses/user_timeline', { screen_name: id, tweet_mode: 'extended', @@ -19,19 +38,24 @@ module.exports = async (ctx) => { description: data[0].user.description, item: data.map((item) => { item = item.retweeted_status || item; - item.full_text = item.full_text.replace(/https:\/\/t\.co(.*)/g, ''); - let img = ''; - item.extended_entities && - item.extended_entities.media.forEach((item) => { - img += `
${item.type === 'video' ? 'Video: ' : ''}`; - }); + item.full_text = formatText(item.full_text); + const img = formatMedia(item); let url = ''; - item.entities.urls.forEach((u) => { - url += `${u.expanded_url}`; - }); + let quote = ''; + + if (item.is_quote_status) { + const quoteData = item.quoted_status; + const author = quoteData.user; + quote += `

${author.name}: ${formatText(quoteData.full_text)}
`; + quote += formatMedia(quoteData); + quote += formatUrl(quoteData); + } else { + url = formatUrl(item); + } + return { title: `${item.in_reply_to_screen_name ? 'Re ' : ''}${item.full_text}`, - description: `${item.in_reply_to_screen_name ? 'Re ' : ''}${item.full_text}${url}${img}`, + description: `${item.in_reply_to_screen_name ? 'Re ' : ''}${item.full_text}${url}${img}${quote}`, pubDate: new Date(item.created_at).toUTCString(), link: `https://twitter.com/${id}/status/${item.id_str}`, };