diff --git a/package.json b/package.json index 17dea701..56ec9422 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dependencies": { "@prisma/client": "5.22.0", "html-to-slack": "0.3.5", + "iamcal": "^2.1.2", "jest": "^29.7.0", "marked": "^14.1.3", "marked-base-url": "^1.1.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43f82ecf..7521cd98 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: html-to-slack: specifier: 0.3.5 version: 0.3.5 + iamcal: + specifier: ^2.1.2 + version: 2.1.2 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@20.11.16) @@ -1565,6 +1568,9 @@ packages: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} + iamcal@2.1.2: + resolution: {integrity: sha512-h5lqF0pYRpz8z+AZF+x3h8G49xl3uvQOxOSshF0PfFjP0DUrTgTCGQGjoA9+gKQi1kEZo8T8JbamSVcO9GH68A==} + ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} @@ -4254,7 +4260,7 @@ snapshots: debug: 4.3.7 enhanced-resolve: 5.17.1 eslint: 8.57.0 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0) fast-glob: 3.3.2 get-tsconfig: 4.8.0 is-bun-module: 1.1.0 @@ -4267,7 +4273,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0): + eslint-module-utils@2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0): dependencies: debug: 3.2.7 optionalDependencies: @@ -4289,7 +4295,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -4656,6 +4662,8 @@ snapshots: human-signals@2.1.0: {} + iamcal@2.1.2: {} + ieee754@1.2.1: {} ignore@5.3.2: {} diff --git a/src/app/api/events/ical/route.ts b/src/app/api/events/ical/route.ts new file mode 100644 index 00000000..410efcab --- /dev/null +++ b/src/app/api/events/ical/route.ts @@ -0,0 +1,27 @@ +import EventService from '@/services/eventService'; +import { NextRequest, NextResponse } from 'next/server'; +import { Calendar, CalendarEvent, dump, parseCalendar } from 'iamcal'; + +export const dynamic = 'force-dynamic'; + +export async function GET(_request: NextRequest, _ctx: { params?: unknown }) { + const events = await EventService.getAll(); + const calendar = new Calendar('cthit'); + + for (const event of events) { + calendar.addComponent( + new CalendarEvent(event.id.toString(), event.startTime, event.startTime) + .setEnd(event.endTime) + .setSummary(event.titleSv) + ); + } + const ical = calendar.serialize(); + + return new NextResponse(ical, { + status: 200, + headers: { + 'Content-Type': 'text/calendar; charset=utf-8', + 'Content-Disposition': 'attachment; filename="events.ics"' + } + }); +} diff --git a/src/app/api/events/route.ts b/src/app/api/events/json/route.ts similarity index 100% rename from src/app/api/events/route.ts rename to src/app/api/events/json/route.ts