From 9502b6613ff361c2b44488beceb9912db0a73967 Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Tue, 10 Dec 2024 01:01:20 +0100 Subject: [PATCH 1/6] Calendar: Use ctf id as persistent UID --- api/src/routes/ical.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index f14872c4c..42e3a9e29 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -53,6 +53,7 @@ export function icalRoute(pool: Pool): Handler { for (const ctf of ctfs) { cal.createEvent({ + id: ctf.id, start: ctf.start_time, end: ctf.end_time, description: ctf.description, From 7ca8c2d43a3d40c5dde7067c163a0df701d44f85 Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Tue, 10 Dec 2024 01:01:45 +0100 Subject: [PATCH 2/6] Calendar: Add ctftime_url as attachment --- api/src/routes/ical.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index 42e3a9e29..ed6c9d63f 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -8,6 +8,7 @@ type CtfRow = { start_time: string; end_time: string; ctf_url: string; + ctftime_url: string; description: string; }; @@ -30,7 +31,7 @@ export function icalRoute(pool: Pool): Handler { async function getCtfs(): Promise { const r = await pool.query( - "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; @@ -59,6 +60,7 @@ export function icalRoute(pool: Pool): Handler { description: ctf.description, summary: ctf.title, url: ctf.ctf_url, + attachments: [ctf.ctftime_url], }); } From 4e56a02b9a96a3bf0fc548811b7ef2428eaeed1d Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Tue, 10 Dec 2024 01:20:09 +0100 Subject: [PATCH 3/6] Calendar: Add pad domain to ensure global uniqueness --- api/src/routes/ical.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index ed6c9d63f..839381a9f 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -1,6 +1,7 @@ import { ICalCalendar } from "ical-generator"; import { Request, Response, Handler } from "express"; import { Pool } from "pg"; +import config from "../config"; type CtfRow = { id: number; @@ -54,7 +55,7 @@ export function icalRoute(pool: Pool): Handler { for (const ctf of ctfs) { cal.createEvent({ - id: ctf.id, + id: `${ctf.id}@${config.pad.domain}`, start: ctf.start_time, end: ctf.end_time, description: ctf.description, From 4d12bd926ff9725455d1fd72db026be38d3f0147 Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Thu, 12 Dec 2024 21:57:37 +0100 Subject: [PATCH 4/6] Calendar: Add ctftime event id and default for empty pad domain --- api/src/routes/ical.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index 839381a9f..85d042856 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -54,8 +54,9 @@ 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}@${config.pad.domain}`, + id: `${ctf.id}:${ctftime_id || "no-ctftime"}@${config.pad.domain || "ctfnote"}`, start: ctf.start_time, end: ctf.end_time, description: ctf.description, From 5e110fefe1b12196d88dac3e1ceb88fbe5b83c05 Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Sun, 15 Dec 2024 00:52:31 +0100 Subject: [PATCH 5/6] Calendar: Fix ATTACH:null on missing ctftime_url --- api/src/routes/ical.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index 85d042856..731c7fffe 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -62,7 +62,7 @@ export function icalRoute(pool: Pool): Handler { description: ctf.description, summary: ctf.title, url: ctf.ctf_url, - attachments: [ctf.ctftime_url], + attachments: ctf.ctftime_url ? [ctf.ctftime_url] : [], }); } From b59755664032339d9aa6d089d8e4af530fba9d31 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:09:13 +0100 Subject: [PATCH 6/6] Run prettier on ical.ts This removes a redundant space. --- api/src/routes/ical.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index 731c7fffe..429957add 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -56,7 +56,7 @@ export function icalRoute(pool: Pool): Handler { 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"}`, + id: `${ctf.id}:${ctftime_id || "no-ctftime"}@${config.pad.domain || "ctfnote"}`, start: ctf.start_time, end: ctf.end_time, description: ctf.description,