feat: 豆瓣广播全文输出 (#6742) (#6756)

This commit is contained in:
Queensferry
2021-01-23 22:40:51 -05:00
committed by GitHub
parent 9ebc992d85
commit 6c0349152d
+43 -12
View File
@@ -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 &&