File
Blob: src/worker/dav/discovery/root.ts
| 1 | import type { DavPatAuth } from "@/worker/auth/basic"; |
| 2 | import { hasAnyDavScope, hasDavScope } from "@/worker/auth/scopes"; |
| 3 | import { ADDRESSBOOK_HOME_RESOURCE } from "@/worker/dav/discovery/addressbooks"; |
| 4 | import { CALENDAR_HOME_RESOURCE } from "@/worker/dav/discovery/calendars"; |
| 5 | import { FILES_HOME_RESOURCE } from "@/worker/dav/discovery/files"; |
| 6 | import { PRINCIPALS_RESOURCE } from "@/worker/dav/discovery/principals"; |
| 7 | import type { DiscoveryResource } from "@/worker/dav/discovery/resources"; |
| 8 | |
| 9 | export const ROOT_RESOURCE: DiscoveryResource = { |
| 10 | kind: "root", |
| 11 | protocol: "discovery", |
| 12 | href: "/", |
| 13 | displayName: "dab", |
| 14 | }; |
| 15 | |
| 16 | export function isRootPath(pathname: string): boolean { |
| 17 | return pathname === "/"; |
| 18 | } |
| 19 | |
| 20 | export function rootChildResources(auth: DavPatAuth): DiscoveryResource[] { |
| 21 | const children = [PRINCIPALS_RESOURCE]; |
| 22 | if (hasAnyDavScope(auth.scopes, ["dav:files:read", "dav:files:write"])) children.push(FILES_HOME_RESOURCE); |
| 23 | if (hasDavScope(auth.scopes, "dav:caldav:read")) children.push(CALENDAR_HOME_RESOURCE); |
| 24 | if (hasDavScope(auth.scopes, "dav:carddav:read")) children.push(ADDRESSBOOK_HOME_RESOURCE); |
| 25 | return children; |
| 26 | } |