Skip to content

Commit

Permalink
refactor(routes): hdu/auto use user input (DIYgod#18051)
Browse files Browse the repository at this point in the history
* refactor(routes): hdu/auto use user input

* Update lib/routes/hdu/auto/notice.ts
  • Loading branch information
jalenzz authored Jan 7, 2025
1 parent c405ee8 commit acca684
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 87 deletions.
27 changes: 0 additions & 27 deletions lib/routes/hdu/auto/graduate.ts

This file was deleted.

53 changes: 47 additions & 6 deletions lib/routes/hdu/auto/notice.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 changes: 0 additions & 27 deletions lib/routes/hdu/auto/student.ts

This file was deleted.

27 changes: 0 additions & 27 deletions lib/routes/hdu/auto/undergraduate.ts

This file was deleted.

0 comments on commit acca684

Please sign in to comment.