From 33aec8da9414bc26e32886eddd96ed786265af23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E8=B4=A7?= <1365143958@qq.com> Date: Wed, 28 Sep 2022 05:52:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=AE=A2=E8=8E=B7=E5=8F=96=E5=85=A8=E6=96=87=20(#10921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 增加安全客获取全文 * fix: 不需要控制台输出 * fix: const single * fix: 不分状态获取全文 现在仅在添加了 `fulltext` 或 `quanwen` 时才获取全文 * docs: 添加安全客获取全文参数说明 * docs: 删除重复的内容 --- docs/programming.md | 2 +- lib/v2/anquanke/category.js | 24 ++++++++++++++++++------ lib/v2/anquanke/maintainer.js | 2 +- lib/v2/anquanke/router.js | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/programming.md b/docs/programming.md index c510b5bc13..3bbe87dc03 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -720,7 +720,7 @@ GitHub 官方也提供了一些 RSS: ### 分类订阅 - + | 360 网络安全周报 | 活动 | 知识 | 资讯 | 招聘 | 工具 | | ---------- | -------- | --------- | ---- | --- | ---- | diff --git a/lib/v2/anquanke/category.js b/lib/v2/anquanke/category.js index cc4262e491..2dfbe6a091 100644 --- a/lib/v2/anquanke/category.js +++ b/lib/v2/anquanke/category.js @@ -1,20 +1,32 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { const api = 'https://api.anquanke.com/data/v1/posts?size=10&page=1&category='; const type = ctx.params.category; + const fulltext = ctx.params.fulltext; const host = 'https://www.anquanke.com'; const res = await got(`${api}${type}`); const dataArray = res.data.data; - const items = dataArray.map((item) => ({ - title: item.title, - description: item.desc, - pubDate: timezone(parseDate(item.date), +8), - link: `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`, - author: item.author.nickname, + const items = await Promise.all( + dataArray.map(async (item) => { + const art_url = `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`; + return { + title: item.title, + description: fulltext === 'fulltext' || fulltext === 'quanwen' + ? await ctx.cache.tryGet(art_url, async () => { + const { data: res } = await got(art_url); + const content = cheerio.load(res); + return content('#js-article').html(); + }) + : item.desc, + pubDate: timezone(parseDate(item.date), +8), + link: art_url, + author: item.author.nickname, + }; })); ctx.state.data = { diff --git a/lib/v2/anquanke/maintainer.js b/lib/v2/anquanke/maintainer.js index e247fa46d9..0dc8f87b54 100644 --- a/lib/v2/anquanke/maintainer.js +++ b/lib/v2/anquanke/maintainer.js @@ -1,4 +1,4 @@ module.exports = { // '/vul': ['qwertyuiop6'], - '/:category': ['qwertyuiop6'], + '/:category/:fulltext?': ['qwertyuiop6'], }; diff --git a/lib/v2/anquanke/router.js b/lib/v2/anquanke/router.js index 7cc1f079a5..08674bf4e3 100644 --- a/lib/v2/anquanke/router.js +++ b/lib/v2/anquanke/router.js @@ -1,4 +1,4 @@ module.exports = (router) => { // router.get('/vul', require('./vul')); // 404 - router.get('/:category', require('./category')); + router.get('/:category/:fulltext?', require('./category')); };