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

3.2.1 • Public • Published

@nextcloud/files

npm last version Code coverage Project documentation

Nextcloud Files helpers for Nextcloud apps and libraries

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))

Readme

Keywords

Package Sidebar

Install

npm i @nextcloud/files

Weekly Downloads

7,781

Version

3.2.1

License

AGPL-3.0-or-later

Unpacked Size

629 kB

Total Files

26

Last publish

Collaborators

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