fix(route): foresightnews (#11218)

This commit is contained in:
Tony
2022-11-04 22:44:49 +08:00
committed by GitHub
parent d926a02d62
commit d1818958af
+8 -11
View File
@@ -1,6 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const zlib = require('zlib');
const categories = {
'': {
@@ -28,12 +29,11 @@ module.exports = async (ctx) => {
const rootUrl = 'https://foresightnews.pro';
const currentUrl = `${rootUrl}/v1/${categories[category].id}?page=1&size=${ctx.query.limit ?? 30}${category === 'column' ? `&column_id=${id}` : ''}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const response = await got(currentUrl);
let items = response.data.data.list.map((item) =>
const list = JSON.parse(zlib.inflateSync(Buffer.from(response.data.data.list, 'base64')).toString());
let items = list.map((item) =>
item.source_type
? {
type: item.source_type,
@@ -47,8 +47,8 @@ module.exports = async (ctx) => {
: {
type: category,
title: item.title,
author: item?.author?.username ?? undefined,
link: `${rootUrl}/${category === 'article' ? 'article' : 'news'}/detail/${item.id}`,
author: item.author?.username ?? undefined,
link: `${rootUrl}/${category === 'article' || category === 'column' ? 'article' : 'news'}/detail/${item.id}`,
category: item.tags ? item.tags.map((tag) => tag.name) : undefined,
description: item.content ?? '',
pubDate: parseDate(item.publishDate),
@@ -63,10 +63,7 @@ module.exports = async (ctx) => {
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (item.type !== 'news') {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);