mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(dropbox) add getToken, mkDir, writeFile, readFile, readDir
This commit is contained in:
parent
551958f713
commit
2cb28da206
1 changed files with 66 additions and 0 deletions
|
|
@ -83,6 +83,72 @@ var CloudCmd, Util, DOM, Dropbox, cb, Client;
|
|||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
this.readDir = function(dirPath, callback) {
|
||||
var path = dirPath || '/';
|
||||
|
||||
Client.readdir(path, function(error, names, obj, files) {
|
||||
var i, n, name, size, file, fullSize, msg,
|
||||
json = {
|
||||
path : path,
|
||||
files : []
|
||||
};
|
||||
|
||||
if (error)
|
||||
msg = error.responseText;
|
||||
|
||||
n = files && files.length;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
file = files[i];
|
||||
name = file.name;
|
||||
|
||||
if (!file.isFile)
|
||||
size = 'dir';
|
||||
else
|
||||
size = CloudFunc.getShortSize(file.size);
|
||||
|
||||
json.files.push({
|
||||
name: name,
|
||||
size: size
|
||||
});
|
||||
}
|
||||
|
||||
Util.exec(callback, msg, json);
|
||||
});
|
||||
};
|
||||
|
||||
this.readFile = function(name, callback) {
|
||||
Client.readFile(name, function(error, data) {
|
||||
var msg;
|
||||
|
||||
if (error)
|
||||
msg = error.responseText;
|
||||
|
||||
callback(msg, data);
|
||||
});
|
||||
};
|
||||
|
||||
this.writeFile = function(name, data, callback) {
|
||||
Client.writeFile(name, data, function(error, data) {
|
||||
var msg;
|
||||
|
||||
if (error)
|
||||
msg = error.responseText;
|
||||
|
||||
callback(msg, data);
|
||||
});
|
||||
};
|
||||
|
||||
this.mkDir = function(path, callback) {
|
||||
Client.mkdir(path, callback);
|
||||
};
|
||||
|
||||
this.getToken = function() {
|
||||
return Client.credentials().token;
|
||||
};
|
||||
|
||||
/**
|
||||
* upload file to DropBox
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue