@nextcloud/files 4.0.0-rc.1 → 4.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{folder-CeyZUHai.mjs → folder-D9CBQngR.mjs} +16 -12
- package/dist/chunks/folder-D9CBQngR.mjs.map +1 -0
- package/dist/dav.mjs +12 -17
- package/dist/dav.mjs.map +1 -1
- package/dist/globalScope.d.ts +27 -0
- package/dist/headers/index.d.ts +1 -2
- package/dist/headers/listHeaders.d.ts +11 -11
- package/dist/index.mjs +68 -95
- package/dist/index.mjs.map +1 -1
- package/dist/node/fileType.d.ts +1 -1
- package/dist/node/index.d.ts +4 -2
- package/dist/node/node.d.ts +5 -16
- package/dist/node/nodeData.d.ts +16 -2
- package/dist/registry.d.ts +38 -11
- package/package.json +4 -4
- package/dist/chunks/folder-CeyZUHai.mjs.map +0 -1
- package/dist/headers/functions.d.ts +0 -11
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getLoggerBuilder } from "@nextcloud/logger";
|
|
2
2
|
import { join, encodePath, basename, extname, dirname } from "@nextcloud/paths";
|
|
3
|
+
window._nc_files_scope ??= {};
|
|
4
|
+
window._nc_files_scope.v4_0 ??= {};
|
|
5
|
+
const scopedGlobals = window._nc_files_scope.v4_0;
|
|
3
6
|
const logger = getLoggerBuilder().setApp("@nextcloud/files").detectUser().build();
|
|
4
7
|
const FileType = Object.freeze({
|
|
5
8
|
Folder: "folder",
|
|
@@ -39,6 +42,16 @@ const Permission = Object.freeze({
|
|
|
39
42
|
*/
|
|
40
43
|
ALL: 31
|
|
41
44
|
});
|
|
45
|
+
const NodeStatus = Object.freeze({
|
|
46
|
+
/** This is a new node and it doesn't exists on the filesystem yet */
|
|
47
|
+
NEW: "new",
|
|
48
|
+
/** This node has failed and is unavailable */
|
|
49
|
+
FAILED: "failed",
|
|
50
|
+
/** This node is currently loading or have an operation in progress */
|
|
51
|
+
LOADING: "loading",
|
|
52
|
+
/** This node is locked and cannot be modified */
|
|
53
|
+
LOCKED: "locked"
|
|
54
|
+
});
|
|
42
55
|
function isDavResource(source, davService) {
|
|
43
56
|
return source.match(davService) !== null;
|
|
44
57
|
}
|
|
@@ -126,16 +139,6 @@ function fixRegExp(pattern) {
|
|
|
126
139
|
const validFlags = Array.from(new Set(matches[3])).filter((flag) => "gimsuy".includes(flag)).join("");
|
|
127
140
|
return new RegExp(matches[2], validFlags);
|
|
128
141
|
}
|
|
129
|
-
const NodeStatus = Object.freeze({
|
|
130
|
-
/** This is a new node and it doesn't exists on the filesystem yet */
|
|
131
|
-
NEW: "new",
|
|
132
|
-
/** This node has failed and is unavailable */
|
|
133
|
-
FAILED: "failed",
|
|
134
|
-
/** This node is currently loading or have an operation in progress */
|
|
135
|
-
LOADING: "loading",
|
|
136
|
-
/** This node is locked and cannot be modified */
|
|
137
|
-
LOCKED: "locked"
|
|
138
|
-
});
|
|
139
142
|
class Node {
|
|
140
143
|
_attributes;
|
|
141
144
|
_data;
|
|
@@ -466,6 +469,7 @@ export {
|
|
|
466
469
|
File as a,
|
|
467
470
|
Folder as b,
|
|
468
471
|
NodeStatus as c,
|
|
469
|
-
logger as l
|
|
472
|
+
logger as l,
|
|
473
|
+
scopedGlobals as s
|
|
470
474
|
};
|
|
471
|
-
//# sourceMappingURL=folder-
|
|
475
|
+
//# sourceMappingURL=folder-D9CBQngR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder-D9CBQngR.mjs","sources":["../../lib/globalScope.ts","../../lib/utils/logger.ts","../../lib/node/fileType.ts","../../lib/permissions.ts","../../lib/node/nodeData.ts","../../lib/node/node.ts","../../lib/node/file.ts","../../lib/node/folder.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { IFileAction, IFileListAction } from './actions/index.ts'\nimport type { DavProperty } from './dav/index.ts'\nimport type {\n\tIFileListFilter,\n\tIFileListHeader,\n\tNavigation,\n\tNewMenu,\n} from './index.ts'\nimport type { FilesRegistry } from './registry.ts'\nimport type { ISidebarTab } from './sidebar/index.ts'\nimport type { ISidebarAction } from './sidebar/SidebarAction.ts'\n\ninterface InternalGlobalScope {\n\tdavNamespaces?: DavProperty\n\tdavProperties?: string[]\n\n\tnewFileMenu?: NewMenu\n\tnavigation?: Navigation\n\tregistry?: FilesRegistry\n\n\tfileActions?: Map<string, IFileAction>\n\tfileListActions?: Map<string, IFileListAction>\n\tfileListFilters?: Map<string, IFileListFilter>\n\tfileListHeaders?: Map<string, IFileListHeader>\n\n\tfilesSidebarActions?: Map<string, ISidebarAction>\n\tfilesSidebarTabs?: Map<string, ISidebarTab>\n}\n\nwindow._nc_files_scope ??= {}\nwindow._nc_files_scope.v4_0 ??= {}\n\n/**\n * Get the global scope for the files library.\n * This is used to store global variables scoped to prevent breaking changes in the future.\n *\n * @internal\n */\nexport const scopedGlobals = window._nc_files_scope.v4_0 as InternalGlobalScope\n","/**\n * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport { getLoggerBuilder } from '@nextcloud/logger'\n\nexport default getLoggerBuilder()\n\t.setApp('@nextcloud/files')\n\t.detectUser()\n\t.build()\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nexport const FileType = Object.freeze({\n\tFolder: 'folder',\n\tFile: 'file',\n})\n\nexport type IFileType = typeof FileType[keyof typeof FileType]\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\n/**\n * Node permissions\n */\nexport const Permission = Object.freeze({\n\t/**\n\t * No permissions granted\n\t */\n\tNONE: 0,\n\t/**\n\t * Can read the file content\n\t */\n\tREAD: 1,\n\t/**\n\t * Can modify the file itself (move, rename, etc)\n\t */\n\tUPDATE: 2,\n\t/**\n\t * Can create new files/folders inside a folder\n\t */\n\tCREATE: 4,\n\t/**\n\t * Can change the file content\n\t */\n\tWRITE: 4,\n\t/**\n\t * Can delete the node\n\t */\n\tDELETE: 8,\n\t/**\n\t * Can share the node\n\t */\n\tSHARE: 16,\n\t/**\n\t * All permissions are granted\n\t */\n\tALL: 31,\n})\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { join } from '@nextcloud/paths'\nimport { Permission } from '../permissions.ts'\n\nexport const NodeStatus = Object.freeze({\n\t/** This is a new node and it doesn't exists on the filesystem yet */\n\tNEW: 'new',\n\t/** This node has failed and is unavailable */\n\tFAILED: 'failed',\n\t/** This node is currently loading or have an operation in progress */\n\tLOADING: 'loading',\n\t/** This node is locked and cannot be modified */\n\tLOCKED: 'locked',\n})\n\nexport type INodeStatus = typeof NodeStatus[keyof typeof NodeStatus]\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface Attribute { [key: string]: any }\n\nexport interface NodeData {\n\t/**\n\t * URL to the resource.\n\t * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg\n\t * or https://domain.com/Photos/picture.jpg\n\t */\n\tsource: string\n\n\t/**\n\t * The absolute root of the home relative to the service.\n\t * It is highly recommended to provide that information.\n\t * e.g. /files/emma\n\t */\n\troot: string\n\n\t/** Unique ID */\n\tid?: number\n\n\t/** Last modified time */\n\tmtime?: Date\n\n\t/** Creation time */\n\tcrtime?: Date\n\n\t/** The mime type Optional for folders only */\n\tmime?: string\n\n\t/** The node size type */\n\tsize?: number\n\n\t/**\n\t * The node permissions.\n\t *\n\t * A binary mask of `Permission` values.\n\t *\n\t * @see Permission\n\t */\n\tpermissions?: number\n\n\t/** The owner UID of this node */\n\towner: string | null\n\n\t/** Optional the displayname of this node */\n\tdisplayname?: string\n\n\t/** The node attributes */\n\tattributes?: Attribute\n\n\t/** The node status */\n\tstatus?: INodeStatus\n}\n\n/**\n * Check if a node source is from a specific DAV service\n *\n * @param source The source to check\n * @param davService Pattern to check if source is DAV resource\n */\nexport function isDavResource(source: string, davService: RegExp): boolean {\n\treturn source.match(davService) !== null\n}\n\n/**\n * Validate Node construct data\n *\n * @param data The node data\n * @param davService Pattern to check if source is DAV ressource\n */\nexport function validateData(data: NodeData, davService: RegExp) {\n\tif (data.id && typeof data.id !== 'number') {\n\t\tthrow new Error('Invalid id type of value')\n\t}\n\n\tif (!data.source) {\n\t\tthrow new Error('Missing mandatory source')\n\t}\n\n\ttry {\n\t\tnew URL(data.source)\n\t} catch {\n\t\tthrow new Error('Invalid source format, source must be a valid URL')\n\t}\n\n\tif (!data.source.startsWith('http')) {\n\t\tthrow new Error('Invalid source format, only http(s) is supported')\n\t}\n\n\tif (!data.root) {\n\t\tthrow new Error('Missing mandatory root')\n\t}\n\n\tif (typeof data.root !== 'string') {\n\t\tthrow new Error('Invalid root type')\n\t}\n\n\tif (!data.root.startsWith('/')) {\n\t\tthrow new Error('Root must start with a leading slash')\n\t}\n\n\tif (!data.source.includes(data.root)) {\n\t\tthrow new Error('Root must be part of the source')\n\t}\n\n\tif (isDavResource(data.source, davService)) {\n\t\tconst service = data.source.match(davService)![0]\n\t\tif (!data.source.includes(join(service, data.root))) {\n\t\t\tthrow new Error('The root must be relative to the service. e.g /files/emma')\n\t\t}\n\t}\n\n\tif (data.displayname && typeof data.displayname !== 'string') {\n\t\tthrow new Error('Invalid displayname type')\n\t}\n\n\tif (data.mtime && !(data.mtime instanceof Date)) {\n\t\tthrow new Error('Invalid mtime type')\n\t}\n\n\tif (data.crtime && !(data.crtime instanceof Date)) {\n\t\tthrow new Error('Invalid crtime type')\n\t}\n\n\tif (!data.mime || typeof data.mime !== 'string'\n\t\t|| !data.mime.match(/^[-\\w.]+\\/[-+\\w.]+$/gi)) {\n\t\tthrow new Error('Missing or invalid mandatory mime')\n\t}\n\n\t// Allow size to be 0\n\tif ('size' in data && typeof data.size !== 'number' && data.size !== undefined) {\n\t\tthrow new Error('Invalid size type')\n\t}\n\n\t// Allow permissions to be 0\n\tif ('permissions' in data\n\t\t&& data.permissions !== undefined\n\t\t&& !(typeof data.permissions === 'number'\n\t\t\t&& data.permissions >= Permission.NONE\n\t\t\t&& data.permissions <= Permission.ALL\n\t\t)) {\n\t\tthrow new Error('Invalid permissions')\n\t}\n\n\tif (data.owner\n\t\t&& data.owner !== null\n\t\t&& typeof data.owner !== 'string') {\n\t\tthrow new Error('Invalid owner type')\n\t}\n\n\tif (data.attributes && typeof data.attributes !== 'object') {\n\t\tthrow new Error('Invalid attributes type')\n\t}\n\n\tif (data.status && !Object.values(NodeStatus).includes(data.status)) {\n\t\tthrow new Error('Status must be a valid NodeStatus')\n\t}\n}\n\n/**\n * In case we try to create a node from deserialized data,\n * we need to fix date types.\n *\n * @param data The internal node data\n */\nexport function fixDates(data: NodeData) {\n\tif (data.mtime && typeof data.mtime === 'string') {\n\t\tif (!isNaN(Date.parse(data.mtime))\n\t\t\t&& JSON.stringify(new Date(data.mtime)) === JSON.stringify(data.mtime)) {\n\t\t\tdata.mtime = new Date(data.mtime)\n\t\t}\n\t}\n\n\tif (data.crtime && typeof data.crtime === 'string') {\n\t\tif (!isNaN(Date.parse(data.crtime))\n\t\t\t&& JSON.stringify(new Date(data.crtime)) === JSON.stringify(data.crtime)) {\n\t\t\tdata.crtime = new Date(data.crtime)\n\t\t}\n\t}\n}\n\n/**\n * Fix a RegExp pattern from string or RegExp to RegExp\n *\n * @param pattern The pattern as string or RegExp\n */\nexport function fixRegExp(pattern: string | RegExp): RegExp {\n\tif (pattern instanceof RegExp) {\n\t\treturn pattern\n\t}\n\n\t// Extract the pattern and flags if it's a string\n\t// Pulled from https://www.npmjs.com/package/regex-parser\n\tconst matches = pattern.match(/(\\/?)(.+)\\1([a-z]*)/i)\n\n\t// If there's no match, throw an error\n\tif (!matches) {\n\t\tthrow new Error('Invalid regular expression format.')\n\t}\n\n\t// Filter valid flags: 'g', 'i', 'm', 's', 'u', and 'y'\n\tconst validFlags = Array.from(new Set(matches[3]))\n\t\t.filter((flag) => 'gimsuy'.includes(flag))\n\t\t.join('')\n\n\t// Create the regular expression\n\treturn new RegExp(matches[2], validFlags)\n}\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { IFileType } from './fileType.ts'\nimport type { Attribute, INodeStatus, NodeData } from './nodeData.ts'\n\nimport { basename, dirname, encodePath, extname } from '@nextcloud/paths'\nimport { Permission } from '../permissions.ts'\nimport { fixDates, fixRegExp, isDavResource, validateData } from './nodeData.ts'\n\nexport type NodeConstructorData = [NodeData, RegExp?]\n\nexport abstract class Node {\n\tprivate _attributes: Attribute\n\n\tprotected _data: NodeData\n\tprotected _knownDavService = /(remote|public)\\.php\\/(web)?dav/i\n\n\tprivate readonlyAttributes = Object.entries(Object.getOwnPropertyDescriptors(Node.prototype))\n\t\t.filter((e) => typeof e[1].get === 'function' && e[0] !== '__proto__')\n\t\t.map((e) => e[0])\n\n\tprivate handler = {\n\t\tset: (target: Attribute, prop: string, value: unknown): boolean => {\n\t\t\tif (this.readonlyAttributes.includes(prop)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Apply original changes\n\t\t\treturn Reflect.set(target, prop, value)\n\t\t},\n\t\tdeleteProperty: (target: Attribute, prop: string): boolean => {\n\t\t\tif (this.readonlyAttributes.includes(prop)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Apply original changes\n\t\t\treturn Reflect.deleteProperty(target, prop)\n\t\t},\n\t} as ProxyHandler<Attribute>\n\n\tprotected constructor(...[data, davService]: NodeConstructorData) {\n\t\tif (!data.mime) {\n\t\t\tdata.mime = 'application/octet-stream'\n\t\t}\n\n\t\t// Fix primitive types if needed\n\t\tfixDates(data)\n\t\tdavService = fixRegExp(davService || this._knownDavService)\n\n\t\t// Validate data\n\t\tvalidateData(data, davService)\n\n\t\tthis._data = {\n\t\t\t...data,\n\t\t\tattributes: {},\n\t\t}\n\n\t\t// Proxy the attributes to update the mtime on change\n\t\tthis._attributes = new Proxy(this._data.attributes!, this.handler)\n\n\t\t// Update attributes, this sanitizes the attributes to only contain valid attributes\n\t\tthis.update(data.attributes ?? {})\n\n\t\tif (davService) {\n\t\t\tthis._knownDavService = davService\n\t\t}\n\t}\n\n\t/**\n\t * Get the source url to this object\n\t * There is no setter as the source is not meant to be changed manually.\n\t * You can use the rename or move method to change the source.\n\t */\n\tget source(): string {\n\t\t// strip any ending slash\n\t\treturn this._data.source.replace(/\\/$/i, '')\n\t}\n\n\t/**\n\t * Get the encoded source url to this object for requests purposes\n\t */\n\tget encodedSource(): string {\n\t\tconst { origin } = new URL(this.source)\n\t\treturn origin + encodePath(this.source.slice(origin.length))\n\t}\n\n\t/**\n\t * Get this object name\n\t * There is no setter as the source is not meant to be changed manually.\n\t * You can use the rename or move method to change the source.\n\t */\n\tget basename(): string {\n\t\treturn basename(this.source)\n\t}\n\n\t/**\n\t * The nodes displayname\n\t * By default the display name and the `basename` are identical,\n\t * but it is possible to have a different name. This happens\n\t * on the files app for example for shared folders.\n\t */\n\tget displayname(): string {\n\t\treturn this._data.displayname || this.basename\n\t}\n\n\t/**\n\t * Set the displayname\n\t */\n\tset displayname(displayname: string) {\n\t\tvalidateData({ ...this._data, displayname }, this._knownDavService)\n\t\tthis._data.displayname = displayname\n\t}\n\n\t/**\n\t * Get this object's extension\n\t * There is no setter as the source is not meant to be changed manually.\n\t * You can use the rename or move method to change the source.\n\t */\n\tget extension(): string | null {\n\t\treturn extname(this.source)\n\t}\n\n\t/**\n\t * Get the directory path leading to this object\n\t * Will use the relative path to root if available\n\t *\n\t * There is no setter as the source is not meant to be changed manually.\n\t * You can use the rename or move method to change the source.\n\t */\n\tget dirname(): string {\n\t\treturn dirname(this.path)\n\t}\n\n\t/**\n\t * Is it a file or a folder ?\n\t */\n\tabstract get type(): IFileType\n\n\t/**\n\t * Get the file mime\n\t */\n\tget mime(): string {\n\t\treturn this._data.mime || 'application/octet-stream'\n\t}\n\n\t/**\n\t * Set the file mime\n\t * Removing the mime type will set it to `application/octet-stream`\n\t */\n\tset mime(mime: string | undefined) {\n\t\tmime ??= 'application/octet-stream'\n\n\t\tvalidateData({ ...this._data, mime }, this._knownDavService)\n\t\tthis._data.mime = mime\n\t}\n\n\t/**\n\t * Get the file modification time\n\t */\n\tget mtime(): Date | undefined {\n\t\treturn this._data.mtime\n\t}\n\n\t/**\n\t * Set the file modification time\n\t */\n\tset mtime(mtime: Date | undefined) {\n\t\tvalidateData({ ...this._data, mtime }, this._knownDavService)\n\t\tthis._data.mtime = mtime\n\t}\n\n\t/**\n\t * Get the file creation time\n\t * There is no setter as the creation time is not meant to be changed\n\t */\n\tget crtime(): Date | undefined {\n\t\treturn this._data.crtime\n\t}\n\n\t/**\n\t * Get the file size\n\t */\n\tget size(): number | undefined {\n\t\treturn this._data.size\n\t}\n\n\t/**\n\t * Set the file size\n\t */\n\tset size(size: number | undefined) {\n\t\tvalidateData({ ...this._data, size }, this._knownDavService)\n\t\tthis.updateMtime()\n\t\tthis._data.size = size\n\t}\n\n\t/**\n\t * Get the file attribute\n\t * This contains all additional attributes not provided by the Node class\n\t */\n\tget attributes(): Attribute {\n\t\treturn this._attributes\n\t}\n\n\t/**\n\t * Get the file permissions\n\t */\n\tget permissions(): number {\n\t\t// If this is not a dav resource, we can only read it\n\t\tif (this.owner === null && !this.isDavResource) {\n\t\t\treturn Permission.READ\n\t\t}\n\n\t\t// If the permissions are not defined, we have none\n\t\treturn this._data.permissions !== undefined\n\t\t\t? this._data.permissions\n\t\t\t: Permission.NONE\n\t}\n\n\t/**\n\t * Set the file permissions\n\t */\n\tset permissions(permissions: number) {\n\t\tvalidateData({ ...this._data, permissions }, this._knownDavService)\n\t\tthis.updateMtime()\n\t\tthis._data.permissions = permissions\n\t}\n\n\t/**\n\t * Get the file owner\n\t * There is no setter as the owner is not meant to be changed\n\t */\n\tget owner(): string | null {\n\t\t// Remote resources have no owner\n\t\tif (!this.isDavResource) {\n\t\t\treturn null\n\t\t}\n\t\treturn this._data.owner\n\t}\n\n\t/**\n\t * Is this a dav-related resource ?\n\t */\n\tget isDavResource(): boolean {\n\t\treturn isDavResource(this.source, this._knownDavService)\n\t}\n\n\t/**\n\t * Get the dav root of this object\n\t * There is no setter as the root is not meant to be changed\n\t */\n\tget root(): string {\n\t\treturn this._data.root.replace(/^(.+)\\/$/, '$1')\n\t}\n\n\t/**\n\t * Get the absolute path of this object relative to the root\n\t */\n\tget path(): string {\n\t\t// Extract the path part from the source URL\n\t\t// e.g. https://cloud.domain.com/remote.php/dav/files/username/Path/To/File.txt\n\t\tconst idx = this.source.indexOf('://')\n\t\tconst protocol = this.source.slice(0, idx) // e.g. https\n\t\tconst remainder = this.source.slice(idx + 3) // e.g. cloud.domain.com/remote.php/dav/files/username/Path/To/File.txt\n\n\t\tconst slashIndex = remainder.indexOf('/')\n\t\tconst host = remainder.slice(0, slashIndex) // e.g. cloud.domain.com\n\t\tconst rawPath = remainder.slice(slashIndex) // e.g. /remote.php/dav/files/username/Path/To/File.txt\n\n\t\t// Rebuild a safe URL with encoded path\n\t\tconst safeUrl = `${protocol}://${host}${encodePath(rawPath)}`\n\t\tconst url = new URL(safeUrl)\n\n\t\tlet source = decodeURIComponent(url.pathname)\n\n\t\tif (this.isDavResource) {\n\t\t\t// ensure we only work on the real path in case root is not distinct\n\t\t\tsource = source.split(this._knownDavService).pop()!\n\t\t}\n\t\t// Using replace would remove all part matching root\n\t\tconst firstMatch = source.indexOf(this.root)\n\t\t// Ensure we do not remove the leading slash\n\t\tconst root = this.root.replace(/\\/$/, '')\n\t\treturn source.slice(firstMatch + root.length) || '/'\n\t}\n\n\t/**\n\t * Get the node id if defined.\n\t * There is no setter as the fileid is not meant to be changed\n\t */\n\tget fileid(): number | undefined {\n\t\treturn this._data?.id\n\t}\n\n\t/**\n\t * Get the node status.\n\t */\n\tget status(): INodeStatus | undefined {\n\t\treturn this._data?.status\n\t}\n\n\t/**\n\t * Set the node status.\n\t */\n\tset status(status: INodeStatus | undefined) {\n\t\tvalidateData({ ...this._data, status }, this._knownDavService)\n\t\tthis._data.status = status\n\t}\n\n\t/**\n\t * Move the node to a new destination\n\t *\n\t * @param destination the new source.\n\t * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg\n\t */\n\tmove(destination: string) {\n\t\tvalidateData({ ...this._data, source: destination }, this._knownDavService)\n\t\tconst oldBasename = this.basename\n\n\t\tthis._data.source = destination\n\t\t// Check if the displayname and the (old) basename were the same\n\t\t// meaning no special displayname was set but just a fallback to the basename by Nextcloud's WebDAV server\n\t\tif (this.displayname === oldBasename\n\t\t\t&& this.basename !== oldBasename) {\n\t\t\t// We have to assume that the displayname was not set but just a copy of the basename\n\t\t\t// this can not be guaranteed, so to be sure users should better refetch the node\n\t\t\tthis.displayname = this.basename\n\t\t}\n\t}\n\n\t/**\n\t * Rename the node\n\t * This aliases the move method for easier usage\n\t *\n\t * @param basename The new name of the node\n\t */\n\trename(basename: string) {\n\t\tif (basename.includes('/')) {\n\t\t\tthrow new Error('Invalid basename')\n\t\t}\n\t\tthis.move(dirname(this.source) + '/' + basename)\n\t}\n\n\t/**\n\t * Update the mtime if exists\n\t */\n\tupdateMtime() {\n\t\tif (this._data.mtime) {\n\t\t\tthis._data.mtime = new Date()\n\t\t}\n\t}\n\n\t/**\n\t * Update the attributes of the node\n\t * Warning, updating attributes will NOT automatically update the mtime.\n\t *\n\t * @param attributes The new attributes to update on the Node attributes\n\t */\n\tupdate(attributes: Attribute) {\n\t\tfor (const [name, value] of Object.entries(attributes)) {\n\t\t\ttry {\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tdelete this.attributes[name]\n\t\t\t\t} else {\n\t\t\t\t\tthis.attributes[name] = value\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Ignore readonly attributes\n\t\t\t\tif (e instanceof TypeError) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// Throw all other exceptions\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns a clone of the node\n\t */\n\tclone(): this {\n\t\t// @ts-expect-error -- this class is abstract and cannot be instantiated directly but all its children can\n\t\treturn new this.constructor(structuredClone(this._data), this._knownDavService)\n\t}\n\n\t/**\n\t * JSON representation of the node\n\t */\n\ttoJSON(): string {\n\t\treturn JSON.stringify([structuredClone(this._data), this._knownDavService.toString()])\n\t}\n}\n\n/**\n * Interface of the node class\n */\nexport type INode = Pick<Node, keyof Node>\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { NodeConstructorData } from './node.ts'\n\nimport { FileType } from './fileType.ts'\nimport { Node } from './node.ts'\n\nexport class File extends Node {\n\tpublic constructor(...[data, davService]: NodeConstructorData) {\n\t\tsuper(data, davService)\n\t}\n\n\tget type(): typeof FileType.File {\n\t\treturn FileType.File\n\t}\n}\n\n/**\n * Interface of the File class\n */\nexport type IFile = Pick<File, keyof File>\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { NodeConstructorData } from './node.ts'\n\nimport { FileType } from './fileType.ts'\nimport { Node } from './node.ts'\n\nexport class Folder extends Node {\n\tconstructor(...[data, davService]: NodeConstructorData) {\n\t\t// enforcing mimes\n\t\tsuper({\n\t\t\t...data,\n\t\t\tmime: 'httpd/unix-directory',\n\t\t}, davService)\n\t}\n\n\tget type(): typeof FileType.Folder {\n\t\treturn FileType.Folder\n\t}\n\n\tget extension(): null {\n\t\treturn null\n\t}\n\n\tget mime(): 'httpd/unix-directory' {\n\t\treturn 'httpd/unix-directory'\n\t}\n}\n\n/**\n * Interface of the folder class\n */\nexport type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ACd;AAAA,EAEA,IAAI,OAA+B;AAClC,WAAO,SAAS;AAAA,EACjB;AAAA,EAEA,IAAI,YAAkB;AACrB,WAAO;AAAA,EACR;AAAA,EAEA,IAAI,OAA+B;AAClC,WAAO;AAAA,EACR;AACD;"}
|
package/dist/dav.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { getCurrentUser, onRequestTokenUpdate, getRequestToken } from "@nextclou
|
|
|
2
2
|
import { generateRemoteUrl } from "@nextcloud/router";
|
|
3
3
|
import { isPublicShare, getSharingToken } from "@nextcloud/sharing/public";
|
|
4
4
|
import { createClient, getPatcher } from "webdav";
|
|
5
|
-
import { P as Permission, l as logger, c as NodeStatus, a as File, b as Folder } from "./chunks/folder-
|
|
5
|
+
import { P as Permission, s as scopedGlobals, l as logger, c as NodeStatus, a as File, b as Folder } from "./chunks/folder-D9CBQngR.mjs";
|
|
6
|
+
import "@nextcloud/paths";
|
|
6
7
|
/*!
|
|
7
8
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
8
9
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -59,12 +60,10 @@ const defaultDavNamespaces = {
|
|
|
59
60
|
ocs: "http://open-collaboration-services.org/ns"
|
|
60
61
|
};
|
|
61
62
|
function registerDavProperty(prop, namespace = { nc: "http://nextcloud.org/ns" }) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const namespaces = { ...window._nc_dav_namespaces, ...namespace };
|
|
67
|
-
if (window._nc_dav_properties.find((search) => search === prop)) {
|
|
63
|
+
scopedGlobals.davNamespaces ??= { ...defaultDavNamespaces };
|
|
64
|
+
scopedGlobals.davProperties ??= [...defaultDavProperties];
|
|
65
|
+
const namespaces = { ...scopedGlobals.davNamespaces, ...namespace };
|
|
66
|
+
if (scopedGlobals.davProperties.find((search) => search === prop)) {
|
|
68
67
|
logger.warn(`${prop} already registered`, { prop });
|
|
69
68
|
return false;
|
|
70
69
|
}
|
|
@@ -77,21 +76,17 @@ function registerDavProperty(prop, namespace = { nc: "http://nextcloud.org/ns" }
|
|
|
77
76
|
logger.error(`${prop} namespace unknown`, { prop, namespaces });
|
|
78
77
|
return false;
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
scopedGlobals.davProperties.push(prop);
|
|
80
|
+
scopedGlobals.davNamespaces = namespaces;
|
|
82
81
|
return true;
|
|
83
82
|
}
|
|
84
83
|
function getDavProperties() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return window._nc_dav_properties.map((prop) => `<${prop} />`).join(" ");
|
|
84
|
+
scopedGlobals.davProperties ??= [...defaultDavProperties];
|
|
85
|
+
return scopedGlobals.davProperties.map((prop) => `<${prop} />`).join(" ");
|
|
89
86
|
}
|
|
90
87
|
function getDavNameSpaces() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return Object.keys(window._nc_dav_namespaces).map((ns) => `xmlns:${ns}="${window._nc_dav_namespaces?.[ns]}"`).join(" ");
|
|
88
|
+
scopedGlobals.davNamespaces ??= { ...defaultDavNamespaces };
|
|
89
|
+
return Object.keys(scopedGlobals.davNamespaces).map((ns) => `xmlns:${ns}="${scopedGlobals.davNamespaces?.[ns]}"`).join(" ");
|
|
95
90
|
}
|
|
96
91
|
function getDefaultPropfind() {
|
|
97
92
|
return `<?xml version="1.0"?>
|
package/dist/dav.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dav.mjs","sources":["../lib/dav/davPermissions.ts","../lib/dav/davProperties.ts","../lib/dav/dav.ts"],"sourcesContent":["/*!\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { Permission } from '../permissions.ts'\n\n/**\n * Parse the WebDAV permission string to a permission enum\n *\n * @param permString - The DAV permission string\n */\nexport function parsePermissions(permString = ''): number {\n\tlet permissions = Permission.NONE\n\tif (!permString) {\n\t\treturn permissions\n\t}\n\n\tif (permString.includes('G')) {\n\t\tpermissions |= Permission.READ\n\t}\n\tif (permString.includes('W')) {\n\t\tpermissions |= Permission.WRITE\n\t}\n\tif (permString.includes('CK')) {\n\t\tpermissions |= Permission.CREATE\n\t}\n\tif (permString.includes('NV')) {\n\t\tpermissions |= Permission.UPDATE\n\t}\n\tif (permString.includes('D')) {\n\t\tpermissions |= Permission.DELETE\n\t}\n\tif (permString.includes('R')) {\n\t\tpermissions |= Permission.SHARE\n\t}\n\n\treturn permissions\n}\n","/**\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { getCurrentUser } from '@nextcloud/auth'\nimport logger from '../utils/logger.ts'\n\nexport type DavProperty = { [key: string]: string }\n\nexport const defaultDavProperties = [\n\t'd:getcontentlength',\n\t'd:getcontenttype',\n\t'd:getetag',\n\t'd:getlastmodified',\n\t'd:creationdate',\n\t'd:displayname',\n\t'd:quota-available-bytes',\n\t'd:resourcetype',\n\t'nc:has-preview',\n\t'nc:is-encrypted',\n\t'nc:mount-type',\n\t'oc:comments-unread',\n\t'oc:favorite',\n\t'oc:fileid',\n\t'oc:owner-display-name',\n\t'oc:owner-id',\n\t'oc:permissions',\n\t'oc:size',\n]\n\nexport const defaultDavNamespaces = {\n\td: 'DAV:',\n\tnc: 'http://nextcloud.org/ns',\n\toc: 'http://owncloud.org/ns',\n\tocs: 'http://open-collaboration-services.org/ns',\n}\n\n/**\n * Register custom DAV properties\n *\n * Can be used if your app introduces custom DAV properties, so e.g. the files app can make use of it.\n *\n * @param prop The property\n * @param namespace The namespace of the property\n */\nexport function registerDavProperty(prop: string, namespace: DavProperty = { nc: 'http://nextcloud.org/ns' }): boolean {\n\tif (typeof window._nc_dav_properties === 'undefined') {\n\t\twindow._nc_dav_properties = [...defaultDavProperties]\n\t\twindow._nc_dav_namespaces = { ...defaultDavNamespaces }\n\t}\n\n\tconst namespaces = { ...window._nc_dav_namespaces, ...namespace }\n\n\t// Check duplicates\n\tif (window._nc_dav_properties.find((search) => search === prop)) {\n\t\tlogger.warn(`${prop} already registered`, { prop })\n\t\treturn false\n\t}\n\n\tif (prop.startsWith('<') || prop.split(':').length !== 2) {\n\t\tlogger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop })\n\t\treturn false\n\t}\n\n\tconst ns = prop.split(':')[0]\n\tif (!namespaces[ns]) {\n\t\tlogger.error(`${prop} namespace unknown`, { prop, namespaces })\n\t\treturn false\n\t}\n\n\twindow._nc_dav_properties.push(prop)\n\twindow._nc_dav_namespaces = namespaces\n\treturn true\n}\n\n/**\n * Get the registered dav properties\n */\nexport function getDavProperties(): string {\n\tif (typeof window._nc_dav_properties === 'undefined') {\n\t\twindow._nc_dav_properties = [...defaultDavProperties]\n\t}\n\n\treturn window._nc_dav_properties.map((prop) => `<${prop} />`).join(' ')\n}\n\n/**\n * Get the registered dav namespaces\n */\nexport function getDavNameSpaces(): string {\n\tif (typeof window._nc_dav_namespaces === 'undefined') {\n\t\twindow._nc_dav_namespaces = { ...defaultDavNamespaces }\n\t}\n\n\treturn Object.keys(window._nc_dav_namespaces)\n\t\t.map((ns) => `xmlns:${ns}=\"${window._nc_dav_namespaces?.[ns]}\"`)\n\t\t.join(' ')\n}\n\n/**\n * Get the default PROPFIND request body\n */\nexport function getDefaultPropfind(): string {\n\treturn `<?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}\n\n/**\n * Get the REPORT body to filter for favorite nodes\n */\nexport function getFavoritesReport(): string {\n\treturn `<?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}\n\n/**\n * Get the SEARCH body to search for recently modified files\n *\n * @param lastModified Oldest timestamp to include (Unix timestamp)\n * @example\n * ```ts\n * // SEARCH for recent files need a different DAV endpoint\n * const client = davGetClient(generateRemoteUrl('dav'))\n * // Timestamp of last week\n * const lastWeek = Math.round(Date.now() / 1000) - (60 * 60 * 24 * 7)\n * const contentsResponse = await client.getDirectoryContents(path, {\n * details: true,\n * data: davGetRecentSearch(lastWeek),\n * headers: {\n * method: 'SEARCH',\n * 'Content-Type': 'application/xml; charset=utf-8',\n * },\n * deep: true,\n * }) as ResponseDataDetailed<FileStat[]>\n * ```\n */\nexport function getRecentSearch(lastModified: number): string {\n\treturn `<?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}\n","/*\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { DAVResultResponseProps, FileStat, ResponseDataDetailed, WebDAVClient } from 'webdav'\nimport type { Node, NodeData } from '../node/index.ts'\n\nimport { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'\nimport { generateRemoteUrl } from '@nextcloud/router'\nimport { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'\nimport { createClient, getPatcher } from 'webdav'\nimport { File, Folder, NodeStatus } from '../node/index.ts'\nimport { parsePermissions } from './davPermissions.ts'\nimport { getFavoritesReport } from './davProperties.ts'\n\n/**\n * Nextcloud DAV result response\n */\ninterface ResponseProps extends DAVResultResponseProps {\n\tcreationdate: string\n\tpermissions: string\n\tmime: string\n\tfileid: number\n\tsize: number\n\t'owner-id': string | number\n}\n\n/**\n * Get the DAV root path for the current user or public share\n */\nexport function getRootPath(): string {\n\tif (isPublicShare()) {\n\t\treturn `/files/${getSharingToken()}`\n\t}\n\treturn `/files/${getCurrentUser()?.uid}`\n}\n\n/**\n * The DAV root path for the current user\n * This is a cached version of `getRemoteURL`\n */\nexport const defaultRootPath = getRootPath()\n\n/**\n * Get the DAV remote URL used as base URL for the WebDAV client\n * It also handles public shares\n */\nexport function getRemoteURL(): string {\n\tconst url = generateRemoteUrl('dav')\n\tif (isPublicShare()) {\n\t\treturn url.replace('remote.php', 'public.php')\n\t}\n\treturn url\n}\n\n/**\n * The DAV remote URL used as base URL for the WebDAV client\n * This is a cached version of `getRemoteURL`\n */\nexport const defaultRemoteURL = getRemoteURL()\n\n/**\n * Get a WebDAV client configured to include the Nextcloud request token\n *\n * @param remoteURL The DAV server remote URL\n * @param headers Optional additional headers to set for every request\n */\nexport function getClient(remoteURL = defaultRemoteURL, headers: Record<string, string> = {}) {\n\tconst client = createClient(remoteURL, { headers })\n\n\t/**\n\t * Set headers for DAV requests\n\t *\n\t * @param token CSRF token\n\t */\n\tfunction setHeaders(token: string | null) {\n\t\tclient.setHeaders({\n\t\t\t...headers,\n\t\t\t// Add this so the server knows it is an request from the browser\n\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t// Inject user auth\n\t\t\trequesttoken: token ?? '',\n\t\t})\n\t}\n\n\t// refresh headers when request token changes\n\tonRequestTokenUpdate(setHeaders)\n\tsetHeaders(getRequestToken())\n\n\t/**\n\t * Allow to override the METHOD to support dav REPORT\n\t *\n\t * @see https://github.com/perry-mitchell/webdav-client/blob/8d9694613c978ce7404e26a401c39a41f125f87f/source/request.ts\n\t */\n\tconst patcher = getPatcher()\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore\n\t// https://github.com/perry-mitchell/hot-patcher/issues/6\n\tpatcher.patch('fetch', (url: string, options: RequestInit): Promise<Response> => {\n\t\tconst headers = options.headers as Record<string, string>\n\t\tif (headers?.method) {\n\t\t\toptions.method = headers.method\n\t\t\tdelete headers.method\n\t\t}\n\t\treturn fetch(url, options)\n\t})\n\n\treturn client\n}\n\n/**\n * Use WebDAV to query for favorite Nodes\n *\n * @param options - Options for the favorite query\n * @param options.client - The WebDAV client to use for performing the request\n * @param options.path - Base path for the favorites, if unset all favorites are queried\n * @param options.davRoot - The root path for the DAV user (defaults to `defaultRootPath`)\n * @param options.signal - Optional abort signal to cancel the request\n *\n * @example\n * ```js\n * import { getFavoriteNodes } from '@nextcloud/files'\n *\n * // query favorites for the root\n * const favorites = await getFavoriteNodes()\n * ```\n * @example\n * ```js\n * // Advanced usage with custom client and path\n * import { getClient, defaultRootPath, getFavoriteNodes } from '@nextcloud/files'\n *\n * const client = getClient()\n * const controller = new AbortController()\n * const favoritesPromise = getFavoriteNodes({ client, path: '/some/folder', signal: controller.signal })\n * // you can abort the request if needed\n * controller.abort()\n * // or await the result\n * const favorites = await favoritesPromise\n * ```\n */\nexport async function getFavoriteNodes(options: { client?: WebDAVClient, path?: string, davRoot?: string, signal?: AbortSignal } = {}): Promise<Node[]> {\n\tconst client = options.client ?? getClient()\n\tconst path = options.path ?? '/'\n\tconst davRoot = options.davRoot ?? defaultRootPath\n\n\tconst contentsResponse = await client.getDirectoryContents(`${davRoot}${path}`, {\n\t\tsignal: options.signal,\n\t\tdetails: true,\n\t\tdata: getFavoritesReport(),\n\t\theaders: {\n\t\t\t// see getClient for patched webdav client\n\t\t\tmethod: 'REPORT',\n\t\t},\n\t\tincludeSelf: true,\n\t}) as ResponseDataDetailed<FileStat[]>\n\n\treturn contentsResponse.data\n\t\t.filter((node) => node.filename !== path) // exclude current dir\n\t\t.map((result) => resultToNode(result, davRoot))\n}\n\n/**\n * Convert DAV result `FileStat` to `Node`\n *\n * @param node The DAV result\n * @param filesRoot The DAV files root path\n * @param remoteURL The DAV server remote URL (same as on `getClient`)\n */\nexport function resultToNode(node: FileStat, filesRoot = defaultRootPath, remoteURL = defaultRemoteURL): Node {\n\tlet userId = getCurrentUser()?.uid\n\tif (isPublicShare()) {\n\t\tuserId = userId ?? 'anonymous'\n\t} else if (!userId) {\n\t\tthrow new Error('No user id found')\n\t}\n\n\tconst props = node.props as ResponseProps\n\tconst permissions = parsePermissions(props?.permissions)\n\tconst owner = String(props?.['owner-id'] || userId)\n\tconst id = props.fileid || 0\n\n\tconst mtime = new Date(Date.parse(node.lastmod))\n\tconst crtime = new Date(Date.parse(props.creationdate))\n\n\tconst nodeData: NodeData = {\n\t\tid,\n\t\tsource: `${remoteURL}${node.filename}`,\n\t\tmtime: !isNaN(mtime.getTime()) && mtime.getTime() !== 0 ? mtime : undefined,\n\t\tcrtime: !isNaN(crtime.getTime()) && crtime.getTime() !== 0 ? crtime : undefined,\n\t\tmime: node.mime || 'application/octet-stream',\n\t\t// Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380\n\t\tdisplayname: props.displayname !== undefined ? String(props.displayname) : undefined,\n\t\tsize: props?.size || Number.parseInt(props.getcontentlength || '0'),\n\t\t// The fileid is set to -1 for failed requests\n\t\tstatus: id < 0 ? NodeStatus.FAILED : undefined,\n\t\tpermissions,\n\t\towner,\n\t\troot: filesRoot,\n\t\tattributes: {\n\t\t\t...node,\n\t\t\t...props,\n\t\t\thasPreview: props?.['has-preview'],\n\t\t},\n\t}\n\n\tdelete nodeData.attributes?.props\n\n\treturn node.type === 'file' ? new File(nodeData) : new Folder(nodeData)\n}\n"],"names":["headers"],"mappings":";;;;;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,iBAAiB,aAAa,IAAY;AACzD,MAAI,cAAc,WAAW;AAC7B,MAAI,CAAC,YAAY;AAChB,WAAO;AAAA,EACR;AAEA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,IAAI,GAAG;AAC9B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,IAAI,GAAG;AAC9B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,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;AAAA,EACpB,WAAW,CAAC,QAAQ;AACnB,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACnC;AAEA,QAAM,QAAQ,KAAK;AACnB,QAAM,cAAc,iBAAiB,OAAO,WAAW;AACvD,QAAM,QAAQ,OAAO,QAAQ,UAAU,KAAK,MAAM;AAClD,QAAM,KAAK,MAAM,UAAU;AAE3B,QAAM,QAAQ,IAAI,KAAK,KAAK,MAAM,KAAK,OAAO,CAAC;AAC/C,QAAM,SAAS,IAAI,KAAK,KAAK,MAAM,MAAM,YAAY,CAAC;AAEtD,QAAM,WAAqB;AAAA,IAC1B;AAAA,IACA,QAAQ,GAAG,SAAS,GAAG,KAAK,QAAQ;AAAA,IACpC,OAAO,CAAC,MAAM,MAAM,QAAA,CAAS,KAAK,MAAM,QAAA,MAAc,IAAI,QAAQ;AAAA,IAClE,QAAQ,CAAC,MAAM,OAAO,QAAA,CAAS,KAAK,OAAO,QAAA,MAAc,IAAI,SAAS;AAAA,IACtE,MAAM,KAAK,QAAQ;AAAA;AAAA,IAEnB,aAAa,MAAM,gBAAgB,SAAY,OAAO,MAAM,WAAW,IAAI;AAAA,IAC3E,MAAM,OAAO,QAAQ,OAAO,SAAS,MAAM,oBAAoB,GAAG;AAAA;AAAA,IAElE,QAAQ,KAAK,IAAI,WAAW,SAAS;AAAA,IACrC;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,YAAY;AAAA,MACX,GAAG;AAAA,MACH,GAAG;AAAA,MACH,YAAY,QAAQ,aAAa;AAAA,IAAA;AAAA,EAClC;AAGD,SAAO,SAAS,YAAY;AAE5B,SAAO,KAAK,SAAS,SAAS,IAAI,KAAK,QAAQ,IAAI,IAAI,OAAO,QAAQ;AACvE;"}
|
|
1
|
+
{"version":3,"file":"dav.mjs","sources":["../lib/dav/davPermissions.ts","../lib/dav/davProperties.ts","../lib/dav/dav.ts"],"sourcesContent":["/*!\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { Permission } from '../permissions.ts'\n\n/**\n * Parse the WebDAV permission string to a permission enum\n *\n * @param permString - The DAV permission string\n */\nexport function parsePermissions(permString = ''): number {\n\tlet permissions = Permission.NONE\n\tif (!permString) {\n\t\treturn permissions\n\t}\n\n\tif (permString.includes('G')) {\n\t\tpermissions |= Permission.READ\n\t}\n\tif (permString.includes('W')) {\n\t\tpermissions |= Permission.WRITE\n\t}\n\tif (permString.includes('CK')) {\n\t\tpermissions |= Permission.CREATE\n\t}\n\tif (permString.includes('NV')) {\n\t\tpermissions |= Permission.UPDATE\n\t}\n\tif (permString.includes('D')) {\n\t\tpermissions |= Permission.DELETE\n\t}\n\tif (permString.includes('R')) {\n\t\tpermissions |= Permission.SHARE\n\t}\n\n\treturn permissions\n}\n","/**\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { getCurrentUser } from '@nextcloud/auth'\nimport { scopedGlobals } from '../globalScope.ts'\nimport logger from '../utils/logger.ts'\n\nexport type DavProperty = { [key: string]: string }\n\nexport const defaultDavProperties = [\n\t'd:getcontentlength',\n\t'd:getcontenttype',\n\t'd:getetag',\n\t'd:getlastmodified',\n\t'd:creationdate',\n\t'd:displayname',\n\t'd:quota-available-bytes',\n\t'd:resourcetype',\n\t'nc:has-preview',\n\t'nc:is-encrypted',\n\t'nc:mount-type',\n\t'oc:comments-unread',\n\t'oc:favorite',\n\t'oc:fileid',\n\t'oc:owner-display-name',\n\t'oc:owner-id',\n\t'oc:permissions',\n\t'oc:size',\n]\n\nexport const defaultDavNamespaces = {\n\td: 'DAV:',\n\tnc: 'http://nextcloud.org/ns',\n\toc: 'http://owncloud.org/ns',\n\tocs: 'http://open-collaboration-services.org/ns',\n}\n\n/**\n * Register custom DAV properties\n *\n * Can be used if your app introduces custom DAV properties, so e.g. the files app can make use of it.\n *\n * @param prop The property\n * @param namespace The namespace of the property\n */\nexport function registerDavProperty(prop: string, namespace: DavProperty = { nc: 'http://nextcloud.org/ns' }): boolean {\n\tscopedGlobals.davNamespaces ??= { ...defaultDavNamespaces }\n\tscopedGlobals.davProperties ??= [...defaultDavProperties]\n\n\tconst namespaces = { ...scopedGlobals.davNamespaces, ...namespace }\n\n\t// Check duplicates\n\tif (scopedGlobals.davProperties.find((search) => search === prop)) {\n\t\tlogger.warn(`${prop} already registered`, { prop })\n\t\treturn false\n\t}\n\n\tif (prop.startsWith('<') || prop.split(':').length !== 2) {\n\t\tlogger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop })\n\t\treturn false\n\t}\n\n\tconst ns = prop.split(':')[0]\n\tif (!namespaces[ns]) {\n\t\tlogger.error(`${prop} namespace unknown`, { prop, namespaces })\n\t\treturn false\n\t}\n\n\tscopedGlobals.davProperties.push(prop)\n\tscopedGlobals.davNamespaces = namespaces\n\treturn true\n}\n\n/**\n * Get the registered dav properties\n */\nexport function getDavProperties(): string {\n\tscopedGlobals.davProperties ??= [...defaultDavProperties]\n\treturn scopedGlobals.davProperties.map((prop) => `<${prop} />`).join(' ')\n}\n\n/**\n * Get the registered dav namespaces\n */\nexport function getDavNameSpaces(): string {\n\tscopedGlobals.davNamespaces ??= { ...defaultDavNamespaces }\n\treturn Object.keys(scopedGlobals.davNamespaces)\n\t\t.map((ns) => `xmlns:${ns}=\"${scopedGlobals.davNamespaces?.[ns]}\"`)\n\t\t.join(' ')\n}\n\n/**\n * Get the default PROPFIND request body\n */\nexport function getDefaultPropfind(): string {\n\treturn `<?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}\n\n/**\n * Get the REPORT body to filter for favorite nodes\n */\nexport function getFavoritesReport(): string {\n\treturn `<?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}\n\n/**\n * Get the SEARCH body to search for recently modified files\n *\n * @param lastModified Oldest timestamp to include (Unix timestamp)\n * @example\n * ```ts\n * // SEARCH for recent files need a different DAV endpoint\n * const client = davGetClient(generateRemoteUrl('dav'))\n * // Timestamp of last week\n * const lastWeek = Math.round(Date.now() / 1000) - (60 * 60 * 24 * 7)\n * const contentsResponse = await client.getDirectoryContents(path, {\n * details: true,\n * data: davGetRecentSearch(lastWeek),\n * headers: {\n * method: 'SEARCH',\n * 'Content-Type': 'application/xml; charset=utf-8',\n * },\n * deep: true,\n * }) as ResponseDataDetailed<FileStat[]>\n * ```\n */\nexport function getRecentSearch(lastModified: number): string {\n\treturn `<?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}\n","/*\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { DAVResultResponseProps, FileStat, ResponseDataDetailed, WebDAVClient } from 'webdav'\nimport type { Node, NodeData } from '../node/index.ts'\n\nimport { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'\nimport { generateRemoteUrl } from '@nextcloud/router'\nimport { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'\nimport { createClient, getPatcher } from 'webdav'\nimport { File, Folder, NodeStatus } from '../node/index.ts'\nimport { parsePermissions } from './davPermissions.ts'\nimport { getFavoritesReport } from './davProperties.ts'\n\n/**\n * Nextcloud DAV result response\n */\ninterface ResponseProps extends DAVResultResponseProps {\n\tcreationdate: string\n\tpermissions: string\n\tmime: string\n\tfileid: number\n\tsize: number\n\t'owner-id': string | number\n}\n\n/**\n * Get the DAV root path for the current user or public share\n */\nexport function getRootPath(): string {\n\tif (isPublicShare()) {\n\t\treturn `/files/${getSharingToken()}`\n\t}\n\treturn `/files/${getCurrentUser()?.uid}`\n}\n\n/**\n * The DAV root path for the current user\n * This is a cached version of `getRemoteURL`\n */\nexport const defaultRootPath = getRootPath()\n\n/**\n * Get the DAV remote URL used as base URL for the WebDAV client\n * It also handles public shares\n */\nexport function getRemoteURL(): string {\n\tconst url = generateRemoteUrl('dav')\n\tif (isPublicShare()) {\n\t\treturn url.replace('remote.php', 'public.php')\n\t}\n\treturn url\n}\n\n/**\n * The DAV remote URL used as base URL for the WebDAV client\n * This is a cached version of `getRemoteURL`\n */\nexport const defaultRemoteURL = getRemoteURL()\n\n/**\n * Get a WebDAV client configured to include the Nextcloud request token\n *\n * @param remoteURL The DAV server remote URL\n * @param headers Optional additional headers to set for every request\n */\nexport function getClient(remoteURL = defaultRemoteURL, headers: Record<string, string> = {}) {\n\tconst client = createClient(remoteURL, { headers })\n\n\t/**\n\t * Set headers for DAV requests\n\t *\n\t * @param token CSRF token\n\t */\n\tfunction setHeaders(token: string | null) {\n\t\tclient.setHeaders({\n\t\t\t...headers,\n\t\t\t// Add this so the server knows it is an request from the browser\n\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t// Inject user auth\n\t\t\trequesttoken: token ?? '',\n\t\t})\n\t}\n\n\t// refresh headers when request token changes\n\tonRequestTokenUpdate(setHeaders)\n\tsetHeaders(getRequestToken())\n\n\t/**\n\t * Allow to override the METHOD to support dav REPORT\n\t *\n\t * @see https://github.com/perry-mitchell/webdav-client/blob/8d9694613c978ce7404e26a401c39a41f125f87f/source/request.ts\n\t */\n\tconst patcher = getPatcher()\n\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t// @ts-ignore\n\t// https://github.com/perry-mitchell/hot-patcher/issues/6\n\tpatcher.patch('fetch', (url: string, options: RequestInit): Promise<Response> => {\n\t\tconst headers = options.headers as Record<string, string>\n\t\tif (headers?.method) {\n\t\t\toptions.method = headers.method\n\t\t\tdelete headers.method\n\t\t}\n\t\treturn fetch(url, options)\n\t})\n\n\treturn client\n}\n\n/**\n * Use WebDAV to query for favorite Nodes\n *\n * @param options - Options for the favorite query\n * @param options.client - The WebDAV client to use for performing the request\n * @param options.path - Base path for the favorites, if unset all favorites are queried\n * @param options.davRoot - The root path for the DAV user (defaults to `defaultRootPath`)\n * @param options.signal - Optional abort signal to cancel the request\n *\n * @example\n * ```js\n * import { getFavoriteNodes } from '@nextcloud/files'\n *\n * // query favorites for the root\n * const favorites = await getFavoriteNodes()\n * ```\n * @example\n * ```js\n * // Advanced usage with custom client and path\n * import { getClient, defaultRootPath, getFavoriteNodes } from '@nextcloud/files'\n *\n * const client = getClient()\n * const controller = new AbortController()\n * const favoritesPromise = getFavoriteNodes({ client, path: '/some/folder', signal: controller.signal })\n * // you can abort the request if needed\n * controller.abort()\n * // or await the result\n * const favorites = await favoritesPromise\n * ```\n */\nexport async function getFavoriteNodes(options: { client?: WebDAVClient, path?: string, davRoot?: string, signal?: AbortSignal } = {}): Promise<Node[]> {\n\tconst client = options.client ?? getClient()\n\tconst path = options.path ?? '/'\n\tconst davRoot = options.davRoot ?? defaultRootPath\n\n\tconst contentsResponse = await client.getDirectoryContents(`${davRoot}${path}`, {\n\t\tsignal: options.signal,\n\t\tdetails: true,\n\t\tdata: getFavoritesReport(),\n\t\theaders: {\n\t\t\t// see getClient for patched webdav client\n\t\t\tmethod: 'REPORT',\n\t\t},\n\t\tincludeSelf: true,\n\t}) as ResponseDataDetailed<FileStat[]>\n\n\treturn contentsResponse.data\n\t\t.filter((node) => node.filename !== path) // exclude current dir\n\t\t.map((result) => resultToNode(result, davRoot))\n}\n\n/**\n * Convert DAV result `FileStat` to `Node`\n *\n * @param node The DAV result\n * @param filesRoot The DAV files root path\n * @param remoteURL The DAV server remote URL (same as on `getClient`)\n */\nexport function resultToNode(node: FileStat, filesRoot = defaultRootPath, remoteURL = defaultRemoteURL): Node {\n\tlet userId = getCurrentUser()?.uid\n\tif (isPublicShare()) {\n\t\tuserId = userId ?? 'anonymous'\n\t} else if (!userId) {\n\t\tthrow new Error('No user id found')\n\t}\n\n\tconst props = node.props as ResponseProps\n\tconst permissions = parsePermissions(props?.permissions)\n\tconst owner = String(props?.['owner-id'] || userId)\n\tconst id = props.fileid || 0\n\n\tconst mtime = new Date(Date.parse(node.lastmod))\n\tconst crtime = new Date(Date.parse(props.creationdate))\n\n\tconst nodeData: NodeData = {\n\t\tid,\n\t\tsource: `${remoteURL}${node.filename}`,\n\t\tmtime: !isNaN(mtime.getTime()) && mtime.getTime() !== 0 ? mtime : undefined,\n\t\tcrtime: !isNaN(crtime.getTime()) && crtime.getTime() !== 0 ? crtime : undefined,\n\t\tmime: node.mime || 'application/octet-stream',\n\t\t// Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380\n\t\tdisplayname: props.displayname !== undefined ? String(props.displayname) : undefined,\n\t\tsize: props?.size || Number.parseInt(props.getcontentlength || '0'),\n\t\t// The fileid is set to -1 for failed requests\n\t\tstatus: id < 0 ? NodeStatus.FAILED : undefined,\n\t\tpermissions,\n\t\towner,\n\t\troot: filesRoot,\n\t\tattributes: {\n\t\t\t...node,\n\t\t\t...props,\n\t\t\thasPreview: props?.['has-preview'],\n\t\t},\n\t}\n\n\tdelete nodeData.attributes?.props\n\n\treturn node.type === 'file' ? new File(nodeData) : new Folder(nodeData)\n}\n"],"names":["headers"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,iBAAiB,aAAa,IAAY;AACzD,MAAI,cAAc,WAAW;AAC7B,MAAI,CAAC,YAAY;AAChB,WAAO;AAAA,EACR;AAEA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,IAAI,GAAG;AAC9B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,IAAI,GAAG;AAC9B,mBAAe,WAAW;AAAA,EAC3B;AACA,MAAI,WAAW,SAAS,GAAG,GAAG;AAC7B,m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AAQ,KAAK;AACnB,QAAM,cAAc,iBAAiB,OAAO,WAAW;AACvD,QAAM,QAAQ,OAAO,QAAQ,UAAU,KAAK,MAAM;AAClD,QAAM,KAAK,MAAM,UAAU;AAE3B,QAAM,QAAQ,IAAI,KAAK,KAAK,MAAM,KAAK,OAAO,CAAC;AAC/C,QAAM,SAAS,IAAI,KAAK,KAAK,MAAM,MAAM,YAAY,CAAC;AAEtD,QAAM,WAAqB;AAAA,IAC1B;AAAA,IACA,QAAQ,GAAG,SAAS,GAAG,KAAK,QAAQ;AAAA,IACpC,OAAO,CAAC,MAAM,MAAM,QAAA,CAAS,KAAK,MAAM,QAAA,MAAc,IAAI,QAAQ;AAAA,IAClE,QAAQ,CAAC,MAAM,OAAO,QAAA,CAAS,KAAK,OAAO,QAAA,MAAc,IAAI,SAAS;AAAA,IACtE,MAAM,KAAK,QAAQ;AAAA;AAAA,IAEnB,aAAa,MAAM,gBAAgB,SAAY,OAAO,MAAM,WAAW,IAAI;AAAA,IAC3E,MAAM,OAAO,QAAQ,OAAO,SAAS,MAAM,oBAAoB,GAAG;AAAA;AAAA,IAElE,QAAQ,KAAK,IAAI,WAAW,SAAS;AAAA,IACrC;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,YAAY;AAAA,MACX,GAAG;AAAA,MACH,GAAG;AAAA,MACH,YAAY,QAAQ,aAAa;AAAA,IAAA;AAAA,EAClC;AAGD,SAAO,SAAS,YAAY;AAE5B,SAAO,KAAK,SAAS,SAAS,IAAI,KAAK,QAAQ,IAAI,IAAI,OAAO,QAAQ;AACvE;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IFileAction, IFileListAction } from './actions/index.ts';
|
|
2
|
+
import { DavProperty } from './dav/index.ts';
|
|
3
|
+
import { IFileListFilter, IFileListHeader, Navigation, NewMenu } from './index.ts';
|
|
4
|
+
import { FilesRegistry } from './registry.ts';
|
|
5
|
+
import { ISidebarTab } from './sidebar/index.ts';
|
|
6
|
+
import { ISidebarAction } from './sidebar/SidebarAction.ts';
|
|
7
|
+
interface InternalGlobalScope {
|
|
8
|
+
davNamespaces?: DavProperty;
|
|
9
|
+
davProperties?: string[];
|
|
10
|
+
newFileMenu?: NewMenu;
|
|
11
|
+
navigation?: Navigation;
|
|
12
|
+
registry?: FilesRegistry;
|
|
13
|
+
fileActions?: Map<string, IFileAction>;
|
|
14
|
+
fileListActions?: Map<string, IFileListAction>;
|
|
15
|
+
fileListFilters?: Map<string, IFileListFilter>;
|
|
16
|
+
fileListHeaders?: Map<string, IFileListHeader>;
|
|
17
|
+
filesSidebarActions?: Map<string, ISidebarAction>;
|
|
18
|
+
filesSidebarTabs?: Map<string, ISidebarTab>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the global scope for the files library.
|
|
22
|
+
* This is used to store global variables scoped to prevent breaking changes in the future.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export declare const scopedGlobals: InternalGlobalScope;
|
|
27
|
+
export {};
|
package/dist/headers/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IView } from '../navigation/view.ts';
|
|
2
2
|
import { IFolder } from '../node/folder.ts';
|
|
3
|
-
export interface
|
|
3
|
+
export interface IFileListHeader {
|
|
4
4
|
/** Unique ID */
|
|
5
5
|
id: string;
|
|
6
6
|
/** Order */
|
|
@@ -12,13 +12,13 @@ export interface HeaderData {
|
|
|
12
12
|
/** Executed when root folder changed */
|
|
13
13
|
updated(folder: IFolder, view: IView): void;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Register a new file list header.
|
|
17
|
+
*
|
|
18
|
+
* @param header - The header to register
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerFileListHeader(header: IFileListHeader): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get all currently registered file list headers.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFileListHeaders(): IFileListHeader[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { s as scopedGlobals, l as logger, F as FileType } from "./chunks/folder-D9CBQngR.mjs";
|
|
2
|
+
import { a, b, N, c, P } from "./chunks/folder-D9CBQngR.mjs";
|
|
1
3
|
import { TypedEventTarget } from "typescript-event-target";
|
|
2
|
-
import { l as logger, F as FileType } from "./chunks/folder-CeyZUHai.mjs";
|
|
3
|
-
import { a, b, N, c, P } from "./chunks/folder-CeyZUHai.mjs";
|
|
4
4
|
import isSvg from "is-svg";
|
|
5
5
|
import { getCapabilities } from "@nextcloud/capabilities";
|
|
6
6
|
import { extname, basename } from "@nextcloud/paths";
|
|
7
7
|
import { getCanonicalLocale, getLanguage } from "@nextcloud/l10n";
|
|
8
|
-
class
|
|
8
|
+
class FilesRegistry extends TypedEventTarget {
|
|
9
9
|
}
|
|
10
10
|
function getRegistry() {
|
|
11
|
-
|
|
12
|
-
return
|
|
11
|
+
scopedGlobals.registry ??= new FilesRegistry();
|
|
12
|
+
return scopedGlobals.registry;
|
|
13
13
|
}
|
|
14
14
|
function getFilesRegistry() {
|
|
15
15
|
return getRegistry();
|
|
@@ -20,16 +20,19 @@ const DefaultType = Object.freeze({
|
|
|
20
20
|
});
|
|
21
21
|
function registerFileAction(action) {
|
|
22
22
|
validateAction$1(action);
|
|
23
|
-
|
|
24
|
-
if (
|
|
23
|
+
scopedGlobals.fileActions ??= /* @__PURE__ */ new Map();
|
|
24
|
+
if (scopedGlobals.fileActions.has(action.id)) {
|
|
25
25
|
logger.error(`FileAction ${action.id} already registered`, { action });
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
scopedGlobals.fileActions.set(action.id, action);
|
|
29
29
|
getRegistry().dispatchTypedEvent("register:action", new CustomEvent("register:action", { detail: action }));
|
|
30
30
|
}
|
|
31
31
|
function getFileActions() {
|
|
32
|
-
|
|
32
|
+
if (scopedGlobals.fileActions) {
|
|
33
|
+
return [...scopedGlobals.fileActions.values()];
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
33
36
|
}
|
|
34
37
|
function validateAction$1(action) {
|
|
35
38
|
if (!action.id || typeof action.id !== "string") {
|
|
@@ -85,16 +88,19 @@ function validateAction$1(action) {
|
|
|
85
88
|
}
|
|
86
89
|
function registerFileListAction(action) {
|
|
87
90
|
validateAction(action);
|
|
88
|
-
|
|
89
|
-
if (
|
|
91
|
+
scopedGlobals.fileListActions ??= /* @__PURE__ */ new Map();
|
|
92
|
+
if (scopedGlobals.fileListActions.has(action.id)) {
|
|
90
93
|
logger.error(`FileListAction with id "${action.id}" is already registered`, { action });
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
|
|
96
|
+
scopedGlobals.fileListActions.set(action.id, action);
|
|
94
97
|
getRegistry().dispatchTypedEvent("register:listAction", new CustomEvent("register:listAction", { detail: action }));
|
|
95
98
|
}
|
|
96
99
|
function getFileListActions() {
|
|
97
|
-
|
|
100
|
+
if (scopedGlobals.fileListActions) {
|
|
101
|
+
return [...scopedGlobals.fileListActions.values()];
|
|
102
|
+
}
|
|
103
|
+
return [];
|
|
98
104
|
}
|
|
99
105
|
function validateAction(action) {
|
|
100
106
|
if (!action.id || typeof action.id !== "string") {
|
|
@@ -121,25 +127,24 @@ function validateAction(action) {
|
|
|
121
127
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
122
128
|
*/
|
|
123
129
|
function registerFileListFilter(filter) {
|
|
124
|
-
|
|
125
|
-
if (
|
|
130
|
+
scopedGlobals.fileListFilters ??= /* @__PURE__ */ new Map();
|
|
131
|
+
if (scopedGlobals.fileListFilters.has(filter.id)) {
|
|
126
132
|
throw new Error(`File list filter "${filter.id}" already registered`);
|
|
127
133
|
}
|
|
128
|
-
|
|
134
|
+
scopedGlobals.fileListFilters.set(filter.id, filter);
|
|
129
135
|
getRegistry().dispatchTypedEvent("register:listFilter", new CustomEvent("register:listFilter", { detail: filter }));
|
|
130
136
|
}
|
|
131
137
|
function unregisterFileListFilter(filterId) {
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
getRegistry().dispatchTypedEvent("unregister:listFilter", new CustomEvent("unregister:listFilter", { detail: filter }));
|
|
138
|
+
if (scopedGlobals.fileListFilters && scopedGlobals.fileListFilters.has(filterId)) {
|
|
139
|
+
scopedGlobals.fileListFilters.delete(filterId);
|
|
140
|
+
getRegistry().dispatchTypedEvent("unregister:listFilter", new CustomEvent("unregister:listFilter", { detail: filterId }));
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
function getFileListFilters() {
|
|
139
|
-
if (
|
|
140
|
-
return [];
|
|
144
|
+
if (scopedGlobals.fileListFilters) {
|
|
145
|
+
return [...scopedGlobals.fileListFilters.values()];
|
|
141
146
|
}
|
|
142
|
-
return [
|
|
147
|
+
return [];
|
|
143
148
|
}
|
|
144
149
|
/*!
|
|
145
150
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
@@ -163,63 +168,38 @@ class FileListFilter extends TypedEventTarget {
|
|
|
163
168
|
this.dispatchTypedEvent("update:filter", new CustomEvent("update:filter"));
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this._header = header;
|
|
171
|
-
}
|
|
172
|
-
get id() {
|
|
173
|
-
return this._header.id;
|
|
174
|
-
}
|
|
175
|
-
get order() {
|
|
176
|
-
return this._header.order;
|
|
177
|
-
}
|
|
178
|
-
get enabled() {
|
|
179
|
-
return this._header.enabled;
|
|
180
|
-
}
|
|
181
|
-
get render() {
|
|
182
|
-
return this._header.render;
|
|
183
|
-
}
|
|
184
|
-
get updated() {
|
|
185
|
-
return this._header.updated;
|
|
186
|
-
}
|
|
187
|
-
validateHeader(header) {
|
|
188
|
-
if (!header.id || !header.render || !header.updated) {
|
|
189
|
-
throw new Error("Invalid header: id, render and updated are required");
|
|
190
|
-
}
|
|
191
|
-
if (typeof header.id !== "string") {
|
|
192
|
-
throw new Error("Invalid id property");
|
|
193
|
-
}
|
|
194
|
-
if (header.enabled !== void 0 && typeof header.enabled !== "function") {
|
|
195
|
-
throw new Error("Invalid enabled property");
|
|
196
|
-
}
|
|
197
|
-
if (header.render && typeof header.render !== "function") {
|
|
198
|
-
throw new Error("Invalid render property");
|
|
199
|
-
}
|
|
200
|
-
if (header.updated && typeof header.updated !== "function") {
|
|
201
|
-
throw new Error("Invalid updated property");
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function registerFileListHeaders(header) {
|
|
206
|
-
if (typeof window._nc_filelistheader === "undefined") {
|
|
207
|
-
window._nc_filelistheader = [];
|
|
208
|
-
logger.debug("FileListHeaders initialized");
|
|
209
|
-
}
|
|
210
|
-
if (window._nc_filelistheader.find((search) => search.id === header.id)) {
|
|
171
|
+
function registerFileListHeader(header) {
|
|
172
|
+
validateHeader(header);
|
|
173
|
+
scopedGlobals.fileListHeaders ??= /* @__PURE__ */ new Map();
|
|
174
|
+
if (scopedGlobals.fileListHeaders.has(header.id)) {
|
|
211
175
|
logger.error(`Header ${header.id} already registered`, { header });
|
|
212
176
|
return;
|
|
213
177
|
}
|
|
214
|
-
|
|
178
|
+
scopedGlobals.fileListHeaders.set(header.id, header);
|
|
215
179
|
getRegistry().dispatchTypedEvent("register:listHeader", new CustomEvent("register:listHeader", { detail: header }));
|
|
216
180
|
}
|
|
217
181
|
function getFileListHeaders() {
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
|
|
182
|
+
if (!scopedGlobals.fileListHeaders) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
return [...scopedGlobals.fileListHeaders.values()];
|
|
186
|
+
}
|
|
187
|
+
function validateHeader(header) {
|
|
188
|
+
if (!header.id || !header.render || !header.updated) {
|
|
189
|
+
throw new Error("Invalid header: id, render and updated are required");
|
|
190
|
+
}
|
|
191
|
+
if (typeof header.id !== "string") {
|
|
192
|
+
throw new Error("Invalid id property");
|
|
193
|
+
}
|
|
194
|
+
if (header.enabled !== void 0 && typeof header.enabled !== "function") {
|
|
195
|
+
throw new Error("Invalid enabled property");
|
|
196
|
+
}
|
|
197
|
+
if (header.render && typeof header.render !== "function") {
|
|
198
|
+
throw new Error("Invalid render property");
|
|
199
|
+
}
|
|
200
|
+
if (header.updated && typeof header.updated !== "function") {
|
|
201
|
+
throw new Error("Invalid updated property");
|
|
221
202
|
}
|
|
222
|
-
return window._nc_filelistheader;
|
|
223
203
|
}
|
|
224
204
|
function checkOptionalProperty(obj, property, type) {
|
|
225
205
|
if (typeof obj[property] !== "undefined") {
|
|
@@ -442,11 +422,8 @@ class Navigation extends TypedEventTarget {
|
|
|
442
422
|
}
|
|
443
423
|
}
|
|
444
424
|
function getNavigation() {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
logger.debug("Navigation service initialized");
|
|
448
|
-
}
|
|
449
|
-
return window._nc_navigation;
|
|
425
|
+
scopedGlobals.navigation ??= new Navigation();
|
|
426
|
+
return scopedGlobals.navigation;
|
|
450
427
|
}
|
|
451
428
|
const NewMenuEntryCategory = Object.freeze({
|
|
452
429
|
/**
|
|
@@ -516,11 +493,8 @@ class NewMenu {
|
|
|
516
493
|
}
|
|
517
494
|
}
|
|
518
495
|
function getNewFileMenu() {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
logger.debug("NewFileMenu initialized");
|
|
522
|
-
}
|
|
523
|
-
return window._nc_newfilemenu;
|
|
496
|
+
scopedGlobals.newFileMenu ??= new NewMenu();
|
|
497
|
+
return scopedGlobals.newFileMenu;
|
|
524
498
|
}
|
|
525
499
|
function addNewFileMenuEntry(entry) {
|
|
526
500
|
const newFileMenu = getNewFileMenu();
|
|
@@ -541,17 +515,17 @@ function getNewFileMenuEntries(context) {
|
|
|
541
515
|
}
|
|
542
516
|
function registerSidebarAction(action) {
|
|
543
517
|
validateSidebarAction(action);
|
|
544
|
-
|
|
545
|
-
if (
|
|
518
|
+
scopedGlobals.filesSidebarActions ??= /* @__PURE__ */ new Map();
|
|
519
|
+
if (scopedGlobals.filesSidebarActions.has(action.id)) {
|
|
546
520
|
logger.warn(`Sidebar action with id "${action.id}" already registered. Skipping.`);
|
|
547
521
|
return;
|
|
548
522
|
}
|
|
549
|
-
|
|
523
|
+
scopedGlobals.filesSidebarActions.set(action.id, action);
|
|
550
524
|
logger.debug(`New sidebar action with id "${action.id}" registered.`);
|
|
551
525
|
}
|
|
552
526
|
function getSidebarActions() {
|
|
553
|
-
if (
|
|
554
|
-
return [...
|
|
527
|
+
if (scopedGlobals.filesSidebarActions) {
|
|
528
|
+
return [...scopedGlobals.filesSidebarActions.values()];
|
|
555
529
|
}
|
|
556
530
|
return [];
|
|
557
531
|
}
|
|
@@ -577,17 +551,17 @@ function validateSidebarAction(action) {
|
|
|
577
551
|
}
|
|
578
552
|
function registerSidebarTab(tab) {
|
|
579
553
|
validateSidebarTab(tab);
|
|
580
|
-
|
|
581
|
-
if (
|
|
554
|
+
scopedGlobals.filesSidebarTabs ??= /* @__PURE__ */ new Map();
|
|
555
|
+
if (scopedGlobals.filesSidebarTabs.has(tab.id)) {
|
|
582
556
|
logger.warn(`Sidebar tab with id "${tab.id}" already registered. Skipping.`);
|
|
583
557
|
return;
|
|
584
558
|
}
|
|
585
|
-
|
|
559
|
+
scopedGlobals.filesSidebarTabs.set(tab.id, tab);
|
|
586
560
|
logger.debug(`New sidebar tab with id "${tab.id}" registered.`);
|
|
587
561
|
}
|
|
588
562
|
function getSidebarTabs() {
|
|
589
|
-
if (
|
|
590
|
-
return [...
|
|
563
|
+
if (scopedGlobals.filesSidebarTabs) {
|
|
564
|
+
return [...scopedGlobals.filesSidebarTabs.values()];
|
|
591
565
|
}
|
|
592
566
|
return [];
|
|
593
567
|
}
|
|
@@ -869,7 +843,6 @@ export {
|
|
|
869
843
|
FileType,
|
|
870
844
|
FilesSortingMode,
|
|
871
845
|
b as Folder,
|
|
872
|
-
Header,
|
|
873
846
|
InvalidFilenameError,
|
|
874
847
|
InvalidFilenameErrorReason,
|
|
875
848
|
Navigation,
|
|
@@ -898,7 +871,7 @@ export {
|
|
|
898
871
|
registerFileAction,
|
|
899
872
|
registerFileListAction,
|
|
900
873
|
registerFileListFilter,
|
|
901
|
-
|
|
874
|
+
registerFileListHeader,
|
|
902
875
|
registerSidebarAction,
|
|
903
876
|
registerSidebarTab,
|
|
904
877
|
removeNewFileMenuEntry,
|