Skip to content

martianyi/VdiskSDK-Node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node SDK For Vdisk

Vdisk Documentation

http://vdisk.weibo.com/developers/index.php?module=api&action=apiinfo

Usage

Install 安装

npm install vdisksdk-node --save

OAuth2 授权接口封装

var OAuth2 = require("vdisksdk-node").OAuth2;
var oauth = new OAuth2(WEIPAN_APPKEY,WEIPAN_APPSECRET,WEIPAN_CALLBACK)

Get the authorization url

var url = oauth.authorize()

Get access token

oauth.accessToken({code:"b0841e108f70acc530aefeee7d0daf14"},function(err, resp){
    if(err) throw(err);
    console.log(resp);
})

Get refresh token

oauth.accessToken({grant_type:"refresh_token",refresh_token: "347ee06666gE5HW3madls3FeZm7e0141"},function(err, resp){
    if(err){
        throw(err)
    }
    console.log(resp);
    done();
})

Client 微盘接口封装

var Client = require("vdisksdk-node").Client;
var client = new Client();

Get account info

client.accountInfo(accessToken, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

Get metadata 获取文件和目录信息

client.metadata({access_token: accessToken}, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

delta

client.delta({access_token: accessToken}, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

files

client.files({access_token: accessToken, path: 'test/test.txt'}, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

revisions 获得文件的历史版本

client.revisions({access_token: accessToken, path: 'test/test.txt'}, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

Save files

client.saveFiles({
    access_token: accessToken,
    path: 'test/test.txt',
    files: __dirname + '/file.txt'
}, function (err, resp) {
    if (err) {
        throw(err)
    }
    console.log(resp);
})

API

Classes

OAuth2

oauth2 client

Client

vdisk client

OAuth2

oauth2 client

Kind: global class

new OAuth2(app_key, app_secret, call_back_url)

Constructor

Param Description
app_key 申请应用时分配的AppKey
app_secret 申请应用时分配的AppSecret
call_back_url

oAuth2.authorize(response_type, display, state) ⇒ string

Get the authorization url

Kind: instance method of OAuth2

Param Description
response_type 返回类型,支持code、token,默认值为code
display 授权页面的终端类型 default/mobile/popup
state 用于保持请求和回调的状态,在回调时,会在Query Parameter中回传该参数

oAuth2.accessToken(grant_type, code, refresh_token, cb)

Get access token

Kind: instance method of OAuth2

Param Description
grant_type 请求的类型 authorization_code/refresh_token
code grant_type为authorization_code时传入
refresh_token grant_type为refresh_token时传入
cb 回调函数,接收error和response两个参数

Client

vdisk client

Kind: global class

new Client(root)

Constructor

Param Description
root sandbox/basic

client.accountInfo(access_token, cb)

Get account info

Kind: instance method of Client

Param Description
access_token 接口获取授权后的access token
cb 回调函数,接收error和response两个参数

client.metadata(access_token, path, cb)

Get metadata 获取文件和目录信息

Kind: instance method of Client

Param
access_token
path
cb

client.delta(access_token, cursor, cb)

Delta

Kind: instance method of Client

Param
access_token
cursor
cb

client.files(access_token, path, rev, cb)

Get files

Kind: instance method of Client

Param
access_token
path
rev
cb

client.revisions(access_token, path, cb)

Get revisions 获得文件的历史版本

Kind: instance method of Client

Param
access_token
path
cb

client.saveFiles(access_token, path, files, overwrite, sha1, size, parent_rev, cb)

Save files

Kind: instance method of Client

Param
access_token
path
files
overwrite
sha1
size
parent_rev
cb

client.updateFiles(access_token, path, files, overwrite, sha1, size, parent_rev, cb)

Update files

Kind: instance method of Client

Param
access_token
path
files
overwrite
sha1
size
parent_rev
cb

client.shares(access_token, path, cancel, cb)

Shares 描述创建并返回一个此分享文件的链接

Kind: instance method of Client

Param
access_token
path
cancel
cb

client.restore(access_token, path, rev, cb)

Restore 还原文件到某个版本

Kind: instance method of Client

Param
access_token
path
rev
cb

client.search(access_token, path, query, file_limit, include_deleted, cb)

Search 返回符合搜索的所有文件和目录信息。搜索权限于指定的目录路径及其下级目录

Kind: instance method of Client

Param
access_token
path
query
file_limit
include_deleted
cb

client.copyRef(access_token, path, cb)

Get copy_ref 创建一个可以转存此分享文件的标识字符串

Kind: instance method of Client

Param
access_token
path
cb

client.media(access_token, path, cb)

Get media 获取文件下载和播放的链接

Kind: instance method of Client

Param
access_token
path
cb

client.thumbnails(access_token, path, size, cb)

Get thumbnails 获取图片文件的缩略图

Kind: instance method of Client

Param Description
access_token
path
size s:60x60,m:100x100,l:640x480,xl:1027x768
cb

client.copyFiles(access_token, to_path, from_path, from_copy_ref, cb)

Copy Files 复制一个对象。当前目录下的目录和文件总数不超过 10000 个时,可以执行此操作。超过此限额时,请进入更深层的目录分批操作。

Kind: instance method of Client

Param
access_token
to_path
from_path
from_copy_ref
cb

client.delFiles(access_token, path, cb)

Delete files 删除一个对象。当前目录下的目录和文件总数不超过 10000 个时,可以执行此操作。超过此限额时,请进入更深层的目录分批操作。

Kind: instance method of Client

Param
access_token
path
cb

client.moveFiles(access_token, from_path, to_path, cb)

Move files 移动一个对象,当前目录下的目录和文件总数不超过 5000 个时,可以执行此操作。超过此限额时,请进入更深层的目录分批操作

Kind: instance method of Client

Param
access_token
from_path
to_path
cb

client.createFolder(access_token, path, cb)

Create folder 创建目录. 一个目录下最多允许创建 1000 个子目录。

Kind: instance method of Client

Param
access_token
path
cb

client.shareMedia(access_token, from_copy_ref, cb)

Get share media 获取分享文件下载和播放的链接

Kind: instance method of Client

Param Description
access_token
from_copy_ref 拷贝引用
cb 回调函数

client.shareSearch(access_token, query, type, sort_order, page, page_size, cb)

Share search 搜索分享的文件

Kind: instance method of Client

Param Description
access_token
query 搜索关键词,可以传多个值,以|分隔。如query= txt|pdf|rar;按组查询时,可选doc,img,video,audio,else中一种
type 搜索类型,1:全文件检索,2:按名称3:按标题,4:按描述5:按文件(夹)类型,6:按后缀,7:按组查询。 可以传多个type,如2:5:6,此时query值也以:分隔,表示各个type对应的query值,例如:query=web:doc并且type=3:7就表示查询分组是文档的并且标题中有关键字web的文件。
sort_order 排序字段,可以传多个,可用的值为:sharetime(分享时间),price(价格),degree(星级),count_download(下载量),bytes(大小),可以传多个,以:分隔
page 当前页数(取值范围1-40),默认1
page_size 每页大小(取值范围1-9999),默认20
cb 回调函数

About

Node SDK for Vdisk

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published