import type { DavPatAuth } from "@/worker/auth/basic"; import { hasDavScope } from "@/worker/auth/scopes"; import type { DiscoveryResource } from "@/worker/dav/discovery/resources"; export const CALENDAR_HOME_RESOURCE: DiscoveryResource = { kind: "calendar-home", protocol: "caldav", href: "/calendars/", displayName: "Calendars", }; export const CALENDAR_DEFAULT_RESOURCE: DiscoveryResource = { kind: "calendar-default", protocol: "caldav", href: "/calendars/default/", displayName: "Default", }; export function isCalendarDiscoveryPath(pathname: string): boolean { return pathname === "/calendars" || pathname.startsWith("/calendars/"); } export function calendarResourceForPath(pathname: string): DiscoveryResource | null { if (pathname === "/calendars" || pathname === "/calendars/") return CALENDAR_HOME_RESOURCE; if (pathname === "/calendars/default" || pathname === "/calendars/default/") return CALENDAR_DEFAULT_RESOURCE; return null; } export function calendarChildResources(auth: DavPatAuth): DiscoveryResource[] { return hasDavScope(auth.scopes, "dav:caldav:read") ? [CALENDAR_DEFAULT_RESOURCE] : []; }