Skip to content

Commit

Permalink
fix(route): ifeng/feng this route is empty (#9372)
Browse files Browse the repository at this point in the history
* ifeng/feng this route is empty

* refactor: migrate to v2

* fix: parseDate
  • Loading branch information
Fatpandac authored Mar 23, 2022
1 parent baeafb9 commit 259bcf1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,8 @@ router.get('/lastfm/top/:country?', lazyloadRouteHandler('./routes/lastfm/top'))
router.get('/piapro/user/:pid', lazyloadRouteHandler('./routes/piapro/user'));
router.get('/piapro/public/:type/:tag?/:category?', lazyloadRouteHandler('./routes/piapro/public'));

// 凤凰网
router.get('/ifeng/feng/:id/:type', lazyloadRouteHandler('./routes/ifeng/feng'));
// 凤凰网 migrated to v2
// router.get('/ifeng/feng/:id/:type', lazyloadRouteHandler('./routes/ifeng/feng'));

// 第一版主
router.get('/novel/d1bz/:category/:id', lazyloadRouteHandler('./routes/d1bz/novel'));
Expand Down
12 changes: 7 additions & 5 deletions lib/routes/ifeng/feng.js → lib/v2/ifeng/feng.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const { JSDOM } = require('jsdom');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const id = ctx.params.id;
Expand All @@ -15,14 +17,14 @@ module.exports = async (ctx) => {
});
const contentResponse = await got({
method: 'get',
url: `https://shankapi.ifeng.com/winter/feng/author/getFengAuthorListData/${id}/${type}/1`,
url: `https://shankapi.ifeng.com/season/ishare/getShareListData/${id}/${type}/1/ifengnewsh5/getListData`,
headers: {
Referer: `https://feng.ifeng.com/author/${id}`,
},
});

const userData = userResponse.data.data.data;
const contentData = contentResponse.data.data;
const contentData = JSON.parse(contentResponse.data.match(/"data":(\[(.*?)\])/)[1]);

const mediaName = userData.weMediaName;
const items = await Promise.all(
Expand All @@ -31,13 +33,13 @@ module.exports = async (ctx) => {
const simple = {
title: item.title,
description: `<img src="${item.thumbnail}">${item.title}`,
pubDate: new Date(Date.parse(item.newsTime.replace(/-/g, '/'))),
pubDate: timezone(parseDate(item.newsTime), +8),
author: mediaName,
link,
};

const details = await ctx.cache.tryGet(`ifeng:feng:${link}`, async () => {
const response = await got.get(link);
const response = await got(link);
const $ = cheerio.load(response.data);
if (type === 'doc') {
const dom = new JSDOM(`<body><script>${$('[async] + script').html()}</script></body>`, {
Expand All @@ -57,7 +59,7 @@ module.exports = async (ctx) => {
description: $('meta[name=description]').attr('content'),
};
});
return Promise.resolve(Object.assign({}, simple, details));
return { ...simple, ...details };
})
);

Expand Down
3 changes: 3 additions & 0 deletions lib/v2/ifeng/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/feng/:id/:type': ['Jamch'],
};
11 changes: 11 additions & 0 deletions lib/v2/ifeng/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
'ifeng.com': {
_name: '凤凰网',
'.': [
{
title: '大风号',
docs: 'https://docs.rsshub.app/new-media.html#feng-huang-wang',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ifeng/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/feng/:id/:type', require('./feng'));
};
File renamed without changes.

0 comments on commit 259bcf1

Please sign in to comment.