@667/js-owncloud-client 中文文档教程

发布于 3年前 浏览 24 项目主页 更新于 3年前

构建状态依赖状态devDependencies Status

这个表单的主要目的是更新deps(主要是现在已经弃用的request),axios、axios-retry和form-data基本上取代了request包。 此外,node-lts 分支是主要关注的分支,因为 owncloud sdk 通常设计为在浏览器而非节点中运行。

Install

$ npm install js-owncloud-client

Usage

Node.JS

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');

// Login
oc.login('username', 'password').then(status => {
    // STUFF
}).catch(error => {
    // HANDLE ERROR
});

// Share File With Link
oc.shares.shareFileWithLink('linkToYourFile').then(shareInfo => {
    console.log("Link is : " + shareInfo.getLink());
}).catch(error => {
    // HANDLE ERROR
});

// List all files
oc.files.list('/path/to/file/folder').then(files => {
    console.log(files);
}).catch(error => {
    console.log(error);
});

Browser

<script type="text/javascript" src="./js-owncloud-client/browser/owncloud.js"></script>

<script type="text/javascript">
  // var oc is global
  oc.setInstance('*owncloud instance URL*');

  // Login
  oc.login('username', 'password').then(status => {
    window.alert(status);
  }).catch(error => {
    window.alert(error);
  });

  // Share File With Link
  oc.shares.shareFileWithLink('linkToYourFile').then(shareInfo => {
      window.alert("Link is : " + shareInfo.getLink());
  }).catch(error => {
      window.alert(error);
  });

  // List all files
  oc.files.list('/path/to/file/folder').then(files => {
      console.log(files);
  }).catch(error => {
      console.log(error);
  });
</script>

Example Projects

Node.JS Based

Browser Based

使用此库的示例文本文件保存和检索静态 Web 应用程序:链接

All Methods Available

General

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
setInstanceoc.setInstance(instance)
loginoc.login(username, password)
getConfigoc.getConfig()
getVersionoc.getVersion()
getCapabilitiesoc.getCapabilities()

Files Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
listoc.files.list(/path/to/file/folder, depth)
getFileContentsoc.files.getFileContents(path/to/file/folder)
putFileContentsoc.files.putFileContents(path/to/file, contents)
mkdiroc.files.mkdir(path/to/folder)
createFolderoc.files.createFolder(path/to/folder)
deleteoc.files.delete(path/to/file/folder)
fileInfooc.files.fileInfo(path/to/file/folder)
getFileoc.files.getFile(remotePath, localPath)
getDirectoryAsZipoc.files.getDirectoryAsZip(remotePath, localPath)
putFileoc.files.putFile(remotePath, localPath)
putDirectoryoc.files.putDirectory(remotePath, localPath)
moveoc.files.move(source, target)
copyoc.files.copy(source, target)

Apps Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
getAppsoc.apps.getApps()
getAttributeoc.apps.getAttribute(app, key)
setAttributeoc.apps.setAttribute(app, key, value)
deleteAttributeoc.apps.deleteAttribute(app, key)
enableAppoc.apps.enableApp(appName)
disableAppoc.apps.disableApp(appName)

Group Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
createGroupoc.groups.createGroup(groupName)
deleteGroupoc.groups.deleteGroup(groupName)
getGroupsoc.groups.getGroups()
getGroupMembersoc.groups.getGroupMembers(groupName)
groupExistsoc.groups.groupExists(groupName)

Share Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
shareFileWithLinkoc.shares.shareFileWithLink(path, {perms: perms, publicUpload: publicUpload, password: password})
updateShareoc.shares.updateShare(shareId, {perms: perms, publicUpload: publicUpload, password: password})
shareFileWithUseroc.shares.shareFileWithUser(path, username, {perms: perms, remoteUser: remoteUser })
shareFileWithGroupoc.shares.shareFileWithGroup(path, groupname, {perms: perms })
getSharesoc.shares.getShares()
isSharedoc.shares.isShared(path/to/file/folder)
getShareoc.shares.getShare(shareId)
listOpenRemoteShareoc.shares.listOpenRemoteShare()
acceptRemoteShareoc.shares.acceptRemoteShare(shareId)
declineRemoteShareoc.shares.declineRemoteShare(shareId)
deleteShareoc.shares.deleteShare(shareId)

User Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
createUseroc.users.createUser(username, password)
deleteUseroc.users.deleteUser(username)
searchUsersoc.users.searchUsers(searchKey)
userExistsoc.users.userExists(username)
getUsersoc.users.getUsers()
setUserAttributeoc.users.setUserAttribute(username, key, value)
addUserToGroupoc.users.addUserToGroup(username, groupName)
getUserGroupsoc.users.getUserGroups(username)
userIsInGroupoc.users.userIsInGroup(username, groupName)
getUseroc.users.getUser(username)
removeUserFromGroupoc.users.removeUserFromGroup(username, groupName)
addUserToSubadminGroupoc.users.addUserToSubadminGroup(username, groupName)
getUserSubadminGroupsoc.users.getUserSubadminGroups(username)
userIsInSubadminGroupoc.users.userIsInSubadminGroup(username, groupName)

Building the Documentation

Swagger Documentation

卡住了? 只需键入此命令即可在您的浏览器中查看上述所有可用方法!

$ cd node_modules/js-owncloud-client/
$ make swagger

如果您打开通过运行上述命令显示的链接,您将看到类似这样的内容:

在这里,您可以单击任何方法并输入值,以在浏览器本身中试验这些方法!
现在不是很酷吗? :wink:

JSDocs

要构建 jsdoc,请键入此命令并按照终端上的说明进行操作:

$ cd node_modules/js-owncloud-client/
$ make jsdocs

Unit tests

以下命令将运行所有单元测试。 在运行该命令之前,请确保您已相应地编辑了 owncloud/test/config.json 文件。

$ cd node_modules/js-owncloud-client/
$ make test

Team

Noveen Sachdeva        文森特佩特里
Noveen Sachdeva             文森特佩特里

GSoC'17

Build StatusDependencies StatusdevDependencies Status

The main purpose of this form was to update the deps (mainly request which is now deprecated) and axios, axios-retry, and form-data basically take the place of the request package. Further the node-lts branch is the primary branch of concern as owncloud sdk in general is designed to run in the browser not node.

Install

$ npm install js-owncloud-client

Usage

Node.JS

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');

// Login
oc.login('username', 'password').then(status => {
    // STUFF
}).catch(error => {
    // HANDLE ERROR
});

// Share File With Link
oc.shares.shareFileWithLink('linkToYourFile').then(shareInfo => {
    console.log("Link is : " + shareInfo.getLink());
}).catch(error => {
    // HANDLE ERROR
});

// List all files
oc.files.list('/path/to/file/folder').then(files => {
    console.log(files);
}).catch(error => {
    console.log(error);
});

Browser

<script type="text/javascript" src="./js-owncloud-client/browser/owncloud.js"></script>

<script type="text/javascript">
  // var oc is global
  oc.setInstance('*owncloud instance URL*');

  // Login
  oc.login('username', 'password').then(status => {
    window.alert(status);
  }).catch(error => {
    window.alert(error);
  });

  // Share File With Link
  oc.shares.shareFileWithLink('linkToYourFile').then(shareInfo => {
      window.alert("Link is : " + shareInfo.getLink());
  }).catch(error => {
      window.alert(error);
  });

  // List all files
  oc.files.list('/path/to/file/folder').then(files => {
      console.log(files);
  }).catch(error => {
      console.log(error);
  });
</script>

Example Projects

Node.JS Based

Browser Based

A sample text-file saving and retreiving static web app which uses this library: link

All Methods Available

General

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
setInstanceoc.setInstance(instance)
loginoc.login(username, password)
getConfigoc.getConfig()
getVersionoc.getVersion()
getCapabilitiesoc.getCapabilities()

