feat(route): add 世界计划(pjsk) (#7878)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
15x15 2021-07-17 17:40:52 +08:00 committed by GitHub
parent 0889aeeff7
commit b101ba9755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -187,3 +187,9 @@ Steam provides some official RSS feeds:
### Discussions
<RouteEn author="whtsky" example="/steamgifts/discussions" path="/steamgifts/discussions/:category?" :paramsDesc="['category name, default to All']"/>
## ProjectSekai プロセカ
### News
<Route author="15x15G" example="/pjsk/news" path="/pjsk/news"/>

View File

@ -712,3 +712,9 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
### 游戏横幅
<Route author="y2361547758" example="/magireco/event_banner" path="/magireco/event_banner"/>
## 世界计划 多彩舞台 ProjectSekai プロセカ
### 公告
<Route author="15x15G" example="/pjsk/news" path="/pjsk/news"/>

View File

@ -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'));

49
lib/routes/pjsk/news.js Normal file
View File

@ -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,
};
};