From 3938bce863bbe3126c8aae54761a656efb3c7972 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Thu, 18 Jul 2024 04:55:17 -0500 Subject: [PATCH] fix: conditional XML or ICS response --- routes/calendar/calendar/get.js | 52 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/routes/calendar/calendar/get.js b/routes/calendar/calendar/get.js index 54b8657..c9acb8b 100644 --- a/routes/calendar/calendar/get.js +++ b/routes/calendar/calendar/get.js @@ -14,19 +14,18 @@ module.exports = function (options) { fullData: true }); - if (ctx.accepts('xml')) { - const ics = await options.data.buildICS(ctx, events, calendar); - return response(ctx.url, status[200], [ - { - 'D:getetag': options.data.getETag(ctx, calendar) - }, - { - 'CAL:calendar-data': ics - } - ]); - } + if (ctx.accepts('text/calendar')) + return options.data.buildICS(ctx, events, calendar); - return options.data.buildICS(ctx, events, calendar); + const ics = await options.data.buildICS(ctx, events, calendar); + return response(ctx.url, status[200], [ + { + 'D:getetag': options.data.getETag(ctx, calendar) + }, + { + 'CAL:calendar-data': ics + } + ]); } const event = await options.data.getEvent(ctx, { @@ -42,21 +41,20 @@ module.exports = function (options) { return; } - if (ctx.accepts('xml')) { - const ics = await options.data.buildICS(ctx, event, calendar); - return response(ctx.url, status[200], [ - { - // TODO: should E-Tag here be of calendar or event? - // 'D:getetag': options.data.getETag(ctx, calendar) - 'D:getetag': options.data.getETag(ctx, calendar) - }, - { - 'CAL:calendar-data': ics - } - ]); - } - - return options.data.buildICS(ctx, event, calendar); + if (ctx.accepts('text/calendar')) + return options.data.buildICS(ctx, event, calendar); + + const ics = await options.data.buildICS(ctx, event, calendar); + return response(ctx.url, status[200], [ + { + // TODO: should E-Tag here be of calendar or event? + // 'D:getetag': options.data.getETag(ctx, calendar) + 'D:getetag': options.data.getETag(ctx, calendar) + }, + { + 'CAL:calendar-data': ics + } + ]); }; return {