From 6c0349152d28bfd7df4af07bf5b544945288d262 Mon Sep 17 00:00:00 2001 From: Queensferry Date: Sun, 24 Jan 2021 11:40:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B1=86=E7=93=A3=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E5=85=A8=E6=96=87=E8=BE=93=E5=87=BA=20(#6742)=20(#6756)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/douban/people/status.js | 55 +++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/lib/routes/douban/people/status.js b/lib/routes/douban/people/status.js index d413ab77d2..cfd6c62804 100644 --- a/lib/routes/douban/people/status.js +++ b/lib/routes/douban/people/status.js @@ -2,6 +2,8 @@ const querystring = require('querystring'); const got = require('@/utils/got'); const { fallback, queryToBoolean, queryToInteger } = require('@/utils/readable-social'); +const headers = { Referer: `https://m.douban.com/` }; + function tryFixStatus(status) { let result = { isFixSuccess: true, why: '' }; const now = new Date(); @@ -407,24 +409,53 @@ function getContentByActivity(ctx, item, params = {}, picsPrefixes = []) { return { title, description }; } +async function getFullTextItems(ctx, items) { + const prefix = 'https://m.douban.com/rexxar/api/v2/status/'; + + await Promise.all( + items.map(async (item) => { + let url = prefix + item.status.id; + let cache = ctx.cache.get(url); + if (cache) { + item.status.text = cache; + } else { + const { + data: { text }, + } = await got({ url, headers }); + ctx.cache.set(url, text); + item.status.text = text; + } + // retweet + if (!item.status.reshared_status) { + return; + } + url = prefix + item.status.reshared_status.id; + cache = ctx.cache.get(url); + if (cache) { + item.status.reshared_status.text = cache; + } else { + const { + data: { text }, + } = await got({ url, headers }); + ctx.cache.set(url, text); + item.status.reshared_status.text = text; + } + }) + ); +} + module.exports = async (ctx) => { const userid = ctx.params.userid; - const url = `https://m.douban.com/rexxar/api/v2/status/user_timeline/${userid}?max_id=&ck=eUUA&for_mobile=1`; - - const response = await got({ - method: 'GET', - url: url, - headers: { - Referer: `https://m.douban.com/people/${userid}/statuses`, - }, - }); - + const url = `https://m.douban.com/rexxar/api/v2/status/user_timeline/${userid}`; + const response = await got({ url, headers }); const items = response.data.items; - const username = items ? items[0].status.author.name : ''; + if (items) { + await getFullTextItems(ctx, items); + } ctx.state.data = { - title: `豆瓣广播 - ${username ? username : userid}`, + title: `豆瓣广播 - ${items ? items[0].status.author.name : userid}`, link: `https://m.douban.com/people/${userid}/statuses`, item: items &&