From 362db670e098279e50f1ab566258ea513d868e88 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 5 Jun 2019 19:13:46 +0800 Subject: [PATCH] feat: add vgtime keyword, close #2328 --- docs/game.md | 8 +++++-- docs/joinus/README.md | 3 +++ lib/router.js | 1 + lib/routes/vgtime/keyword.js | 46 ++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/routes/vgtime/keyword.js diff --git a/docs/game.md b/docs/game.md index 0ae4318bda..fc265998d3 100644 --- a/docs/game.md +++ b/docs/game.md @@ -199,11 +199,15 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ### 游戏时光新闻 - + ### 游戏时光游戏发售表 - + + +### 关键词资讯 + + ## 游研社 diff --git a/docs/joinus/README.md b/docs/joinus/README.md index f189209918..955f1344f3 100644 --- a/docs/joinus/README.md +++ b/docs/joinus/README.md @@ -40,6 +40,9 @@ sidebar: auto const response = await got({ method: 'get', url: `https://api.bilibili.com/x/space/coin/video?vmid=${uid}&jsonp=jsonp`, + headers: { + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data.data; // response.data 为 HTTP GET 请求返回的数据对象 diff --git a/lib/router.js b/lib/router.js index 72dd1e5522..69d49ba669 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1144,6 +1144,7 @@ router.get('/tophub/:id', require('./routes/tophub')); // 游戏时光 router.get('/vgtime/news', require('./routes/vgtime/news.js')); router.get('/vgtime/release', require('./routes/vgtime/release')); +router.get('/vgtime/keyword/:keyword', require('./routes/vgtime/keyword')); // MP4吧 router.get('/mp4ba/:param', require('./routes/mp4ba')); diff --git a/lib/routes/vgtime/keyword.js b/lib/routes/vgtime/keyword.js new file mode 100644 index 0000000000..9458548059 --- /dev/null +++ b/lib/routes/vgtime/keyword.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { keyword = '' } = ctx.params; + const response = await got({ + method: 'get', + url: `http://www.vgtime.com/search/load.jhtml?keyword=${encodeURIComponent(keyword)}&type=topic&typeTag=2&page=1&pageSize=12`, + headers: { + Referer: `http://www.vgtime.com/search/list.jhtml?keyword=${encodeURIComponent(keyword)}`, + }, + }); + const data = response.data.data; + + const result = await Promise.all( + data.map(async (item) => { + const url = `https://www.vgtime.com/topic/${item.objectId}.jhtml`; + + const description = await ctx.cache.tryGet(url, async () => { + const result = await got.get(url); + + const $ = cheerio.load(result.data); + $('h1.art_tit').remove(); + $('.editor_name').remove(); + + return $('.vg_main article').html(); + }); + + const result = { + title: item.title, + author: JSON.parse(item.content).userName, + pubDate: new Date(item.createTime * 1000).toUTCString(), + link: url, + description, + }; + + return Promise.resolve(result); + }) + ); + + ctx.state.data = { + title: `游戏时光${keyword}资讯`, + link: `http://www.vgtime.com/search/list.jhtml?keyword=${encodeURIComponent(keyword)}`, + item: result, + }; +};