From 3a697e27fb69fe32698acec29ebc92020a3a124c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:59:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20add=20=E5=B0=91=E5=A5=B3=E5=89=8D?= =?UTF-8?q?=E7=BA=BF=E6=83=85=E6=8A=A5=E5=B1=80=20(#8519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 2 +- lib/router.js | 2 +- lib/routes/gf-cn/news.js | 39 ----------------------------- lib/v2/gf-cn/maintainer.js | 3 +++ lib/v2/gf-cn/news.js | 50 ++++++++++++++++++++++++++++++++++++++ lib/v2/gf-cn/radar.js | 13 ++++++++++ lib/v2/gf-cn/router.js | 3 +++ 7 files changed, 71 insertions(+), 41 deletions(-) delete mode 100644 lib/routes/gf-cn/news.js create mode 100644 lib/v2/gf-cn/maintainer.js create mode 100644 lib/v2/gf-cn/news.js create mode 100644 lib/v2/gf-cn/radar.js create mode 100644 lib/v2/gf-cn/router.js diff --git a/docs/game.md b/docs/game.md index 0eb898ac27..bc1d0e988f 100644 --- a/docs/game.md +++ b/docs/game.md @@ -555,7 +555,7 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` ## 少女前线 -### 新闻 +### 情报局 diff --git a/lib/router.js b/lib/router.js index b97696251e..3fcb7973c5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4042,7 +4042,7 @@ router.get('/trakt/collection/:username/:type?', lazyloadRouteHandler('./routes/ router.get('/ccg/:category?', lazyloadRouteHandler('./routes/ccg/index')); // 少女前线 -router.get('/gf-cn/news/:category?', lazyloadRouteHandler('./routes/gf-cn/news')); +// router.get('/gf-cn/news/:category?', lazyloadRouteHandler('./routes/gf-cn/news')); // Eagle router.get('/eagle/changelog/:language?', lazyloadRouteHandler('./routes/eagle/changelog')); diff --git a/lib/routes/gf-cn/news.js b/lib/routes/gf-cn/news.js deleted file mode 100644 index fbe0f0732b..0000000000 --- a/lib/routes/gf-cn/news.js +++ /dev/null @@ -1,39 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const category = ctx.params.category || '1'; - - const rootUrl = 'https://gfcn-webserver.sunborngame.com'; - const currentUrl = `${rootUrl}/website/news_list/${category}?page=0&limit=11`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - - const list = response.data.data.list.map((item) => ({ - title: item.Title, - link: `${rootUrl}/website/news/${item.Id}`, - pubDate: new Date(item.Date).toUTCString(), - })); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - item.description = detailResponse.data.data.Content; - item.link = item.link.replace(`${rootUrl}/website/news/`, `${rootUrl}/NewsInfo?id=`); - - return item; - }) - ) - ); - - ctx.state.data = { - title: `少女前线 - ${category === '1' ? '新闻' : '公告'}`, - link: currentUrl, - item: items, - }; -}; diff --git a/lib/v2/gf-cn/maintainer.js b/lib/v2/gf-cn/maintainer.js new file mode 100644 index 0000000000..d4350891fd --- /dev/null +++ b/lib/v2/gf-cn/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category?': ['nczitzk'], +}; diff --git a/lib/v2/gf-cn/news.js b/lib/v2/gf-cn/news.js new file mode 100644 index 0000000000..a6e2d9722e --- /dev/null +++ b/lib/v2/gf-cn/news.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +const titles = { + 1: '新闻', + 3: '公告', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? '1'; + + const rootUrl = 'https://gf-cn.sunborngame.com'; + const apiRootUrl = 'https://gfcn-webserver.sunborngame.com'; + const apiUrl = `${apiRootUrl}/website/news_list/${category}?page=0&limit=${ctx.query.limit ?? 50}`; + const currentUrl = `${rootUrl}/News`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items = response.data.data.list.map((item) => ({ + guid: item.Id, + title: item.Title, + link: `${rootUrl}/NewsInfo?id=${item.Id}`, + pubDate: timezone(parseDate(item.Date), +8), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.guid, async () => { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/website/news/${item.guid}`, + }); + + item.description = detailResponse.data.data.Content.replace(/