From 565ab1f88973b847542fa7c412aa0dd740903f1a Mon Sep 17 00:00:00 2001 From: AgFlore Date: Sun, 4 Oct 2020 04:22:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AB=AF=E4=BC=A0=E5=AA=92=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E6=8E=A5=E5=8F=A3=E5=8D=87=E7=BA=A7=20(#5786)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: codefactor-io --- docs/traditional-media.md | 22 ++++++++++++------- lib/router.js | 1 + lib/routes/initium/full.js | 45 ++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 747b2093b..bbe5d4cf4 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -241,26 +241,32 @@ Category 列表: ## 端传媒 -### 端传媒 - - +通过提取文章全文,以提供比官方源更佳的阅读体验。 ::: warning 注意 -付费内容全文需要登陆获取,详情见部署页面的配置模块。 +付费内容全文可能需要登陆获取,详情见部署页面的配置模块。 ::: +### 专题・栏目 + + + Type 栏目: -| 深度 | What’s New | 广场 | Pick-Up | -| ------- | ---------- | ----------------- | ------- | -| feature | news-brief | notes-and-letters | pick_up | +| 最新 | 深度 | What’s New | 广场 | 科技 | 风物 | 特约 | ... | +| ------ | ------- | ---------- | ----------------- | ---------- | ------- | ------- | --- | +| latest | feature | news-brief | notes-and-letters | technology | culture | pick_up | ... | -通过提取文章全文,以提供比官方源更佳的阅读体验. +更多栏目名称可通过 获取。 +### 话题・标签 + + + ## 多维新闻网 ### 要闻 diff --git a/lib/router.js b/lib/router.js index ee4cfff80..20ac5b037 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2855,6 +2855,7 @@ router.get('/netease/news/special/:type?', require('./routes/netease/news/specia // 端传媒 router.get('/initium/:type?/:language?', require('./routes/initium/full')); +router.get('/theinitium/:model/:type?/:language?', require('./routes/initium/full')); // Grub Street router.get('/grubstreet', require('./routes/grubstreet/index')); diff --git a/lib/routes/initium/full.js b/lib/routes/initium/full.js index 7f785e438..c484e791d 100644 --- a/lib/routes/initium/full.js +++ b/lib/routes/initium/full.js @@ -4,8 +4,33 @@ const cheerio = require('cheerio'); const resolve_url = require('url').resolve; module.exports = async (ctx) => { - const type = ctx.params.type || 'feature'; + // model是channel/tag/etc.,而type是latest/feature/quest-academy/etc. + const model = ctx.params.model || 'channel'; + const type = ctx.params.type || 'latest'; const language = ctx.params.language || 'zh-hans'; + let listurl; + let listlink; + switch (model) { + + /* + case 'author': + listurl = `https://api.theinitium.com/api/v2/author/?language=${language}&slug=${type}`; + listlink = `https://theinitium.com/author/${type}/`; + break; + case 'follows': + listurl = `https://api.theinitium.com/api/v2/user/follows/?language=${language}&slug=${type}`; + listlink = `https://theinitium.com/follow/`; + break; + */ + case 'channel': + listurl = `https://api.theinitium.com/api/v2/channel/articles/?language=${language}&slug=${type}`; + listlink = `https://theinitium.com/channel/${type}/`; + break; + case 'tags': + listurl = `https://api.theinitium.com/api/v2/tag/articles/?language=${language}&slug=${type}`; + listlink = `https://theinitium.com/tags/${type}/`; + break; + } const key = { email: config.initium.username, @@ -25,7 +50,7 @@ module.exports = async (ctx) => { } else { const login = await got({ method: 'post', - url: `https://api.theinitium.com/api/v1/auth/login/?language=${language}`, + url: `https://api.theinitium.com/api/v2/auth/login/?language=${language}`, headers: { 'Content-Type': 'application/json', Accept: 'application/json', @@ -55,7 +80,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', - url: `https://api.theinitium.com/api/v1/channel/articles/?language=${language}&slug=${type}`, + url: listurl, headers: { 'X-Client-Name': 'Web', Accept: '*/*', @@ -68,6 +93,7 @@ module.exports = async (ctx) => { const name = response.data.name; const articles = response.data.digests; + const image = 'https://d32kak7w9u5ewj.cloudfront.net/static/bundles/0b9cf7fe9c518887768e6c485764cd12.ico'; const getFullText = async (slug) => { let content = await ctx.cache.get(slug + language); @@ -79,14 +105,14 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', - url: `https://api.theinitium.com/api/v1/article/detail/?language=${language}&slug=${slug}`, + url: `https://api.theinitium.com/api/v2/article/detail/?language=${language}&slug=${slug}`, headers: { 'X-Client-Name': 'web', Accept: '*/*', Connection: 'keep-alive', Authorization: token, Origin: `https://theinitium.com/`, - Referer: `https://theinitium.com/`, + Referer: `https://theinitium.com/article/${slug}`, }, }); @@ -126,17 +152,22 @@ module.exports = async (ctx) => { }; const items = await Promise.all( - articles.slice(0, 10).map(async (item) => ({ + articles.slice(0, token === 'Basic YW5vbnltb3VzOkdpQ2VMRWp4bnFCY1ZwbnA2Y0xzVXZKaWV2dlJRY0FYTHY=' ? 10 : articles.length).map(async (item) => ({ title: item.article.headline, + author: item.article.authors.length > 0 ? item.article.authors.map((x) => x.name).toString() : item.article.byline, + category: item.article.channels.filter((x) => !x.homepage).map((x) => x.name), description: await getFullText(item.article.slug), link: resolve_url('https://theinitium.com', item.article.url), pubDate: item.article.date, + updated: item.article.updated, + guid: item.article.uuid, })) ); ctx.state.data = { title: `端传媒 - ${name}`, - link: `https://theinitium.com`, + link: listlink, item: items, + image: image, }; };