From 83aca709b028ecdf57980145f5c1cf5f9e4cc817 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Fri, 27 May 2022 08:16:35 +0800
Subject: [PATCH] fix(route): PANews (#9832)
* fix(route): PANews
* fix(route): PANews author
---
docs/new-media.md | 10 +++---
lib/v2/panewslab/{column.js => author.js} | 34 ++++++-------------
lib/v2/panewslab/index.js | 41 +++++++++++++----------
lib/v2/panewslab/maintainer.js | 4 ++-
lib/v2/panewslab/news.js | 28 ++++++++++++++++
lib/v2/panewslab/newsflash.js | 35 -------------------
lib/v2/panewslab/radar.js | 4 +--
lib/v2/panewslab/router.js | 6 ++--
lib/v2/panewslab/topic.js | 21 ++++--------
9 files changed, 84 insertions(+), 99 deletions(-)
rename lib/v2/panewslab/{column.js => author.js} (55%)
create mode 100644 lib/v2/panewslab/news.js
delete mode 100644 lib/v2/panewslab/newsflash.js
diff --git a/docs/new-media.md b/docs/new-media.md
index 4925fd987..82f88d574 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -965,22 +965,22 @@ IPFS 网关有可能失效,那时候换成其他网关。
${item.remark}`, - category: item.tags.split(','), - }; - }); + let items = response.data.data.map((item) => ({ + title: item.title, + author: item.author.name, + pubDate: parseDate(item.publishTime * 1000), + link: `${rootUrl}/zh/articledetails/${item.id}.html`, + description: `
${item.desc}`, + category: item.tags, + })); items = await Promise.all( items.map((item) => @@ -53,7 +41,7 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: `PANews - ${author}`, + title: `PANews - ${items[0].author}`, link: currentUrl, item: items, }; diff --git a/lib/v2/panewslab/index.js b/lib/v2/panewslab/index.js index 6afee6da6..0e8d52aa5 100644 --- a/lib/v2/panewslab/index.js +++ b/lib/v2/panewslab/index.js @@ -2,33 +2,40 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); +const categories = { + 精选: '', + 链游: 'aipysd', + 元宇宙: 'arxgdo', + NFT: 'dwhfpp', + DeFi: 'gsqjtg', + 监管: 'kohnph', + 央行数字货币: 'loskks', + 波卡: 'sxrabd', + 'Layer 2': 'tdkreq', + DAO: 'yyufxg', + 融资: 'zahilv', + 活动: 'zqives', +}; + module.exports = async (ctx) => { - const category = ctx.params.category ?? ''; + const category = ctx.params.category ?? '精选'; const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/api/newstopic/page`; + const apiUrl = `${rootUrl}/webapi/depth/list?LId=1&Rn=${ctx.query.limit ?? 25}&TagId=${categories[category]}&tw=0`; const currentUrl = `${rootUrl}/zh/profundity/index.html`; const response = await got({ - method: 'post', + method: 'get', url: apiUrl, - form: { - language: 'zh', - pageIndex: 1, - pageSize: 25, - newsTopicState: 'PUBLISHED', - isEssence: 'T', - tags: category, - }, }); - let items = response.data.data.list.map((item) => ({ + let items = response.data.data.map((item) => ({ title: item.title, - author: item.nick_name, - pubDate: parseDate(item.create_time), + author: item.author.name, + pubDate: parseDate(item.publishTime * 1000), link: `${rootUrl}/zh/articledetails/${item.id}.html`, - description: `
${item.remark}`, - category: item.tags.split(','), + description: `
${item.desc}`, + category: item.tags, })); items = await Promise.all( @@ -49,7 +56,7 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: `PANews - ${category || '精选'}`, + title: `PANews - ${category}`, link: currentUrl, item: items, }; diff --git a/lib/v2/panewslab/maintainer.js b/lib/v2/panewslab/maintainer.js index e97866430..06cba6d62 100644 --- a/lib/v2/panewslab/maintainer.js +++ b/lib/v2/panewslab/maintainer.js @@ -1,6 +1,8 @@ module.exports = { + '/author/:id': ['nczitzk'], '/column/:id': ['nczitzk'], - '/newsflash/:language?': ['nczitzk'], + '/news': ['nczitzk'], + '/newsflash': ['nczitzk'], '/topic/:id': ['nczitzk'], '/:category?': ['nczitzk'], }; diff --git a/lib/v2/panewslab/news.js b/lib/v2/panewslab/news.js new file mode 100644 index 000000000..25e00d13f --- /dev/null +++ b/lib/v2/panewslab/news.js @@ -0,0 +1,28 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://panewslab.com'; + const apiUrl = `${rootUrl}/webapi/flashnews?LId=1&Rn=${ctx.query.limit ?? 50}&tw=0`; + const currentUrl = `${rootUrl}/zh/news/index.html`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const items = response.data.data.flashNews[0].list.map((item) => ({ + title: item.title, + author: item.author.name, + pubDate: parseDate(item.publishTime * 1000), + link: `${rootUrl}/zh/articledetails/${item.id}.html`, + description: `
${item.desc.replace(/\r\n原文链接/g, '')}
`, + category: item.tags, + })); + + ctx.state.data = { + title: 'PANews - 快讯', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/panewslab/newsflash.js b/lib/v2/panewslab/newsflash.js deleted file mode 100644 index 404262b9a..000000000 --- a/lib/v2/panewslab/newsflash.js +++ /dev/null @@ -1,35 +0,0 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); - -module.exports = async (ctx) => { - const language = ctx.params.language ?? 'zh'; - - const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/api/sqtopic/pageBy`; - const currentUrl = `${rootUrl}/${language}/news/index.html`; - - const response = await got({ - method: 'post', - url: apiUrl, - form: { - language, - pageIndex: 1, - pageSize: 50, - topicState: 'PUBLISHED', - }, - }); - - const items = response.data.data.list[0].data.map((item) => ({ - title: item.title, - author: item.nick_name, - pubDate: parseDate(item.create_time), - link: `${rootUrl}/${language}/sqarticledetails/${item.id}.html`, - description: `${item.content.replace(/来源链接$/, '').replace(/原文链接$/, '')}
`, - })); - - ctx.state.data = { - title: 'PANews - 快讯', - link: currentUrl, - item: items, - }; -}; diff --git a/lib/v2/panewslab/radar.js b/lib/v2/panewslab/radar.js index 12d1fe4df..46cfa95ea 100644 --- a/lib/v2/panewslab/radar.js +++ b/lib/v2/panewslab/radar.js @@ -12,13 +12,13 @@ module.exports = { title: '快讯', docs: 'https://docs.rsshub.app/new-media.html#panews-kuai-xun', source: '/', - target: '/panewslab/newsflash/:language?', + target: '/panewslab/news', }, { title: '专栏', docs: 'https://docs.rsshub.app/new-media.html#panews-zhuan-lan', source: '/', - target: '/panewslab/column/:id', + target: '/panewslab/author/:id', }, { title: '专题', diff --git a/lib/v2/panewslab/router.js b/lib/v2/panewslab/router.js index f4a36673d..32b02864b 100644 --- a/lib/v2/panewslab/router.js +++ b/lib/v2/panewslab/router.js @@ -1,6 +1,8 @@ module.exports = function (router) { - router.get('/column/:id', require('./column')); - router.get('/newsflash/:language?', require('./newsflash')); + router.get('/author/:id', require('./author')); + router.get('/column/:id', require('./author')); + router.get('/news', require('./news')); + router.get('/newsflash', require('./news')); router.get('/topic/:id', require('./topic')); router.get('/:category?', require('./index')); }; diff --git a/lib/v2/panewslab/topic.js b/lib/v2/panewslab/topic.js index dab1565c8..a35c73ac7 100644 --- a/lib/v2/panewslab/topic.js +++ b/lib/v2/panewslab/topic.js @@ -6,28 +6,21 @@ module.exports = async (ctx) => { const id = ctx.params.id; const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/newstopic/pageH`; + const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.query.limit ?? 25}&LId=1&sid=${id}&tw=0`; const currentUrl = `${rootUrl}/zh/topiclist/${id}.html`; const response = await got({ - method: 'post', + method: 'get', url: apiUrl, - form: { - language: 'zh', - pageIndex: 1, - pageSize: 25, - newsThemeId: id, - newsTopicState: 'PUBLISHED', - }, }); - let items = response.data.data.list.map((item) => ({ + let items = response.data.data.map((item) => ({ title: item.title, - author: item.nick_name, - pubDate: parseDate(item.create_time), + author: item.author.name, + pubDate: parseDate(item.publishTime * 1000), link: `${rootUrl}/zh/articledetails/${item.id}.html`, - description: `${item.remark}`, - category: item.tags.split(','), + description: `
${item.desc}`, + category: item.tags, })); items = await Promise.all(