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 &&