File
Blob: src/worker/dav/discovery/calendars.ts
| 1 | import type { DavPatAuth } from "@/worker/auth/basic"; |
| 2 | import { hasDavScope } from "@/worker/auth/scopes"; |
| 3 | import type { DiscoveryResource } from "@/worker/dav/discovery/resources"; |
| 4 | |
| 5 | export const CALENDAR_HOME_RESOURCE: DiscoveryResource = { |
| 6 | kind: "calendar-home", |
| 7 | protocol: "caldav", |
| 8 | href: "/calendars/", |
| 9 | displayName: "Calendars", |
| 10 | }; |
| 11 | |
| 12 | export const CALENDAR_DEFAULT_RESOURCE: DiscoveryResource = { |
| 13 | kind: "calendar-default", |
| 14 | protocol: "caldav", |
| 15 | href: "/calendars/default/", |
| 16 | displayName: "Default", |
| 17 | }; |
| 18 | |
| 19 | export function isCalendarDiscoveryPath(pathname: string): boolean { |
| 20 | return pathname === "/calendars" || pathname.startsWith("/calendars/"); |
| 21 | } |
| 22 | |
| 23 | export function calendarResourceForPath(pathname: string): DiscoveryResource | null { |
| 24 | if (pathname === "/calendars" || pathname === "/calendars/") return CALENDAR_HOME_RESOURCE; |
| 25 | if (pathname === "/calendars/default" || pathname === "/calendars/default/") return CALENDAR_DEFAULT_RESOURCE; |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | export function calendarChildResources(auth: DavPatAuth): DiscoveryResource[] { |
| 30 | return hasDavScope(auth.scopes, "dav:caldav:read") ? [CALENDAR_DEFAULT_RESOURCE] : []; |
| 31 | } |