UNPKG

rsshub

Version:
67 lines (64 loc) 2.28 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; //#region lib/routes/ctfhub/search.ts const route = { path: "/search/:limit?/:form?/:class?/:title?", categories: ["study"], example: "/ctfhub/search", parameters: { limit: "一个整数,筛选最新的 limit 场比赛,默认为 10", form: "比赛形式", class: "比赛类型", title: "通过 CTF 赛事名称过滤" }, description: `| \`: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 | 线下赛 |`, name: "查询国内外 CTF 赛事信息", maintainers: ["frankli0324"], handler }; async function handler(ctx) { const host = "https://api.ctfhub.com"; const { limit = "10", form, class: className, title } = ctx.req.param(); const like = {}; if (title !== void 0) like.title = title; if (form !== void 0) like.form = ["线上", "线下"][Number.parseInt(form)]; if (className !== void 0) like.class = (await rofetch(`${host}/User_API/Event/getType`, { method: "POST", body: {} })).data[className]; const opt = { ...Object.keys(like).length > 0 && { like }, offset: 0, limit: Number.parseInt(limit) }; const response = await rofetch(`${host}/User_API/Event/getAll`, { method: "POST", body: opt }); if (response.status !== true) throw new Error("CTFHub API returned an error"); return { title: "CTFHub Calendar", link: "https://www.ctfhub.com/#/calendar", description: "提供全网最全最新的 CTF 赛事信息,关注赛事定制自己专属的比赛日历吧。", item: response.data.items.map((item) => ({ title: item.title, description: "", pubDate: parseDate(item.start_time * 1e3), link: item.official_url })) }; } //#endregion export { route };