@nextcloud/files
TypeScript icon, indicating that this package has built-in type declarations

3.9.0 • Public • Published

@nextcloud/files

npm last version REUSE status Code coverage Project documentation

Nextcloud Files helpers for Nextcloud apps and libraries.

The davGetClient exported function returns a webDAV client that's a wrapper around webdav's webDAV client; All its methods are available here.

Usage example

Using WebDAV to query favorite nodes

import { davGetClient, davRootPath, getFavoriteNodes } from '@nextcloud/files'

const client = davGetClient()
// query favorites for the root folder (meaning all favorites)
const favorites = await getFavoriteNodes(client)
// which is the same as writing:
const favorites = await getFavoriteNodes(client, '/', davRootPath)

Using WebDAV to list all nodes in directory

import {
    davGetClient,
    davGetDefaultPropfind,
    davResultToNode,
    davRootPath,
    davRemoteURL
} from '@nextcloud/files'

// Get the DAV client for the default remote
const client = davGetClient()
// which is the same as writing
const client = davGetClient(davRemoteURL)
// of cause you can also configure another WebDAV remote
const client = davGetClient('https://example.com/dav')

const path = '/my-folder/' // the directory you want to list

// Query the directory content using the webdav library
// `davRootPath` is the files root, for Nextcloud this is '/files/USERID', by default the current user is used
const results = client.getDirectoryContents(`${davRootPath}${path}`, {
    details: true,
    // Query all required properties for a Node
    data: davGetDefaultPropfind()
})

// Convert the result to an array of Node
const nodes = results.data.map((result) => davResultToNode(r))
// If you specified a different root in the `getDirectoryContents` you must add this also on the `davResultToNode` call:
const nodes = results.data.map((result) => davResultToNode(r, myRoot))
// Same if you used a different remote URL:
const nodes = results.data.map((result) => davResultToNode(r, myRoot, myRemoteURL))

Using WebDAV to get a Node from a file's name

	import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
	import { emit } from '@nextcloud/event-bus'
	const client = davGetClient()
	client.stat(`${davRootPath}${filename}`, {
		details: true,
		data: davGetDefaultPropfind(),
	}).then((result) => {
		const node = davResultToNode(result.data)
		emit('files:node:updated', node)
	})

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.0-beta.90next
3.9.04,309latest

Version History

VersionDownloads (Last 7 Days)Published
3.9.04,309
3.8.01,065
3.7.065
3.6.020
3.5.1166
3.5.00
3.4.145
3.4.02
3.3.11
3.3.01
3.2.133
3.2.0182
3.1.1114
3.1.0301
3.0.072
3.0.0-beta.272
3.0.0-beta.262
3.0.0-beta.250
3.0.0-beta.240
3.0.0-beta.230
3.0.0-beta.220
3.0.0-beta.21425
3.0.0-beta.200
3.0.0-beta.190
3.0.0-beta.180
3.0.0-beta.170
3.0.0-beta.161
3.0.0-beta.151
3.0.0-beta.142
3.0.0-beta.130
3.0.0-beta.120
3.0.0-beta.112
3.0.0-beta.1032
3.0.0-beta.90
3.0.0-beta.867
3.0.0-beta.727
3.0.0-beta.60
3.0.0-beta.551
3.0.0-beta.40
3.0.0-beta.30
3.0.0-beta.20
3.0.0-beta.10
3.0.1-beta.00
2.1.087
2.0.00
1.1.011
1.0.113
1.0.00
0.1.00

Package Sidebar

Install

npm i @nextcloud/files

Weekly Downloads

7,099

Version

3.9.0

License

AGPL-3.0-or-later

Unpacked Size

816 kB

Total Files

32

Last publish

Collaborators

  • susnux
  • pytal
  • gretadoci
  • mejo-
  • artonge
  • max-nextcloud
  • st3iny
  • marcoambrosinii
  • icewind1991
  • skjnldsv
  • christophwurst
  • juliushaertl
  • nickvergessen