mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 08:10:32 +08:00
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const timezone = require('@/utils/timezone');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
const { rootUrl } = require('./utils');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id;
|
|
|
|
const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.query.limit ?? 25}`;
|
|
|
|
let author = '';
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
let items = response.data.data.items.data.map((item) => ({
|
|
title: item.title,
|
|
summary: item.summary,
|
|
link: `${rootUrl}/post/${item.entity_id}`,
|
|
pubDate: timezone(parseDate(item.published_at), +8),
|
|
}));
|
|
|
|
items = await Promise.all(
|
|
items.map(
|
|
async (item) =>
|
|
await ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
|
|
const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]);
|
|
|
|
content('img').each(function () {
|
|
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
|
});
|
|
|
|
item.description = content.html();
|
|
item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1];
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `${author} - Odaily星球日报`,
|
|
link: `${rootUrl}/user/${id}`,
|
|
item: items,
|
|
};
|
|
};
|