mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
1 line
No EOL
12 KiB
XML
1 line
No EOL
12 KiB
XML
{"version":3,"file":"dav-B62B0Btx.chunk.mjs","sources":["../node_modules/@nextcloud/files/dist/dav.mjs"],"sourcesContent":["import { getCurrentUser, onRequestTokenUpdate, getRequestToken } from \"@nextcloud/auth\";\nimport { generateRemoteUrl } from \"@nextcloud/router\";\nimport { isPublicShare, getSharingToken } from \"@nextcloud/sharing/public\";\nimport { createClient, getPatcher } from \"webdav\";\nimport { P as Permission, l as logger, c as NodeStatus, a as File, b as Folder } from \"./chunks/folder-CeyZUHai.mjs\";\n/*!\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nfunction parsePermissions(permString = \"\") {\n let permissions = Permission.NONE;\n if (!permString) {\n return permissions;\n }\n if (permString.includes(\"G\")) {\n permissions |= Permission.READ;\n }\n if (permString.includes(\"W\")) {\n permissions |= Permission.WRITE;\n }\n if (permString.includes(\"CK\")) {\n permissions |= Permission.CREATE;\n }\n if (permString.includes(\"NV\")) {\n permissions |= Permission.UPDATE;\n }\n if (permString.includes(\"D\")) {\n permissions |= Permission.DELETE;\n }\n if (permString.includes(\"R\")) {\n permissions |= Permission.SHARE;\n }\n return permissions;\n}\nconst defaultDavProperties = [\n \"d:getcontentlength\",\n \"d:getcontenttype\",\n \"d:getetag\",\n \"d:getlastmodified\",\n \"d:creationdate\",\n \"d:displayname\",\n \"d:quota-available-bytes\",\n \"d:resourcetype\",\n \"nc:has-preview\",\n \"nc:is-encrypted\",\n \"nc:mount-type\",\n \"oc:comments-unread\",\n \"oc:favorite\",\n \"oc:fileid\",\n \"oc:owner-display-name\",\n \"oc:owner-id\",\n \"oc:permissions\",\n \"oc:size\"\n];\nconst defaultDavNamespaces = {\n d: \"DAV:\",\n nc: \"http://nextcloud.org/ns\",\n oc: \"http://owncloud.org/ns\",\n ocs: \"http://open-collaboration-services.org/ns\"\n};\nfunction registerDavProperty(prop, namespace = { nc: \"http://nextcloud.org/ns\" }) {\n if (typeof window._nc_dav_properties === \"undefined\") {\n window._nc_dav_properties = [...defaultDavProperties];\n window._nc_dav_namespaces = { ...defaultDavNamespaces };\n }\n const namespaces = { ...window._nc_dav_namespaces, ...namespace };\n if (window._nc_dav_properties.find((search) => search === prop)) {\n logger.warn(`${prop} already registered`, { prop });\n return false;\n }\n if (prop.startsWith(\"<\") || prop.split(\":\").length !== 2) {\n logger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop });\n return false;\n }\n const ns = prop.split(\":\")[0];\n if (!namespaces[ns]) {\n logger.error(`${prop} namespace unknown`, { prop, namespaces });\n return false;\n }\n window._nc_dav_properties.push(prop);\n window._nc_dav_namespaces = namespaces;\n return true;\n}\nfunction getDavProperties() {\n if (typeof window._nc_dav_properties === \"undefined\") {\n window._nc_dav_properties = [...defaultDavProperties];\n }\n return window._nc_dav_properties.map((prop) => `<${prop} />`).join(\" \");\n}\nfunction getDavNameSpaces() {\n if (typeof window._nc_dav_namespaces === \"undefined\") {\n window._nc_dav_namespaces = { ...defaultDavNamespaces };\n }\n return Object.keys(window._nc_dav_namespaces).map((ns) => `xmlns:${ns}=\"${window._nc_dav_namespaces?.[ns]}\"`).join(\" \");\n}\nfunction getDefaultPropfind() {\n return `<?xml version=\"1.0\"?>\n\t\t<d:propfind ${getDavNameSpaces()}>\n\t\t\t<d:prop>\n\t\t\t\t${getDavProperties()}\n\t\t\t</d:prop>\n\t\t</d:propfind>`;\n}\nfunction getFavoritesReport() {\n return `<?xml version=\"1.0\"?>\n\t\t<oc:filter-files ${getDavNameSpaces()}>\n\t\t\t<d:prop>\n\t\t\t\t${getDavProperties()}\n\t\t\t</d:prop>\n\t\t\t<oc:filter-rules>\n\t\t\t\t<oc:favorite>1</oc:favorite>\n\t\t\t</oc:filter-rules>\n\t\t</oc:filter-files>`;\n}\nfunction getRecentSearch(lastModified) {\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<d:searchrequest ${getDavNameSpaces()}\n\txmlns:ns=\"https://github.com/icewind1991/SearchDAV/ns\">\n\t<d:basicsearch>\n\t\t<d:select>\n\t\t\t<d:prop>\n\t\t\t\t${getDavProperties()}\n\t\t\t</d:prop>\n\t\t</d:select>\n\t\t<d:from>\n\t\t\t<d:scope>\n\t\t\t\t<d:href>/files/${getCurrentUser()?.uid}/</d:href>\n\t\t\t\t<d:depth>infinity</d:depth>\n\t\t\t</d:scope>\n\t\t</d:from>\n\t\t<d:where>\n\t\t\t<d:and>\n\t\t\t\t<d:or>\n\t\t\t\t\t<d:not>\n\t\t\t\t\t\t<d:eq>\n\t\t\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t\t\t<d:getcontenttype/>\n\t\t\t\t\t\t\t</d:prop>\n\t\t\t\t\t\t\t<d:literal>httpd/unix-directory</d:literal>\n\t\t\t\t\t\t</d:eq>\n\t\t\t\t\t</d:not>\n\t\t\t\t\t<d:eq>\n\t\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t\t<oc:size/>\n\t\t\t\t\t\t</d:prop>\n\t\t\t\t\t\t<d:literal>0</d:literal>\n\t\t\t\t\t</d:eq>\n\t\t\t\t</d:or>\n\t\t\t\t<d:gt>\n\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t<d:getlastmodified/>\n\t\t\t\t\t</d:prop>\n\t\t\t\t\t<d:literal>${lastModified}</d:literal>\n\t\t\t\t</d:gt>\n\t\t\t</d:and>\n\t\t</d:where>\n\t\t<d:orderby>\n\t\t\t<d:order>\n\t\t\t\t<d:prop>\n\t\t\t\t\t<d:getlastmodified/>\n\t\t\t\t</d:prop>\n\t\t\t\t<d:descending/>\n\t\t\t</d:order>\n\t\t</d:orderby>\n\t\t<d:limit>\n\t\t\t<d:nresults>100</d:nresults>\n\t\t\t<ns:firstresult>0</ns:firstresult>\n\t\t</d:limit>\n\t</d:basicsearch>\n</d:searchrequest>`;\n}\nfunction getRootPath() {\n if (isPublicShare()) {\n return `/files/${getSharingToken()}`;\n }\n return `/files/${getCurrentUser()?.uid}`;\n}\nconst defaultRootPath = getRootPath();\nfunction getRemoteURL() {\n const url = generateRemoteUrl(\"dav\");\n if (isPublicShare()) {\n return url.replace(\"remote.php\", \"public.php\");\n }\n return url;\n}\nconst defaultRemoteURL = getRemoteURL();\nfunction getClient(remoteURL = defaultRemoteURL, headers = {}) {\n const client = createClient(remoteURL, { headers });\n function setHeaders(token) {\n client.setHeaders({\n ...headers,\n // Add this so the server knows it is an request from the browser\n \"X-Requested-With\": \"XMLHttpRequest\",\n // Inject user auth\n requesttoken: token ?? \"\"\n });\n }\n onRequestTokenUpdate(setHeaders);\n setHeaders(getRequestToken());\n const patcher = getPatcher();\n patcher.patch(\"fetch\", (url, options) => {\n const headers2 = options.headers;\n if (headers2?.method) {\n options.method = headers2.method;\n delete headers2.method;\n }\n return fetch(url, options);\n });\n return client;\n}\nasync function getFavoriteNodes(options = {}) {\n const client = options.client ?? getClient();\n const path = options.path ?? \"/\";\n const davRoot = options.davRoot ?? defaultRootPath;\n const contentsResponse = await client.getDirectoryContents(`${davRoot}${path}`, {\n signal: options.signal,\n details: true,\n data: getFavoritesReport(),\n headers: {\n // see getClient for patched webdav client\n method: \"REPORT\"\n },\n includeSelf: true\n });\n return contentsResponse.data.filter((node) => node.filename !== path).map((result) => resultToNode(result, davRoot));\n}\nfunction resultToNode(node, filesRoot = defaultRootPath, remoteURL = defaultRemoteURL) {\n let userId = getCurrentUser()?.uid;\n if (isPublicShare()) {\n userId = userId ?? \"anonymous\";\n } else if (!userId) {\n throw new Error(\"No user id found\");\n }\n const props = node.props;\n const permissions = parsePermissions(props?.permissions);\n const owner = String(props?.[\"owner-id\"] || userId);\n const id = props.fileid || 0;\n const mtime = new Date(Date.parse(node.lastmod));\n const crtime = new Date(Date.parse(props.creationdate));\n const nodeData = {\n id,\n source: `${remoteURL}${node.filename}`,\n mtime: !isNaN(mtime.getTime()) && mtime.getTime() !== 0 ? mtime : void 0,\n crtime: !isNaN(crtime.getTime()) && crtime.getTime() !== 0 ? crtime : void 0,\n mime: node.mime || \"application/octet-stream\",\n // Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380\n displayname: props.displayname !== void 0 ? String(props.displayname) : void 0,\n size: props?.size || Number.parseInt(props.getcontentlength || \"0\"),\n // The fileid is set to -1 for failed requests\n status: id < 0 ? NodeStatus.FAILED : void 0,\n permissions,\n owner,\n root: filesRoot,\n attributes: {\n ...node,\n ...props,\n hasPreview: props?.[\"has-preview\"]\n }\n };\n delete nodeData.attributes?.props;\n return node.type === \"file\" ? new File(nodeData) : new Folder(nodeData);\n}\nexport {\n defaultDavNamespaces,\n defaultDavProperties,\n defaultRemoteURL,\n defaultRootPath,\n getClient,\n getDavNameSpaces,\n getDavProperties,\n getDefaultPropfind,\n getFavoriteNodes,\n getFavoritesReport,\n getRecentSearch,\n getRemoteURL,\n getRootPath,\n parsePermissions,\n registerDavProperty,\n resultToNode\n};\n//# sourceMappingURL=dav.mjs.map\n"],"names":["parsePermissions","permString","permissions","Permission","defaultDavProperties","defaultDavNamespaces","registerDavProperty","prop","namespace","namespaces","search","logger","ns","getDavProperties","getDavNameSpaces","getRootPath","isPublicShare","getSharingToken","getCurrentUser","defaultRootPath","getRemoteURL","url","generateRemoteUrl","defaultRemoteURL","getClient","remoteURL","headers","client","createClient","setHeaders","token","onRequestTokenUpdate","getRequestToken","getPatcher","options","headers2","resultToNode","node","filesRoot","userId","props","owner","id","mtime","crtime","nodeData","NodeStatus","File","Folder"],"mappings":"sTASA,SAASA,EAAiBC,EAAa,GAAI,CACzC,IAAIC,EAAcC,EAAW,KAC7B,OAAKF,IAGDA,EAAW,SAAS,GAAG,IACzBC,GAAeC,EAAW,MAExBF,EAAW,SAAS,GAAG,IACzBC,GAAeC,EAAW,OAExBF,EAAW,SAAS,IAAI,IAC1BC,GAAeC,EAAW,QAExBF,EAAW,SAAS,IAAI,IAC1BC,GAAeC,EAAW,QAExB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