From b101ba975545ef8a2e897ec832d00a1afd94a1b1 Mon Sep 17 00:00:00 2001 From: 15x15 <65473527+15x15G@users.noreply.github.com> Date: Sat, 17 Jul 2021 17:40:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=96=E7=95=8C?= =?UTF-8?q?=E8=AE=A1=E5=88=92(pjsk)=20(#7878)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/en/game.md | 6 +++++ docs/game.md | 6 +++++ lib/router.js | 3 +++ lib/routes/pjsk/news.js | 49 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 lib/routes/pjsk/news.js diff --git a/docs/en/game.md b/docs/en/game.md index f2fd36bbe..e5f4d3156 100755 --- a/docs/en/game.md +++ b/docs/en/game.md @@ -187,3 +187,9 @@ Steam provides some official RSS feeds: ### Discussions + +## ProjectSekai | プロセカ + +### News + + diff --git a/docs/game.md b/docs/game.md index 729e61317..e6b1006bf 100644 --- a/docs/game.md +++ b/docs/game.md @@ -712,3 +712,9 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` ### 游戏横幅 + +## 世界计划 多彩舞台 | ProjectSekai | プロセカ + +### 公告 + + diff --git a/lib/router.js b/lib/router.js index fcc8d60b6..ad4925389 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4139,6 +4139,9 @@ router.get('/caus/:category?', require('./routes/caus')); // 摩点 router.get('/modian/zhongchou/:category?/:sort?/:status?', require('./routes/modian/zhongchou')); +// 世界计划 多彩舞台 feat.初音未来 (ProjectSekai) +router.get('/pjsk/news', require('./routes/pjsk/news')); + // 人民论坛网 router.get('/rmlt/idea/:category?', require('./routes/rmlt/idea')); diff --git a/lib/routes/pjsk/news.js b/lib/routes/pjsk/news.js new file mode 100644 index 000000000..8861ced20 --- /dev/null +++ b/lib/routes/pjsk/news.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +module.exports = async (ctx) => { + // 从仓库 Sekai-World/sekai-master-db-diff 获取最新公告 + const response = await got.get(`https://cdn.jsdelivr.net/gh/Sekai-World/sekai-master-db-diff@master/userInformations.json`); + const posts = response.data || []; + const list = await Promise.all( + posts.map(async (post) => { + let link = ''; + let description = ''; + const guid = post.displayOrder.toString() + post.id.toString(); // 双ID + if (post.path.startsWith('information/')) { + // information 公告 + const path = post.path.replace(/information\/index.html\?id=/, ''); + link = `https://production-web.sekai.colorfulpalette.org/${post.path}`; + try { + description = await ctx.cache.tryGet(guid, async () => { + const result = await got.get(`https://production-web.sekai.colorfulpalette.org/html/${path}.html`); + const $ = cheerio.load(result.data); + return $('body').html(); + }); + } catch { + description = link; + } + } else { + // 外链 + link = post.path; + description = post.title; + } + + const item = { + title: post.title, + link: link, + pubDate: timezone(new Date(post.startAt), +8), // +8时区 + description: description, + category: post.informationTag, // event,gacha,music,bug,information + guid: guid, + }; + return Promise.resolve(item); + }) + ); + ctx.state.data = { + title: 'Project Sekai - News', + link: 'https://pjsekai.sega.jp/', + description: 'プロジェクトセカイ カラフルステージ! feat.初音ミク', + item: list, + }; +};