Skip to content

Commit

Permalink
Merge pull request #385 from Minei3oat/improve-calendar
Browse files Browse the repository at this point in the history
Improve iCal endpoint
  • Loading branch information
JJ-8 authored Dec 16, 2024
2 parents f08867c + b597556 commit 559d33e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/src/routes/ical.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ICalCalendar } from "ical-generator";
import { Request, Response, Handler } from "express";
import { Pool } from "pg";
import config from "../config";

type CtfRow = {
id: number;
title: string;
start_time: string;
end_time: string;
ctf_url: string;
ctftime_url: string;
description: string;
};

Expand All @@ -30,7 +32,7 @@ export function icalRoute(pool: Pool): Handler {

async function getCtfs(): Promise<CtfRow[]> {
const r = await pool.query<CtfRow>(
"SELECT id, title, start_time, end_time, ctf_url, description FROM ctfnote.ctf"
"SELECT id, title, start_time, end_time, ctf_url, ctftime_url, description FROM ctfnote.ctf"
);

return r.rows;
Expand All @@ -52,12 +54,15 @@ export function icalRoute(pool: Pool): Handler {
const ctfs = await getCtfs();

for (const ctf of ctfs) {
const ctftime_id = ctf.ctftime_url?.replace(/\/$/, "").split("/").at(-1);
cal.createEvent({
id: `${ctf.id}:${ctftime_id || "no-ctftime"}@${config.pad.domain || "ctfnote"}`,
start: ctf.start_time,
end: ctf.end_time,
description: ctf.description,
summary: ctf.title,
url: ctf.ctf_url,
attachments: ctf.ctftime_url ? [ctf.ctftime_url] : [],
});
}

Expand Down

0 comments on commit 559d33e

Please sign in to comment.