Skip to content

Commit 559d33e

Browse files
authored
Merge pull request TFNS#385 from Minei3oat/improve-calendar
Improve iCal endpoint
2 parents f08867c + b597556 commit 559d33e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

api/src/routes/ical.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { ICalCalendar } from "ical-generator";
22
import { Request, Response, Handler } from "express";
33
import { Pool } from "pg";
4+
import config from "../config";
45

56
type CtfRow = {
67
id: number;
78
title: string;
89
start_time: string;
910
end_time: string;
1011
ctf_url: string;
12+
ctftime_url: string;
1113
description: string;
1214
};
1315

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

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

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

5456
for (const ctf of ctfs) {
57+
const ctftime_id = ctf.ctftime_url?.replace(/\/$/, "").split("/").at(-1);
5558
cal.createEvent({
59+
id: `${ctf.id}:${ctftime_id || "no-ctftime"}@${config.pad.domain || "ctfnote"}`,
5660
start: ctf.start_time,
5761
end: ctf.end_time,
5862
description: ctf.description,
5963
summary: ctf.title,
6064
url: ctf.ctf_url,
65+
attachments: ctf.ctftime_url ? [ctf.ctftime_url] : [],
6166
});
6267
}
6368

0 commit comments

Comments
 (0)