Skip to content
File

Blob: src/worker/dav/discovery/calendars.ts

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