diff --git a/lib/files/node.ts b/lib/files/node.ts index e3dbc66b..42e30480 100644 --- a/lib/files/node.ts +++ b/lib/files/node.ts @@ -20,6 +20,8 @@ * */ import { basename, extname, dirname } from 'path' +import { encodePath } from '@nextcloud/paths' + import { Permission } from '../permissions' import { FileType } from './fileType' import { Attribute, NodeData, isDavRessource, validateData } from './nodeData' @@ -82,6 +84,14 @@ export abstract class Node { return this._data.source.replace(/\/$/i, '') } + /** + * Get the encoded source url to this object for requests purposes + */ + get encodedSource(): string { + const { origin } = new URL(this.source) + return origin + encodePath(this.source.slice(origin.length)) + } + /** * Get this object name */ diff --git a/package-lock.json b/package-lock.json index 6ede877e..249229f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@nextcloud/auth": "^2.2.1", "@nextcloud/l10n": "^2.2.0", "@nextcloud/logger": "^2.7.0", + "@nextcloud/paths": "^2.1.0", "@nextcloud/router": "^2.1.2", "is-svg": "^5.0.0", "webdav": "^5.3.0" @@ -1194,6 +1195,14 @@ "npm": "^9.0.0" } }, + "node_modules/@nextcloud/paths": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@nextcloud/paths/-/paths-2.1.0.tgz", + "integrity": "sha512-8wX0gqwez0bTuAS8A0OEiqbbp0ZsqLr07zSErmS6OYhh9KZcSt/kO6lQV5tnrFqIqJVsxwz4kHUjtZXh6DSf9Q==", + "dependencies": { + "core-js": "^3.6.4" + } + }, "node_modules/@nextcloud/router": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@nextcloud/router/-/router-2.1.2.tgz", diff --git a/package.json b/package.json index dfe5b8ad..6019109c 100644 --- a/package.json +++ b/package.json @@ -72,8 +72,9 @@ "@nextcloud/auth": "^2.2.1", "@nextcloud/l10n": "^2.2.0", "@nextcloud/logger": "^2.7.0", + "@nextcloud/paths": "^2.1.0", "@nextcloud/router": "^2.1.2", "is-svg": "^5.0.0", "webdav": "^5.3.0" } -} \ No newline at end of file +}