feat: add CTFHub 日历 (#4255)

This commit is contained in:
Frank
2020-03-17 12:06:31 +08:00
committed by GitHub
parent 0e7b02bf42
commit ca3b74625c
3 changed files with 90 additions and 0 deletions

View File

@@ -4,6 +4,32 @@ pageClass: routes
# 学习 # 学习
## CTFHub Calendar
### 查询国内外 CTF 赛事信息
<Route author="frankli0324" example="/ctfhub/calendar"
path="/ctfhub/calendar/:limit?/:form?/:class?/:title?"
:paramsDesc="['通过CTF赛事名称过滤', '一个整数筛选最近的limit场比赛', '比赛形式', '比赛类型']">
| `:class` | 类型 |
| :------: | -------------------------------- |
| 0 | Jeopardy[解题] |
| 1 | Attack with Defense[AwD 攻防] |
| 2 | Robo Hacking Game[RHG AI 自动化] |
| 3 | Real World[RW 真实世界] |
| 4 | King of The Hill[KoH 抢占山头] |
| 5 | Mix[混合] |
> class 以 https://api.ctfhub.com/User_API/Event/getType 的返回结果为准
| `:form` | 形式 |
| :-----: | ------ |
| 0 | 线上赛 |
| 1 | 线下赛 |
</Route>
## gradCafe ## gradCafe
### gradCafe result ### gradCafe result

View File

@@ -2380,6 +2380,9 @@ router.get('/moxingfans', require('./routes/moxingfans'));
// Chiphell // Chiphell
router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum')); router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum'));
// CTFHub Event Calendar
router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ctfhub'));
// 模型网 // 模型网
router.get('/moxingnet', require('./routes/moxingnet')); router.get('/moxingnet', require('./routes/moxingnet'));

View File

@@ -0,0 +1,61 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const host = 'https://api.ctfhub.com';
const opt = { like: {} };
for (const i of ['title', 'form', 'class']) {
if (ctx.params[i] !== undefined) {
opt.like[i] = ctx.params[i];
}
}
if (opt.like.class !== undefined) {
const types = await got
.post(`${host}/User_API/Event/getType`, {
headers: {
'content-type': 'application/json',
},
body: '{}',
})
.json();
opt.like.class = types.data[opt.like.class];
}
if (opt.like.form !== undefined) {
opt.like.form = ['线上', '线下'][Number.parseInt(opt.like.form)];
}
if (Object.keys(opt.like).length === 0) {
delete opt.like;
}
opt.offset = 0;
opt.limit = Number.parseInt(ctx.params.limit) || 10;
const response = await got
.post(`${host}/User_API/Event/getAll`, {
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(opt),
})
.json();
if (response.status !== true) {
return;
}
const data = response.data;
ctx.state.data = {
title: 'CTFHub Calendar',
link: 'https://www.ctfhub.com/#/calendar',
description: '提供全网最全最新的 CTF 赛事信息,关注赛事定制自己专属的比赛日历吧。',
item: data.items.map(function(item) {
return {
title: item.title,
description: '',
pubDate: item.start_time,
link: item.official_url,
};
}),
};
};