refactor(routes): hdu/auto use user input (#18051)

* refactor(routes): hdu/auto use user input

* Update lib/routes/hdu/auto/notice.ts
This commit is contained in:
Jalen
2025-01-07 10:52:49 +08:00
committed by GitHub
parent c405ee80ee
commit acca6842a9
4 changed files with 47 additions and 87 deletions
-27
View File
@@ -1,27 +0,0 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';
export const route: Route = {
path: '/auto/graduate',
categories: ['university'],
example: '/hdu/auto/graduate',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 研究生教育通知',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3754/list.htm', '研究生教育'),
description: '杭州电子科技大学自动化学院研究生教育',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3754/list.htm'],
target: '/auto/graduate',
},
],
};
+47 -6
View File
@@ -1,11 +1,31 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';
import logger from '@/utils/logger';
const typeMap = {
notice: {
name: '通知公告',
path: '3779/list.htm',
},
graduate: {
name: '研究生教育',
path: '3754/list.htm',
},
undergraduate: {
name: '本科教学',
path: '3745/list.htm',
},
student: {
name: '学生工作',
path: '3726/list.htm',
},
};
export const route: Route = {
path: '/auto',
path: '/auto/:type?',
categories: ['university'],
example: '/hdu/auto',
parameters: {},
parameters: { type: '分类,见下表,默认为通知公告' },
features: {
requireConfig: false,
requirePuppeteer: false,
@@ -14,14 +34,35 @@ export const route: Route = {
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 通知公告',
name: '自动化学院',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3779/list.htm', '通知公告'),
description: '杭州电子科技大学自动化学院通知公告',
handler: (ctx) => {
let type = ctx.req.param('type') || 'notice';
if (!(type in typeMap)) {
logger.error(`Invalid type: ${type}. Valid types are: ${Object.keys(typeMap).join(', ')}, defaulting to notice`);
type = 'notice';
}
return fetchAutoNews(typeMap[type].path, typeMap[type].name);
},
description: `| 通知公告 | 研究生教育 | 本科教学 | 学生工作 |
| -------- | -------- | -------- | -------- |
| notice | graduate | undergraduate | student |`,
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3779/list.htm'],
target: '/auto',
target: '/auto/notice',
},
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3754/list.htm'],
target: '/auto/graduate',
},
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3745/list.htm'],
target: '/auto/undergraduate',
},
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3726/list.htm'],
target: '/auto/student',
},
],
};
-27
View File
@@ -1,27 +0,0 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';
export const route: Route = {
path: '/auto/student',
categories: ['university'],
example: '/hdu/auto/student',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 学生工作',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3726/list.htm', '学生工作'),
description: '杭州电子科技大学自动化学院学生工作',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3726/list.htm'],
target: '/auto/student',
},
],
};
-27
View File
@@ -1,27 +0,0 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';
export const route: Route = {
path: '/auto/undergraduate',
categories: ['university'],
example: '/hdu/auto/undergraduate',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 本科教学',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3745/list.htm', '本科教学'),
description: '杭州电子科技大学自动化学院本科教学',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3745/list.htm'],
target: '/auto/undergraduate',
},
],
};