From ca3b74625c5d7511018c283c9c75c1fea5fb137c Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 17 Mar 2020 12:06:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20CTFHub=20=E6=97=A5=E5=8E=86=20(#4?= =?UTF-8?q?255)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 26 ++++++++++++++++ lib/router.js | 3 ++ lib/routes/ctfhub/index.js | 61 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 lib/routes/ctfhub/index.js diff --git a/docs/study.md b/docs/study.md index bc567524c0..afaa9d86b9 100644 --- a/docs/study.md +++ b/docs/study.md @@ -4,6 +4,32 @@ pageClass: routes # 学习 +## CTFHub Calendar + +### 查询国内外 CTF 赛事信息 + + + +| `: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 | 线下赛 | + + + ## gradCafe ### gradCafe result diff --git a/lib/router.js b/lib/router.js index 8f82810a1a..f397f1134e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2380,6 +2380,9 @@ router.get('/moxingfans', require('./routes/moxingfans')); // Chiphell 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')); diff --git a/lib/routes/ctfhub/index.js b/lib/routes/ctfhub/index.js new file mode 100644 index 0000000000..2c451504cf --- /dev/null +++ b/lib/routes/ctfhub/index.js @@ -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, + }; + }), + }; +};