feature(rest) streamPack: add one-click folder download

This commit is contained in:
coderaiser 2015-07-06 07:50:54 -04:00
parent 6c8c128b38
commit 11d9e1fef2
2 changed files with 36 additions and 19 deletions

View file

@ -270,7 +270,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
}
function download() {
var TIME = 1000,
var TIME = 30 * 1000,
apiURL = CloudFunc.apiURL,
FS = CloudFunc.FS,
date = Date.now(),
@ -281,12 +281,14 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
selected = DOM.isSelected(file),
path = DOM.getCurrentPath(file),
id = DOM.load.getIdBySrc(path),
isDir = DOM.isCurrentIsDir(file),
dir = isDir ? '&&json' : '';
isDir = DOM.isCurrentIsDir(file);
CloudCmd.log('downloading file ' + path + '...');
path = apiURL + FS + path + '?download' + dir;
if (isDir)
path = apiURL + '/pack' + path + '.tar.gz';
else
path = apiURL + FS + path + '?download';
element = DOM.load({
id : id + '-' + date,

View file

@ -135,25 +135,40 @@
if (p.name[0] === '/')
cmd = p.name.replace('/', '');
switch(cmd) {
case '':
p.data = json.stringify({
info: 'Cloud Commander API v1'
});
if (/^pack/.test(cmd)) {
cmd = cmd.replace(/^pack/, '');
streamPack(cmd, p.response, callback);
} else {
switch(cmd) {
case '':
p.data = json.stringify({
info: 'Cloud Commander API v1'
});
callback(null, {name: 'api.json'}, p.data);
break;
callback(null, {name: 'api.json'}, p.data);
break;
default:
json = {
message: 'Error: command not found!'
};
callback(json);
break;
default:
json = {
message: 'Error: command not found!'
};
callback(json);
break;
}
}
}
function streamPack(cmd, response, fn) {
var filename = cmd.replace(/\.tar\.gz$/, ''),
dir = path.dirname(filename),
names = [
path.basename(filename)
];
operation('pack', dir, response, names, fn);
}
function auth(code, callback) {
var storage = binom('storage', Modules),
gh = binom('GitHub', storage),