mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
feature(rest) add ?hash
This commit is contained in:
parent
4e49eb5095
commit
3dbcb08c97
3 changed files with 56 additions and 2 deletions
39
lib/server/hash.js
Normal file
39
lib/server/hash.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
(function (object) {
|
||||
'use strict';
|
||||
|
||||
var util = require('util'),
|
||||
Writable = require('stream').Writable;
|
||||
|
||||
util.inherits(HashProto, Writable);
|
||||
|
||||
object.Hash = new HashProto();
|
||||
|
||||
function HashProto() {
|
||||
var shasum,
|
||||
crypto = require('crypto');
|
||||
|
||||
Writable.call(this);
|
||||
this.create = function() {
|
||||
var ws = new Writable();
|
||||
|
||||
ws._write = write;
|
||||
ws.get = get;
|
||||
|
||||
shasum = crypto.createHash('sha1');
|
||||
|
||||
return ws;
|
||||
};
|
||||
|
||||
function get() {
|
||||
var hex = shasum.digest('hex');
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
function write (chunk, enc, next) {
|
||||
shasum.update(chunk);
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
|
@ -108,6 +108,7 @@
|
|||
exports.auth = srvrequire('auth').auth,
|
||||
exports.appcache = srvrequire('appcache'),
|
||||
exports.dir = srvrequire('dir'),
|
||||
exports.hash = srvrequire('hash').Hash;
|
||||
diffPatch = librequire('diff/diff-match-patch').diff_match_patch,
|
||||
exports.diff = new (librequire('diff').DiffProto)(diffPatch),
|
||||
exports.rest = srvrequire('rest').api,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
var main = global.cloudcmd.main,
|
||||
fs = main.fs,
|
||||
path = main.path,
|
||||
Hash = main.hash,
|
||||
Util = main.util,
|
||||
pipe = main.pipe,
|
||||
CloudFunc = main.cloudfunc,
|
||||
|
|
@ -98,7 +99,7 @@
|
|||
}
|
||||
|
||||
function onFS(pParams) {
|
||||
var p, lError, lMsg, lSize, lQuery,
|
||||
var p, lError, lMsg, lSize, lQuery, hash,
|
||||
lRet = main.checkParams(pParams);
|
||||
|
||||
if (lRet){
|
||||
|
|
@ -115,7 +116,20 @@
|
|||
sendResponse(p, lSize);
|
||||
});
|
||||
});
|
||||
else
|
||||
else if (Util.strCmp(lQuery, 'hash')) {
|
||||
hash = Hash.create();
|
||||
|
||||
pipe.create({
|
||||
from : p.name,
|
||||
write : hash,
|
||||
callback : function (error) {
|
||||
checkSendError(error, p, function() {
|
||||
var hex = hash.get();
|
||||
sendResponse(p, hex);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else
|
||||
fs.stat(p.name, function(pError, pStat) {
|
||||
checkSendError(pError, p, function() {
|
||||
if (!pStat.isDirectory())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue