@nextcloud/files 3.9.1 → 3.10.0
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/README.md +63 -26
- package/dist/chunks/dav-BBwoJ8WE.cjs +703 -0
- package/dist/chunks/dav-BBwoJ8WE.cjs.map +1 -0
- package/dist/chunks/dav-DxfiR0wZ.mjs +704 -0
- package/dist/chunks/dav-DxfiR0wZ.mjs.map +1 -0
- package/dist/dav.cjs +19 -0
- package/dist/dav.cjs.map +1 -0
- package/dist/dav.d.ts +370 -0
- package/dist/dav.mjs +19 -0
- package/dist/dav.mjs.map +1 -0
- package/dist/index.cjs +99 -709
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1099 -40
- package/dist/index.mjs +403 -1012
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -8
- package/dist/dav/dav.d.ts +0 -56
- package/dist/dav/davPermissions.d.ts +0 -6
- package/dist/dav/davProperties.d.ts +0 -57
- package/dist/fileAction.d.ts +0 -84
- package/dist/fileListFilters.d.ts +0 -90
- package/dist/fileListHeaders.d.ts +0 -27
- package/dist/files/file.d.ts +0 -16
- package/dist/files/fileType.d.ts +0 -8
- package/dist/files/folder.d.ts +0 -22
- package/dist/files/node.d.ts +0 -174
- package/dist/files/nodeData.d.ts +0 -54
- package/dist/navigation/column.d.ts +0 -28
- package/dist/navigation/index.d.ts +0 -7
- package/dist/navigation/navigation.d.ts +0 -74
- package/dist/navigation/view.d.ts +0 -92
- package/dist/newFileMenu.d.ts +0 -66
- package/dist/permissions.d.ts +0 -16
- package/dist/utils/fileSize.d.ts +0 -25
- package/dist/utils/fileSorting.d.ts +0 -35
- package/dist/utils/filename-validation.d.ts +0 -51
- package/dist/utils/filename.d.ts +0 -24
- package/dist/utils/logger.d.ts +0 -2
- package/dist/utils/sorting.d.ts +0 -12
package/README.md
CHANGED
|
@@ -7,70 +7,107 @@
|
|
|
7
7
|
|
|
8
8
|
Nextcloud Files helpers for Nextcloud apps and libraries.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
This library provides three kinds of utils:
|
|
11
|
+
1. WebDAV helper functions to work with the Nextcloud WebDAV interface.
|
|
12
|
+
Those functions are available in `@nextcloud/files/dav`
|
|
13
|
+
2. Geneal purpose function related to files or folders, like filename validation.
|
|
14
|
+
3. Functions and classes to interact with the Nextcloud **files** app, like registering a new view or a file action.
|
|
11
15
|
|
|
12
|
-
## Usage
|
|
16
|
+
## Usage examples
|
|
13
17
|
|
|
14
|
-
###
|
|
18
|
+
### Files app
|
|
19
|
+
|
|
20
|
+
#### Register a "New"-menu entry
|
|
21
|
+
|
|
22
|
+
The "New"-menu allows to create new entries or upload files, it is also possible for other apps to register their own actions here.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import type { Entry } from '@nextcloud/files'
|
|
26
|
+
import { addNewFileMenuEntry } from '@nextcloud/files'
|
|
27
|
+
import { t } from '@nextcloud/l10n'
|
|
28
|
+
|
|
29
|
+
const myEntry: Entry = {
|
|
30
|
+
// unique ID of the entry
|
|
31
|
+
id: 'my-app',
|
|
32
|
+
// The display name in the menu
|
|
33
|
+
displayName: t('my-app', 'New something'),
|
|
34
|
+
// optionally pass an SVG (string) to be used as the menu entry icon
|
|
35
|
+
iconSvgInline: importedSVGFile,
|
|
36
|
+
handler(context: Folder, content: Node[]): void {
|
|
37
|
+
// `context` is the current active folder
|
|
38
|
+
// `content` is the content of the currently active folder
|
|
39
|
+
// You can add new files here e.g. use the WebDAV functions to create files.
|
|
40
|
+
// If new content is added, ensure to emit the event-bus signals so the files app can update the list.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
addNewFileMenuEntry(myEntry)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### WebDAV
|
|
48
|
+
The `getClient` exported function returns a webDAV client that's a wrapper around [webdav's webDAV client](https://www.npmjs.com/package/webdav).
|
|
49
|
+
All its methods are available here.
|
|
50
|
+
|
|
51
|
+
#### Using WebDAV to query favorite nodes
|
|
15
52
|
|
|
16
53
|
```ts
|
|
17
|
-
import {
|
|
54
|
+
import { getClient, defaultRootPath, getFavoriteNodes } from '@nextcloud/files/dav'
|
|
18
55
|
|
|
19
|
-
const client =
|
|
56
|
+
const client = getClient()
|
|
20
57
|
// query favorites for the root folder (meaning all favorites)
|
|
21
58
|
const favorites = await getFavoriteNodes(client)
|
|
22
59
|
// which is the same as writing:
|
|
23
|
-
const favorites = await getFavoriteNodes(client, '/',
|
|
60
|
+
const favorites = await getFavoriteNodes(client, '/', defaultRootPath)
|
|
24
61
|
```
|
|
25
62
|
|
|
26
|
-
|
|
63
|
+
#### Using WebDAV to list all nodes in directory
|
|
27
64
|
|
|
28
65
|
```ts
|
|
29
66
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from '@nextcloud/files'
|
|
67
|
+
getClient,
|
|
68
|
+
getDefaultPropfind,
|
|
69
|
+
resultToNode,
|
|
70
|
+
defaultRootPath,
|
|
71
|
+
defaultRemoteURL
|
|
72
|
+
} from '@nextcloud/files/dav'
|
|
36
73
|
|
|
37
74
|
// Get the DAV client for the default remote
|
|
38
|
-
const client =
|
|
75
|
+
const client = getClient()
|
|
39
76
|
// which is the same as writing
|
|
40
|
-
const client =
|
|
77
|
+
const client = getClient(defaultRemoteURL)
|
|
41
78
|
// of cause you can also configure another WebDAV remote
|
|
42
|
-
const client =
|
|
79
|
+
const client = getClient('https://example.com/dav')
|
|
43
80
|
|
|
44
81
|
const path = '/my-folder/' // the directory you want to list
|
|
45
82
|
|
|
46
83
|
// Query the directory content using the webdav library
|
|
47
84
|
// `davRootPath` is the files root, for Nextcloud this is '/files/USERID', by default the current user is used
|
|
48
|
-
const results = client.getDirectoryContents(`${
|
|
85
|
+
const results = client.getDirectoryContents(`${defaultRootPath}${path}`, {
|
|
49
86
|
details: true,
|
|
50
87
|
// Query all required properties for a Node
|
|
51
|
-
data:
|
|
88
|
+
data: getDefaultPropfind()
|
|
52
89
|
})
|
|
53
90
|
|
|
54
91
|
// Convert the result to an array of Node
|
|
55
|
-
const nodes = results.data.map((result) =>
|
|
56
|
-
// If you specified a different root in the `getDirectoryContents` you must add this also on the `
|
|
57
|
-
const nodes = results.data.map((result) =>
|
|
92
|
+
const nodes = results.data.map((result) => resultToNode(r))
|
|
93
|
+
// If you specified a different root in the `getDirectoryContents` you must add this also on the `resultToNode` call:
|
|
94
|
+
const nodes = results.data.map((result) => resultToNode(r, myRoot))
|
|
58
95
|
// Same if you used a different remote URL:
|
|
59
|
-
const nodes = results.data.map((result) =>
|
|
96
|
+
const nodes = results.data.map((result) => resultToNode(r, myRoot, myRemoteURL))
|
|
60
97
|
|
|
61
98
|
```
|
|
62
99
|
|
|
63
|
-
|
|
100
|
+
#### Using WebDAV to get a Node from a file's name
|
|
64
101
|
|
|
65
102
|
```ts
|
|
66
|
-
import {
|
|
103
|
+
import { getClient, davGetDefaultPropfind, resultToNode, davRootPath } from '@nextcloud/files'
|
|
67
104
|
import { emit } from '@nextcloud/event-bus'
|
|
68
|
-
const client =
|
|
105
|
+
const client = getClient()
|
|
69
106
|
client.stat(`${davRootPath}${filename}`, {
|
|
70
107
|
details: true,
|
|
71
108
|
data: davGetDefaultPropfind(),
|
|
72
109
|
}).then((result) => {
|
|
73
|
-
const node =
|
|
110
|
+
const node = resultToNode(result.data)
|
|
74
111
|
emit('files:node:updated', node)
|
|
75
112
|
})
|
|
76
113
|
```
|