{"version":3,"file":"api-CnLEK7Ep.chunk.mjs","sources":["../build/frontend/apps/systemtags/src/logger.ts","../build/frontend/apps/systemtags/src/utils.ts","../build/frontend/apps/systemtags/src/services/davClient.ts","../build/frontend/apps/systemtags/src/services/api.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { getLoggerBuilder } from '@nextcloud/logger'\n\nexport default getLoggerBuilder()\n\t.setApp('systemtags')\n\t.detectUser()\n\t.build()\n","/**\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { INode } from '@nextcloud/files'\nimport type { DAVResultResponseProps } from 'webdav'\nimport type { BaseTag, ServerTag, Tag, TagWithId } from './types.ts'\n\nimport { emit } from '@nextcloud/event-bus'\n\nexport const defaultBaseTag: BaseTag = {\n\tuserVisible: true,\n\tuserAssignable: true,\n\tcanAssign: true,\n}\n\nconst propertyMappings = Object.freeze({\n\t'display-name': 'displayName',\n\t'user-visible': 'userVisible',\n\t'user-assignable': 'userAssignable',\n\t'can-assign': 'canAssign',\n})\n\n/**\n * Parse tags from WebDAV response\n *\n * @param tags - Array of tags from WebDAV response\n */\nexport function parseTags(tags: { props: DAVResultResponseProps }[]): TagWithId[] {\n\treturn tags.map(({ props }) => Object.fromEntries(Object.entries(props)\n\t\t.map(([key, value]) => {\n\t\t\tkey = propertyMappings[key] ?? key\n\t\t\tvalue = key === 'displayName' ? String(value) : value\n\t\t\treturn [key, value]\n\t\t})) as unknown as TagWithId)\n}\n\n/**\n * Parse id from `Content-Location` header\n *\n * @param url URL to parse\n */\nexport function parseIdFromLocation(url: string): number {\n\tconst queryPos = url.indexOf('?')\n\tif (queryPos > 0) {\n\t\turl = url.substring(0, queryPos)\n\t}\n\n\tconst parts = url.split('/')\n\tlet result\n\tdo {\n\t\tresult = parts[parts.length - 1]\n\t\tparts.pop()\n\t\t// note: first result can be empty when there is a trailing slash,\n\t\t// so we take the part before that\n\t} while (!result && parts.length > 0)\n\n\treturn Number(result)\n}\n\n/**\n * Format a tag for WebDAV operations\n *\n * @param initialTag - Tag to format\n */\nexport function formatTag(initialTag: Tag | ServerTag): ServerTag {\n\tif ('name' in initialTag && !('displayName' in initialTag)) {\n\t\treturn { ...initialTag }\n\t}\n\n\tconst tag: Record<string, unknown> = { ...initialTag }\n\ttag.name = tag.displayName\n\tdelete tag.displayName\n\n\treturn tag as unknown as ServerTag\n}\n\n/**\n * Get system tags from a node\n *\n * @param node - The node to get tags from\n */\nexport function getNodeSystemTags(node: INode): string[] {\n\tconst attribute = node.attributes?.['system-tags']?.['system-tag']\n\tif (attribute === undefined) {\n\t\treturn []\n\t}\n\n\t// if there is only one tag it is a single string or prop object\n\t// if there are multiple then its an array - so we flatten it to be always an array of string or prop objects\n\treturn [attribute]\n\t\t.flat()\n\t\t.map((tag: string | { text: string }) => (\n\t\t\ttypeof tag === 'string'\n\t\t\t\t// its a plain text prop (the tag name) without prop attributes\n\t\t\t\t? tag\n\t\t\t\t// its a prop object with attributes, the tag name is in the 'text' attribute\n\t\t\t\t: tag.text\n\t\t))\n}\n\n/**\n * Set system tags on a node\n *\n * @param node - The node to set tags on\n * @param tags - The tags to set\n */\nexport function setNodeSystemTags(node: INode, tags: string[]): void {\n\tnode.attributes['system-tags'] = {\n\t\t'system-tag': tags,\n\t}\n\temit('files:node:updated', node)\n}\n","/*!\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { Node } from '@nextcloud/files'\nimport type { FileStat, ResponseDataDetailed } from 'webdav'\n\nimport { getClient, getDefaultPropfind, getRootPath, resultToNode } from '@nextcloud/files/dav'\n\nexport const d