Files
RSSHub/lib/routes/sega/pjsekai.ts
T
Tony d585a87daf fix: allow multiple radar rules per route (#14800)
* fix: allow multiple radar rules per route

* fix: github folder

* feat: add namespace to radar target

* docs: fix types url
2024-03-16 03:28:44 +08:00

76 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Route } from '@/types';
import got from '@/utils/got';
import * as cheerio from 'cheerio';
import timezone from '@/utils/timezone';
import cache from '@/utils/cache';
export const route: Route = {
path: '/pjsekai/news',
categories: ['game'],
example: '/sega/pjsekai/news',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['pjsekai.sega.jp/news/index.html'],
},
],
name: '世界计划 多彩舞台 | ProjectSekai | プロセカ',
maintainers: ['15x15G'],
handler,
url: 'pjsekai.sega.jp/news/index.html',
};
async function handler() {
// 从仓库 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 cache.tryGet(guid, async () => {
const result = await got.get(`https://production-web.sekai.colorfulpalette.org/html/${path}.html`);
const $ = cheerio.load(result.data);
return $.html();
});
} catch {
description = link;
}
} else {
// 外链
link = post.path;
description = post.title;
}
const item = {
title: post.title,
link,
pubDate: timezone(new Date(post.startAt), +8), // +8时区
description,
category: post.informationTag, // event,gacha,music,bug,information
guid,
};
return item;
})
);
return {
title: 'Project Sekai - News',
link: 'https://pjsekai.sega.jp/',
description: 'プロジェクトセカイ カラフルステージ! feat.初音ミク',
item: list,
};
}