fix: 端传媒网站接口升级 (#5786)
Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
parent
425e2402b1
commit
565ab1f889
|
|
@ -241,26 +241,32 @@ Category 列表:
|
|||
|
||||
## 端传媒
|
||||
|
||||
### 端传媒
|
||||
|
||||
<Route author="prnake" example="/initium/feature/zh-hans" path="/initium/:type?/:language?" :paramsDesc="['栏目,缺省为深度', '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体']"/>
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验。
|
||||
|
||||
::: warning 注意
|
||||
|
||||
付费内容全文需要登陆获取,详情见部署页面的配置模块。
|
||||
付费内容全文可能需要登陆获取,详情见部署页面的配置模块。
|
||||
|
||||
:::
|
||||
|
||||
### 专题・栏目
|
||||
|
||||
<Route author="prnake" example="/initium/latest/zh-hans" path="/initium/:type?/:language?" :paramsDesc="['栏目,缺省为最新', '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体']"/>
|
||||
|
||||
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 | ... |
|
||||
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验.
|
||||
更多栏目名称可通过 <https://theinitium.com/section/special/> 及 <https://theinitium.com/section/hot_channel/> 获取。
|
||||
|
||||
</Route>
|
||||
|
||||
### 话题・标签
|
||||
|
||||
<Route author="AgFlore" example="/theinitium/tags/2019_10/zh-hans" path="/theinitium/tags/:type/:language?" :paramsDesc="['话题ID,可从话题页URL中获取,如<https://theinitium.com/tags/2019_10/>', '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体']"/>
|
||||
|
||||
## 多维新闻网
|
||||
|
||||
### 要闻
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue