diff --git a/docs/study.md b/docs/study.md index 39dcd687f..983b2d4db 100644 --- a/docs/study.md +++ b/docs/study.md @@ -41,9 +41,9 @@ pageClass: routes ### 查询国内外 CTF 赛事信息 - + | `:class` | 类型 | | :------: | -------------------------------- | @@ -63,6 +63,14 @@ pageClass: routes +### 查询近期赛事 + + + + + ## gradCafe ### gradCafe result diff --git a/lib/router.js b/lib/router.js index ecff73f44..d5a18aa9d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/ctfhub/index.js b/lib/routes/ctfhub/search.js similarity index 95% rename from lib/routes/ctfhub/index.js rename to lib/routes/ctfhub/search.js index 27219aa80..585b8927e 100644 --- a/lib/routes/ctfhub/index.js +++ b/lib/routes/ctfhub/search.js @@ -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, }; }), diff --git a/lib/routes/ctfhub/upcoming.js b/lib/routes/ctfhub/upcoming.js new file mode 100644 index 000000000..6e30e2448 --- /dev/null +++ b/lib/routes/ctfhub/upcoming.js @@ -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, + }; +};