From 72c7cba9dcc23ccb3a8d3ec7011d4eddd5c9e6f9 Mon Sep 17 00:00:00 2001 From: Joschua Becker Date: Thu, 25 Apr 2024 17:07:45 +0200 Subject: [PATCH] fixed: ms-ics-fix --- src/ms-ics-fix/README.md | 18 ++++++++---------- src/ms-ics-fix/index.js | 15 +++------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/ms-ics-fix/README.md b/src/ms-ics-fix/README.md index d07e742..889b4d5 100644 --- a/src/ms-ics-fix/README.md +++ b/src/ms-ics-fix/README.md @@ -30,13 +30,14 @@ Key problem here is, that they are exporting ICS files, which are not RFC compli ```yml # ... -TZID:UTC # Server indicates its using UTC +TZID:UTC # Server indicates its using UTC +# ... +TZID:Central Europe Standard Time # Suddenly it indicates the correct timezone # ... BEGIN:VEVENT # ... -DTSTAMP:20240425T132325Z # Server using a local timezone -# ... and not using the UTC-OFFSET value -# ... as it should to indicate the timezone +DTSTAMP:20240101T130000Z # Server using UTC, tho it said it uses CEST +# ... END:VEVENT # ... ``` @@ -58,18 +59,17 @@ To fix this, this tool will work like an ICS proxy, which will fix the timezone |-----------------------------|---------|---------------|---------------------------------------------------------| | `ICS_ON_DEMAND` | boolean | `false` | Whether to enable the on demand mode. | | `ICS_{counter}_URL` | string | `null` | The URL of the ICS file to serve. | -| `ICS_{counter}_TZID` | string | `null` | The timezone of the ICS file. | | `ICS_{counter}_PATH` | string? | `null` | The path to serve the ICS file. | ## On Demand Mode -If `ICS_ON_DEMAND` is set to `true`, you can make a GET request to `/` with the query parameter `url` and `tzid`. +If `ICS_ON_DEMAND` is set to `true`, you can make a GET request to `/` with the query parameter `url`. ```http -/?url=https%3A%2F%2Fexample.com%2Fcalendar.ics&tzid=Europe%2FBerlin +/?url=https%3A%2F%2Fexample.com%2Fcalendar.ics ``` -This will return the ICS file from `https://example.com/calendar.ics` with the timezone `Europe/Berlin`. +This will return the ICS file from `https://example.com/calendar.ics`. **Don't forget to URL encode the query parameters.** @@ -84,10 +84,8 @@ services: - "3000:3000" environment: ICS_0_URL: "https://example.com/calendar1.ics" - ICS_0_TZID: "Europe/Berlin" ICS_0_PATH: "your-new-filename-which-will-be-served.ics" ICS_1_URL: "https://example.com/calendar2.ics" - ICS_1_TZID: "Europe/Berlin" # ... ``` diff --git a/src/ms-ics-fix/index.js b/src/ms-ics-fix/index.js index 898e333..af02742 100644 --- a/src/ms-ics-fix/index.js +++ b/src/ms-ics-fix/index.js @@ -13,7 +13,6 @@ let counter = 0 while (process.env[`ICS_${counter}_URL`]) { config.ics.push({ url: process.env[`ICS_${counter}_URL`], - tz: process.env[`ICS_${counter}_TZID`], path: process.env[`ICS_${counter}_PATH`], }) counter++ @@ -24,7 +23,7 @@ config.ics = (() => { const n = [] const s = new Set() for (const ics of config.ics) { - if (!ics.url || !ics.tz) continue // Skip invalid ICS + if (!ics.url) continue // Skip invalid ICS if (s.has(ics.path)) ics.path = null // Reset path if duplicated let c = -1 if (!ics.path) do { // Generate path if not provided @@ -38,17 +37,9 @@ config.ics = (() => { })(); // The little magic, microsoft is too lazy to implement... -async function doIcsFix(url, tz) { +async function doIcsFix(url) { const ics = await fetch(url).then(res => res.text()) - return ics.replace(/^TZID:.*$/gm, `TZID:UTC`).split('\n').map(line => { - // Translate DTSTART and DTEND from the specified timezone to UTC - if (!line.startsWith('DTSTART') && !line.startsWith('DTEND')) return line - const date = line.split(':')[1] - const dt = new Date(date) - const dtUTC = new Date(dt.toLocaleString('en-US', { timeZone: tz })) - return `${line.split(':')[0]}:${dtUTC.toISOString().replace(/[-:]/g, '').replace(/\.\d+/, '')}` - return line - }).join('\n') + return ics.replace(/^TZID:.*$/gm, `TZID:UTC`) } app.get('*', (req, res) => {