fix(route): fix priconne-redive and remove deprecated route (#14893)

* fix(route): fix priconne-redive and remove deprecated route

* remove entries in router.js
This commit is contained in:
frankcwl
2024-03-21 23:32:31 +08:00
committed by GitHub
parent 7d1448bd00
commit fe79896615
4 changed files with 17 additions and 108 deletions
-5
View File
@@ -992,11 +992,6 @@ router.get('/ddrk/index', lazyloadRouteHandler('./routes/ddrk/list'));
router.get('/avgle/videos/:order?/:time?/:top?', lazyloadRouteHandler('./routes/avgle/videos.js'));
router.get('/avgle/search/:keyword/:order?/:time?/:top?', lazyloadRouteHandler('./routes/avgle/videos.js'));
// 公主链接公告
// router.get('/pcr/news', lazyloadRouteHandler('./routes/pcr/news'));
router.get('/pcr/news-tw', lazyloadRouteHandler('./routes/pcr/news-tw'));
router.get('/pcr/news-cn', lazyloadRouteHandler('./routes/pcr/news-cn'));
// project-zero issues
router.get('/project-zero-issues', lazyloadRouteHandler('./routes/project-zero-issues/index'));
-28
View File
@@ -1,28 +0,0 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: `https://api.biligame.com/news/list?gameExtensionId=267&positionId=2&typeId=&pageNum=1&pageSize=5`,
});
const data = response.data;
ctx.state.data = {
title: '公主链接国服-最新公告',
link: 'https://game.bilibili.com/pcr/news.html',
item: data
? await Promise.all(
data.data.map(async (item) => ({
title: item.title,
description: await ctx.cache.tryGet(`pcrcn_${item.id}`, async () => {
const resp = await got({ method: 'get', url: `https://api.biligame.com/news/${item.id}` });
return resp.data.data.content;
}),
link: `https://game.bilibili.com/pcr/news.html#detail=${item.id}`,
pubDate: item.ctime ?? item.createTime,
}))
)
: {
title: '获取失败!',
},
};
};
-67
View File
@@ -1,67 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const base = 'http://www.princessconnect.so-net.tw';
module.exports = async (ctx) => {
const url = `${base}/news`;
const list_response = await got.get(url);
const $ = cheerio.load(list_response.data);
const list = $('.news_con dl dd').get();
const parseContent = (htmlString) => {
const $ = cheerio.load(htmlString);
$('.news_con h2 > span').remove();
const time = $('.news_con h2').text().trim();
$('.news_con section h4').first().remove();
const content = $('.news_con section');
return {
description: content.html(),
pubDate: new Date(time),
};
};
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const title = $('a');
const path = title.attr('href');
const link = base + path;
const cache = await ctx.cache.get(link);
if (cache) {
return JSON.parse(cache);
}
const rssitem = {
title: title.text().trim(),
link,
};
try {
const response = await got.get(link);
const result = parseContent(response.data);
rssitem.author = '《超異域公主連結☆Re:Dive》營運團隊';
rssitem.description = result.description;
rssitem.pubDate = result.pubDate;
} catch {
return '';
}
ctx.cache.set(link, JSON.stringify(rssitem));
return rssitem;
})
);
ctx.state.data = {
title: '公主连结 - 台服公告',
link: url,
item: out.filter((item) => item !== ''),
};
};
+17 -8
View File
@@ -5,10 +5,10 @@ import cache from '@/utils/cache';
import { load } from 'cheerio';
export const route: Route = {
path: '/news/:location?',
path: '/news/:server?',
categories: ['game'],
example: '/priconne-redive/news',
parameters: { location: '区域,默认日服' },
parameters: { server: '服务器,默认日服' },
features: {
requireConfig: false,
requirePuppeteer: false,
@@ -20,23 +20,32 @@ export const route: Route = {
radar: [
{
source: ['priconne-redive.jp/news'],
target: '/news/jp',
},
{
source: ['princessconnect.so-net.tw/news'],
target: '/news/zh-tw',
},
{
source: ['game.bilibili.com/pcr/news.html'],
target: '/news/zh-cn',
},
],
name: '最新公告',
maintainers: ['SayaSS', 'frankcwl'],
handler,
url: 'priconne-redive.jp/news',
description: `location
description: `服务器
| 国服 | 台服 | 日服 |
| ----- | ----- | ---- |
| zh-cn | zh-tw | jp |`,
| 国服 | 台服 | 日服 |
| ----- | ----- | ---- |
| zh-cn | zh-tw | jp |`,
};
async function handler(ctx) {
const { location = 'jp' } = ctx.req.param();
const { server = 'jp' } = ctx.req.param();
switch (location) {
switch (server) {
case 'jp': {
const parseContent = (htmlString) => {
const $ = load(htmlString);