File
Blob: src/worker/dav/discovery/addressbooks.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 ADDRESSBOOK_HOME_RESOURCE: DiscoveryResource = { |
| 6 | kind: "addressbook-home", |
| 7 | protocol: "carddav", |
| 8 | href: "/addressbooks/", |
| 9 | displayName: "Address Books", |
| 10 | }; |
| 11 | |
| 12 | export const ADDRESSBOOK_DEFAULT_RESOURCE: DiscoveryResource = { |
| 13 | kind: "addressbook-default", |
| 14 | protocol: "carddav", |
| 15 | href: "/addressbooks/default/", |
| 16 | displayName: "Default", |
| 17 | }; |
| 18 | |
| 19 | export function isAddressbookDiscoveryPath(pathname: string): boolean { |
| 20 | return pathname === "/addressbooks" || pathname.startsWith("/addressbooks/"); |
| 21 | } |
| 22 | |
| 23 | export function addressbookResourceForPath(pathname: string): DiscoveryResource | null { |
| 24 | if (pathname === "/addressbooks" || pathname === "/addressbooks/") return ADDRESSBOOK_HOME_RESOURCE; |
| 25 | if (pathname === "/addressbooks/default" || pathname === "/addressbooks/default/") { |
| 26 | return ADDRESSBOOK_DEFAULT_RESOURCE; |
| 27 | } |
| 28 | return null; |
| 29 | } |
| 30 | |
| 31 | export function addressbookChildResources(auth: DavPatAuth): DiscoveryResource[] { |
| 32 | return hasDavScope(auth.scopes, "dav:carddav:read") ? [ADDRESSBOOK_DEFAULT_RESOURCE] : []; |
| 33 | } |