feature(dropbox) add getToken, mkDir, writeFile, readFile, readDir

This commit is contained in:
coderaiser 2013-12-06 13:25:17 +00:00
parent 551958f713
commit 2cb28da206

View file

@ -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
*/