From f4e55c69e31a1de7886d450bc7ebe1b7dcec6cc6 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Thu, 18 Jul 2024 04:44:21 -0500 Subject: [PATCH] fix: conditional XML or ICS response --- routes/calendar/calendar/get.js | 50 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/routes/calendar/calendar/get.js b/routes/calendar/calendar/get.js index 7046e55..54b8657 100644 --- a/routes/calendar/calendar/get.js +++ b/routes/calendar/calendar/get.js @@ -14,16 +14,19 @@ module.exports = function (options) { fullData: true }); - // 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 - } - ]); + 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 + } + ]); + } + + return options.data.buildICS(ctx, events, calendar); } const event = await options.data.getEvent(ctx, { @@ -39,18 +42,21 @@ module.exports = function (options) { return; } - // 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 - } - ]); + 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); }; return {