import type { DavPatAuth } from "@/worker/auth/basic"; import { hasAnyDavScope, hasDavScope } from "@/worker/auth/scopes"; import { ADDRESSBOOK_HOME_RESOURCE } from "@/worker/dav/discovery/addressbooks"; import { CALENDAR_HOME_RESOURCE } from "@/worker/dav/discovery/calendars"; import { FILES_HOME_RESOURCE } from "@/worker/dav/discovery/files"; import { PRINCIPALS_RESOURCE } from "@/worker/dav/discovery/principals"; import type { DiscoveryResource } from "@/worker/dav/discovery/resources"; export const ROOT_RESOURCE: DiscoveryResource = { kind: "root", protocol: "discovery", href: "/", displayName: "dab", }; export function isRootPath(pathname: string): boolean { return pathname === "/"; } export function rootChildResources(auth: DavPatAuth): DiscoveryResource[] { const children = [PRINCIPALS_RESOURCE]; if (hasAnyDavScope(auth.scopes, ["dav:files:read", "dav:files:write"])) children.push(FILES_HOME_RESOURCE); if (hasDavScope(auth.scopes, "dav:caldav:read")) children.push(CALENDAR_HOME_RESOURCE); if (hasDavScope(auth.scopes, "dav:carddav:read")) children.push(ADDRESSBOOK_HOME_RESOURCE); return children; }