feat: add new route for ctfhub (#6252)

This commit is contained in:
Frank 2020-11-30 19:13:54 +08:00 committed by GitHub
parent ad1f282846
commit 49e49af462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 5 deletions

View File

@ -41,9 +41,9 @@ pageClass: routes
### 查询国内外 CTF 赛事信息
<Route author="frankli0324" example="/ctfhub/calendar"
path="/ctfhub/calendar/:limit?/:form?/:class?/:title?"
:paramsDesc="['通过CTF赛事名称过滤', '一个整数筛选最近的limit场比赛', '比赛形式', '比赛类型']">
<Route author="frankli0324" example="/ctfhub/search"
path="/ctfhub/search/:limit?/:form?/:class?/:title?"
:paramsDesc="['一个整数筛选最新的limit场比赛默认为10', '比赛形式', '比赛类型', '通过CTF赛事名称过滤']">
| `:class` | 类型 |
| :------: | -------------------------------- |
@ -63,6 +63,14 @@ pageClass: routes
</Route>
### 查询近期赛事
<Route author="frankli0324" example="/ctfhub/upcoming"
path="/ctfhub/upcoming/:limit?"
:paramsDesc="['一个整数筛选最近的limit场比赛默认为5']">
</Route>
## gradCafe
### gradCafe result

View File

@ -2011,7 +2011,8 @@ router.get('/dlmu/grs/zsgz/:type', require('./routes/universities/dlmu/grs/zsgz'
router.get('/socialclub/events/:game?', require('./routes/socialclub/events'));
// CTFHub Event Calendar
router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ctfhub'));
router.get('/ctfhub/upcoming/:limit?', require('./routes/ctfhub/upcoming'));
router.get('/ctfhub/search/:limit?/:form?/:class?/:title?', require('./routes/ctfhub/search'));
// 阿里云
router.get('/aliyun/database_month', require('./routes/aliyun/database_month'));

View File

@ -53,7 +53,7 @@ module.exports = async (ctx) => {
return {
title: item.title,
description: '',
pubDate: item.start_time,
pubDate: new Date(item.start_time * 1000).toUTCString(),
link: item.official_url,
};
}),

View File

@ -0,0 +1,58 @@
const got = require('@/utils/got');
const md5 = require('@/utils/md5');
const host = 'https://api.ctfhub.com';
async function get_details(event_id) {
const res = await got
.post(`${host}/User_API/Event/getInfo`, {
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ event_id: event_id }),
})
.json();
if (res.status !== true) {
return '';
}
return res.data;
}
module.exports = async (ctx) => {
const opt = {
offset: 0,
limit: Number.parseInt(ctx.params.limit) || 5,
};
const response = await got
.post(`${host}/User_API/Event/getUpcoming`, {
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(opt),
})
.json();
if (response.status !== true) {
return;
}
const items = await Promise.all(
response.data.items.map(async (item) => {
const det = await get_details(item.id);
return {
title: item.title,
description: det.details,
pubDate: new Date(item.start_time * 1000).toUTCString(),
link: det.official_url,
guid: md5(item.title + item.start_time),
};
})
);
ctx.state.data = {
title: 'CTFHub Calendar',
link: 'https://www.ctfhub.com/#/calendar',
description: '提供全网最全最新的 CTF 赛事信息,关注赛事定制自己专属的比赛日历吧。',
item: items,
};
};