Files Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
listoc.files.list(/path/to/file/folder, depth)
getFileContentsoc.files.getFileContents(path/to/file/folder)
putFileContentsoc.files.putFileContents(path/to/file, contents)
mkdiroc.files.mkdir(path/to/folder)
createFolderoc.files.createFolder(path/to/folder)
deleteoc.files.delete(path/to/file/folder)
fileInfooc.files.fileInfo(path/to/file/folder)
getFileoc.files.getFile(remotePath, localPath)
getDirectoryAsZipoc.files.getDirectoryAsZip(remotePath, localPath)
putFileoc.files.putFile(remotePath, localPath)
putDirectoryoc.files.putDirectory(remotePath, localPath)
moveoc.files.move(source, target)
copyoc.files.copy(source, target)

Apps Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
getAppsoc.apps.getApps()
getAttributeoc.apps.getAttribute(app, key)
setAttributeoc.apps.setAttribute(app, key, value)
deleteAttributeoc.apps.deleteAttribute(app, key)
enableAppoc.apps.enableApp(appName)
disableAppoc.apps.disableApp(appName)

Group Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
createGroupoc.groups.createGroup(groupName)
deleteGroupoc.groups.deleteGroup(groupName)
getGroupsoc.groups.getGroups()
getGroupMembersoc.groups.getGroupMembers(groupName)
groupExistsoc.groups.groupExists(groupName)

Share Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
shareFileWithLinkoc.shares.shareFileWithLink(path, {perms: perms, publicUpload: publicUpload, password: password})
updateShareoc.shares.updateShare(shareId, {perms: perms, publicUpload: publicUpload, password: password})
shareFileWithUseroc.shares.shareFileWithUser(path, username, {perms: perms, remoteUser: remoteUser })
shareFileWithGroupoc.shares.shareFileWithGroup(path, groupname, {perms: perms })
getSharesoc.shares.getShares()
isSharedoc.shares.isShared(path/to/file/folder)
getShareoc.shares.getShare(shareId)
listOpenRemoteShareoc.shares.listOpenRemoteShare()
acceptRemoteShareoc.shares.acceptRemoteShare(shareId)
declineRemoteShareoc.shares.declineRemoteShare(shareId)
deleteShareoc.shares.deleteShare(shareId)

User Management

var owncloud = require('js-owncloud-client');
var oc = new owncloud('*owncloud instance URL*');
MethodCode
createUseroc.users.createUser(username, password)
deleteUseroc.users.deleteUser(username)
searchUsersoc.users.searchUsers(searchKey)
userExistsoc.users.userExists(username)
getUsersoc.users.getUsers()
setUserAttributeoc.users.setUserAttribute(username, key, value)
addUserToGroupoc.users.addUserToGroup(username, groupName)
getUserGroupsoc.users.getUserGroups(username)
userIsInGroupoc.users.userIsInGroup(username, groupName)
getUseroc.users.getUser(username)
removeUserFromGroupoc.users.removeUserFromGroup(username, groupName)
addUserToSubadminGroupoc.users.addUserToSubadminGroup(username, groupName)
getUserSubadminGroupsoc.users.getUserSubadminGroups(username)
userIsInSubadminGroupoc.users.userIsInSubadminGroup(username, groupName)

Building the Documentation

Swagger Documentation

Stuck? Just type this to see all the above available methods live in action in your browser!

$ cd node_modules/js-owncloud-client/
$ make swagger

If you open the link showed by running the above command, you will see something like this :

Here, you can click on any method and type in values, to experiment with the methods in the browser itself!
Now isn't that cool? :wink:

JSDocs

To build the jsdocs, type this command and follow the instructions on the terminal :

$ cd node_modules/js-owncloud-client/
$ make jsdocs

Unit tests

The following command will run all unit tests. Before running the command, make sure you have edited the owncloud/test/config.json file accordingly.

$ cd node_modules/js-owncloud-client/
$ make test

Team

Noveen Sachdeva        Vincent Petry
Noveen Sachdeva             Vincent Petry

GSoC'17

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文