fix(route): odaily (#11220)

This commit is contained in:
Tony 2022-11-05 01:10:46 +09:00 committed by GitHub
parent d1818958af
commit e0fb051047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 21 deletions

View File

@ -20,15 +20,11 @@ module.exports = async (ctx) => {
const currentUrl = `${rootUrl}/api/pp/api/app-front/feed-stream?feed_id=${id}&b_id=&per_page=${ctx.query.limit ?? 25}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const response = await got(currentUrl);
let items = response.data.data.items
.map((item) => ({
title: item.title,
author: item.user.name,
type: item.entity_type,
description: `<p>${item.summary}</p>`,
link: `${rootUrl}/${item.entity_type}/${item.entity_id}`,
@ -37,26 +33,25 @@ module.exports = async (ctx) => {
.filter((item) => item.type !== 'newsflash');
items = await Promise.all(
items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data.match(item.type === 'post' ? /"content":"(.*)","extraction_tags":/ : /"description":"(.*?)","cover":/)[1]);
const ssr = JSON.parse(`{${detailResponse.data.match(/window\.__INITIAL_STATE__ = {(.*)}/)[1]}}`);
content('img').each(function () {
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
});
const content = cheerio.load(ssr.post.detail.content, null, false);
content('img').each((_, img) => {
img.attribs.src = img.attribs.src.split('?x-oss-process')[0];
img.attribs.src = img.attribs.src.split('!heading')[0];
});
item.description = content.html();
item.description = content.html();
item.author = ssr.post.user.name;
delete item.type;
delete item.type;
return item;
})
return item;
})
)
);

View File

@ -1,3 +1,3 @@
module.exports = {
rootUrl: 'https://www.0daily.com',
rootUrl: 'https://www.odaily.news',
};