Support exporting calendar events

Also update Deno and libraries
This commit is contained in:
Bruno Bernardino
2024-03-25 15:50:15 +00:00
parent 5b3217cdfc
commit a788456751
10 changed files with 98 additions and 47 deletions

View File

@@ -118,7 +118,7 @@ export const handler: Handler<Data, FreshContextState> = async (request, context
const calendarEvents = await getCalendarEvents(context.state.user.id, [calendar.id]);
if (request.method === 'GET') {
const response = new Response(formatCalendarEventsToVCalendar(calendarEvents, calendar), {
const response = new Response(formatCalendarEventsToVCalendar(calendarEvents, [calendar]), {
status: 200,
});
@@ -172,7 +172,7 @@ export const handler: Handler<Data, FreshContextState> = async (request, context
if (includeVCalendar) {
parsedCalendarEvent['d:propstat'][0]['d:prop']['cal:calendar-data'] = escapeXml(
formatCalendarEventsToVCalendar([calendarEvent], calendar!),
formatCalendarEventsToVCalendar([calendarEvent], [calendar!]),
);
}

View File

@@ -10,7 +10,7 @@ import {
formatCalendarEventsToVCalendar,
parseVCalendarFromTextContents,
} from '/lib/utils.ts';
import { getCalendar, getCalendarEvent, getCalendarEvents } from '/lib/data/calendar.ts';
import { getCalendar, getCalendarEvent, getCalendarEvents, updateCalendarEvent } from '/lib/data/calendar.ts';
import { createSessionCookie } from '/lib/auth.ts';
interface Data {}
@@ -157,7 +157,15 @@ export const handler: Handler<Data, FreshContextState> = async (request, context
// }
if (request.method === 'GET') {
const response = new Response(formatCalendarEventsToVCalendar([calendarEvent], calendar), {
// Set a UID if there isn't one
if (!calendarEvent.extra.uid) {
calendarEvent.extra.uid = crypto.randomUUID();
await updateCalendarEvent(calendarEvent);
calendarEvent = await getCalendarEvent(calendarEventId, context.state.user.id);
}
const response = new Response(formatCalendarEventsToVCalendar([calendarEvent], [calendar]), {
status: 200,
});
@@ -195,7 +203,7 @@ export const handler: Handler<Data, FreshContextState> = async (request, context
if (includeVCalendar) {
parsedCalendarEvent['d:propstat'][0]['d:prop']['cal:calendar-data'] = escapeXml(
formatCalendarEventsToVCalendar([calendarEvent], calendar!),
formatCalendarEventsToVCalendar([calendarEvent], [calendar!]),
);
}