feature(rest) add unzip

This commit is contained in:
coderaiser 2014-03-25 04:05:13 -04:00
parent 83aa10660c
commit 41654e09d3
12 changed files with 66 additions and 4 deletions

View file

@ -602,6 +602,23 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
RESTful.zip(fileFrom, CloudCmd.refresh);
};
/**
* unzip file
*
*/
this.unzipFile = function() {
var RESTful = DOM.RESTful,
name = Cmd.getCurrentName(),
dir = Cmd.getCurrentDirPath(),
path = dir + name,
fileFrom = {
from : path
};
if (name && name !== '..')
RESTful.unzip(fileFrom, CloudCmd.refresh);
};
/**
* prompt and delete current file or selected files

View file

@ -189,7 +189,8 @@ var CloudCmd, Util, DOM, CloudFunc, $;
},
'Delete' : DOM.promptDelete,
'(Un)Select All': DOM.toggleAllSelectedFiles,
'Zip file' : DOM.zipFile
'Zip file' : DOM.zipFile,
'Unzip file' : DOM.unzipFile
};
if (UploadToItemNames.length)

View file

@ -62,6 +62,15 @@ var Util, DOM, CloudFunc, CloudCmd;
});
};
this.unzip = function(data, callback) {
sendRequest({
method : 'PUT',
url : '/unzip',
data : data,
callback : callback
});
};
this.mv = function(data, callback) {
sendRequest({
method : 'PUT',

View file

@ -52,8 +52,12 @@
Util.exec(p.callback, error);
};
if (p.gzip) {
gzip = zlib.createGzip();
if (p.gzip || p.gunzip) {
if (p.gzip)
gzip = zlib.createGzip();
else
gzip = zlib.createGunzip();
read.on('error', onError);
read = read.pipe(gzip);
}

View file

@ -307,6 +307,24 @@
break;
case 'unzip':
if (!Util.checkObjTrue(lFiles, ['from']))
sendError(pParams, p.data);
else
pipe.create({
from : lFiles.from,
to : lFiles.to || Util.removeStrOneTime(lFiles.from, ['.zip', '.gzip']),
gunzip : true,
callback : function(error) {
checkSendError(error, pParams, function() {
var name = path.basename(lFiles.from);
sendMsg(pParams, 'zip', name);
});
}
});
break;
case 'config':
var hash,
passwd = lFiles && lFiles.password,