From f660fc45648b0a4e089caf23ef541e5d362c7f16 Mon Sep 17 00:00:00 2001 From: COxDE <63153334+coxde@users.noreply.github.com> Date: Tue, 27 Sep 2022 03:52:49 +0800 Subject: [PATCH] fix(route): Add favicon for Initium (#10904) * fix(route): Add favicon for Initium * refactor: migrate to v2 --- docs/new-media.md | 44 ++++++++ docs/traditional-media.md | 44 -------- lib/router.js | 4 +- lib/routes/initium/full.js | 188 -------------------------------- lib/v2/theinitium/full.js | 169 ++++++++++++++++++++++++++++ lib/v2/theinitium/maintainer.js | 6 + lib/v2/theinitium/radar.js | 25 +++++ lib/v2/theinitium/router.js | 3 + 8 files changed, 249 insertions(+), 234 deletions(-) delete mode 100644 lib/routes/initium/full.js create mode 100644 lib/v2/theinitium/full.js create mode 100644 lib/v2/theinitium/maintainer.js create mode 100644 lib/v2/theinitium/radar.js create mode 100644 lib/v2/theinitium/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 5ecbcfd81d..e41fd647c2 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2022,6 +2022,50 @@ area 分区选项 +## 端传媒 + +通过提取文章全文,以提供比官方源更佳的阅读体验。 + +::: warning 注意 + +付费内容全文可能需要登陆获取,详情见部署页面的配置模块。 + +::: + +### 专题・栏目 + + + +Type 栏目: + +| 最新 | 深度 | What’s New | 广场 | 科技 | 风物 | 特约 | ... | +| ------ | ------- | ---------- | ----------------- | ---------- | ------- | ------- | --- | +| latest | feature | news-brief | notes-and-letters | technology | culture | pick_up | ... | + +更多栏目名称可通过 及 获取。 + + + +### 话题・标签 + + + +### 作者 + + + +### 个人订阅追踪动态 + + + +::: warning 注意 + +需要自建,详情见部署页面的配置模块。 + +::: + + + ## 多知网 ### 首页 diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 2addd8ccda..98371dc0ef 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -881,50 +881,6 @@ IT・科学 tech_science -## 端传媒 - -通过提取文章全文,以提供比官方源更佳的阅读体验。 - -::: warning 注意 - -付费内容全文可能需要登陆获取,详情见部署页面的配置模块。 - -::: - -### 专题・栏目 - - - -Type 栏目: - -| 最新 | 深度 | What’s New | 广场 | 科技 | 风物 | 特约 | ... | -| ------ | ------- | ---------- | ----------------- | ---------- | ------- | ------- | --- | -| latest | feature | news-brief | notes-and-letters | technology | culture | pick_up | ... | - -更多栏目名称可通过 及 获取。 - - - -### 话题・标签 - - - -### 作者 - - - -### 个人订阅追踪动态 - - - -::: warning 注意 - -需要自建,详情见部署页面的配置模块。 - -::: - - - ## 俄罗斯卫星通讯社 ### 分类 diff --git a/lib/router.js b/lib/router.js index 6fcf934329..9dec3517c0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2794,8 +2794,8 @@ router.get('/jijitang/publication', lazyloadRouteHandler('./routes/jijitang/publ // router.get('/xwlb', lazyloadRouteHandler('./routes/xwlb/index')); // 端传媒 -router.get('/initium/:type?/:language?', lazyloadRouteHandler('./routes/initium/full')); -router.get('/theinitium/:model/:type?/:language?', lazyloadRouteHandler('./routes/initium/full')); +// router.get('/initium/:type?/:language?', lazyloadRouteHandler('./routes/initium/full')); +// router.get('/theinitium/:model/:type?/:language?', lazyloadRouteHandler('./routes/initium/full')); // Grub Street router.get('/grubstreet', lazyloadRouteHandler('./routes/grubstreet/index')); diff --git a/lib/routes/initium/full.js b/lib/routes/initium/full.js deleted file mode 100644 index 4a12ccd236..0000000000 --- a/lib/routes/initium/full.js +++ /dev/null @@ -1,188 +0,0 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const cheerio = require('cheerio'); -const resolve_url = require('url').resolve; -const timezone = require('@/utils/timezone'); - -module.exports = async (ctx) => { - // model是channel/tag/etc.,而type是latest/feature/quest-academy这些一级栏目/标签/作者名的slug名。如果是追踪的话,那就是model是follow,type是articles。 - 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 'follow': - listurl = `https://api.theinitium.com/api/v2/user/follows/${type}/?language=${language}`; - 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, - password: config.initium.password, - iapReceipt: config.initium.iap_receipt, - }; - const body = JSON.stringify(key); - - let token; - const cache = await ctx.cache.get('INITIUM_TOKEN'); - if (cache) { - token = cache; - } else if (config.initium.bearertoken) { - token = config.initium.bearertoken; - ctx.cache.set('INITIUM_TOKEN', config.initium.bearertoken); - } else if (key.email === undefined) { - token = 'Basic YW5vbnltb3VzOkdpQ2VMRWp4bnFCY1ZwbnA2Y0xzVXZKaWV2dlJRY0FYTHY='; - } else { - const login = await got({ - method: 'post', - url: `https://api.theinitium.com/api/v2/auth/login/?language=${language}`, - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - Connection: 'keep-alive', - Authorization: 'Basic YW5vbnltb3VzOkdpQ2VMRWp4bnFCY1ZwbnA2Y0xzVXZKaWV2dlJRY0FYTHY=', - Origin: `https://theinitium.com/`, - Referer: `https://theinitium.com/`, - 'X-Client-Name': 'Web', - }, - body, - }); - - /* - const devices = login.data.access.devices; - - for (const key in devices) { - const device = devices[key]; - if (device.status === 'logged_in' && !device.logout_at && device.platform === 'web') { - token = 'Bearer ' + device.device_id; - break; - } - } - */ - token = 'Bearer ' + login.data.token; - ctx.cache.set('INITIUM_TOKEN', token); - } - - const headers = { - Accept: '*/*', - Connection: 'keep-alive', - Authorization: token, - 'X-IAP-Receipt': key.iapReceipt || '', - }; - - const response = await got({ - method: 'get', - url: listurl, - headers, - }); - - const name = response.data.name || (response.data[model] && response.data[model].name) || '追踪'; - // 从v1直升的channel和tags里面是digests,v2新增的author和follow出来都是results - const articles = response.data.results ? response.data.results : response.data.digests; - // 如果model=author,那就是avatar;否则都是cover,要么就没封面 - const image = response.data[model] && (response.data[model].cover || response.data[model].avatar); - - const getFullText = async (slug) => { - let content = await ctx.cache.get(slug + language); - if (content) { - return content; - } - - content = ''; - - const response = await got({ - method: 'get', - url: `https://api.theinitium.com/api/v2/article/detail/?language=${language}&slug=${slug}`, - headers, - }); - - const data = response.data; - - if (data.lead.length) { - content += '

「' + data.lead + '」

'; - } - if (data.byline.length) { - content += '

' + data.byline + '

'; - } - if (data.content) { - content += data.content.replace('