rsshub
Version:
Make RSS Great Again!
51 lines (50 loc) • 1.66 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as md5 } from "./md5-CpIHIxCO.mjs";
//#region lib/routes/ctfhub/upcoming.ts
const route = {
path: "/upcoming/:limit?",
categories: ["study"],
example: "/ctfhub/upcoming",
parameters: { limit: "一个整数,筛选最近的 limit 场比赛,默认为 5" },
name: "查询近期赛事",
maintainers: ["frankli0324"],
handler
};
const host = "https://api.ctfhub.com";
async function getDetails(eventId) {
const res = await rofetch(`${host}/User_API/Event/getInfo`, {
method: "POST",
body: { event_id: eventId }
});
return res.status === true ? res.data : "";
}
async function handler(ctx) {
const { limit = "5" } = ctx.req.param();
const response = await rofetch(`${host}/User_API/Event/getUpcoming`, {
method: "POST",
body: {
offset: 0,
limit: Number.parseInt(limit)
}
});
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: await Promise.all(response.data.items.map((item) => cache_default.tryGet(`ctfhub:event:${item.id}`, async () => {
const det = await getDetails(item.id);
return {
title: item.title,
description: det.details,
pubDate: parseDate(item.start_time * 1e3),
link: det.official_url,
guid: md5(item.title + item.start_time)
};
})))
};
}
//#endregion
export { route };