You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
STAGE: ALPHA
This version of the project is still very much in development and should not be used in production environments. The API is not stable and may change at any time. If you want to use this in production, please use the latest stable version.
This readme has not been updated as of yet, so please refer to the updated code documentation for more information.
Changes so far:
Added documentation for all webdav methods
Replaced dependency on request in favor of axios
Replaced dependency on webdav-client in favor of webdav (v.4.11.2)
Improved support for TypeScript
Adds support for Browser usage (DONE - untested as of yet)
Once you have initiated the connection to your nextcloud instance, it is generally a good idea to delay any file or OCS operations until the connection to your instance has been established and verified. Using the client object from above, we can do this like so:
In a real set-up, you'll probably want to limit the number of tries to something sensible, like 15 to 30 seconds by throwing after a given number of attempts.
Finally, use any of the methods described below to interact with your Nextcloud instance:
Configures the Nextcloud connection to talk to a specific Nextcloud WebDav endpoint. This does not issue any kind of request, so it doesn't throw if the parameters are incorrect. This merely sets internal variables.
checkConnectivity(): Promise<boolean>
Checks whether the connection to the configured WebDav endpoint succeeds. This does not throw, it consistently returns a Promise wrapping a boolean.
Pipes the data obtained by reading a file at path on the Nextcloud instance to the provided local stream. Throws a NotFoundError if the requested path does not exist.
Creates a copy of the client that runs the request as the user with the passed credentials. This does absolutely no verification, so you should use checkConnectivity to verify the credentials.
Gets a list of all the shares. Use path to show all the shares for that specific file or folder. Use includeReshares to also include shares not belonging to the user. Use showForSubFiles to show the shares of the children instead. This will throw an error if the path is a file.
Add a new share. shareWith has to be filled if shareType is a user or group. Use permissions bit-wise to add several permissions. OcsSharePermissions.default will let the server decide the permissions. This will throw an error if the specific share already exists. Use shares.edit to edit an existing share.
get: (shareId: string|number): Promise<OcsShare>
Gets the share information.
edit
The following methods are available on client.shares.edit:
To be able to use groupfolders interface, the groupfolders app needs to be downloaded and activated in the Nextcloud settings.
The following methods are available on client.groupfolders:
getFolders: () => Promise<OcsGroupfolder[]>
Returns a list of all configured folders and their settings.
Grants/Removes a group or user the ability to manage a groupfolders' advanced permissions.
mappingId: the id of the group/user to be granted/removed access to/from the groupfolder
mappingType: 'group' or 'user'
manageAcl: true to grants ability to manage a groupfolders' advanced permissions, false to remove
Note: If the groupfolders app is not activated, the requests are returning code 302. The GET requests are redirected to the Location header (/apps/dashboard/) which makes it complicated to catch (returns 200 and text/html content type). The client.groupfolders methods would then throw with an error code 500 and a message "Unable to parse the response body as valid JSON".
Exceptions
NotFoundError
Error indicating that the requested resource doesn't exist, or that the path leading to it doesn't exist in the case of writes.
ForbiddenError
Error indicating that Nextcloud denied the request.
NextcloudError
Generic wrapper for the HTTP errors returned by Nextcloud.
OcsError
Errors used by all OCS calls.
It will return the reason why a request failed as well as a status code if it is available.
Uses createFileDetailProperty to request a Nextcloud property.
Definitions
fileId
This is an OwnCloud property representing either a File or a Folder. It is own of the so-called extraProperties only returned by the WebDAV on request. See the following section for more details
on extraProperties.
WebDAV extraProperties
extraProperties is an optional parameter that can be passed to both getFolderProperties and getFolderFileDetails. The parameter consists of a list of optional properties that are not returned by the WebDAV interface by default.
A simple example that requests the fileId of a directory on top of the standard properties returned by the WebDAV API would be:
Which properties get returned by default and which are only available at request can be found in the Nextcloud Documentation.
Sub Admin
This is a Nextcloud term used to describe a user that has administrator rights for a group.
Contributing
Running tests is a little complicated right now, we're looking into improving this situation. While you can initiate tests using a normal npm test, you'll require docker and docker-compose to be installed in your path.
About
Javascript/Typescript client that communicates with Nextcloud's WebDAV and OCS APIs