feature(time) add

This commit is contained in:
coderaiser 2013-11-20 08:27:38 +00:00
parent 989373b554
commit d13f610f16
4 changed files with 50 additions and 15 deletions

View file

@ -7,6 +7,7 @@
fs = main.fs,
path = main.path,
Util = main.util,
time = main.time,
CHANGESNAME = JSONDIR + 'changes',
CHANGES_JSON = CHANGESNAME + '.json',
@ -27,25 +28,22 @@
}
}
fs.stat(pFileName, function(pError, pStat) {
var lTimeChanged, lFileTime;
time.get(pFileName, function(error, fileTime) {
var timeChanged;
if (!pError) {
lFileTime = pStat.mtime.getTime();
if (lReadedTime !== lFileTime)
lTimeChanged = Times[i] = {
name: pFileName,
time: lFileTime
};
}
else
Util.log(pError);
if (error)
Util.log(error);
else if (lReadedTime !== fileTime)
timeChanged = Times[i] = {
name: pFileName,
time: fileTime
};
if (lTimeChanged)
if (timeChanged)
writeFile(CHANGES_JSON, Util.stringifyJSON(Times));
Util.exec(pCallBack, lTimeChanged);
Util.exec(pCallBack, timeChanged);
});
};

View file

@ -111,6 +111,7 @@
exports.hash = srvrequire('hash'),
diffPatch = librequire('diff/diff-match-patch').diff_match_patch,
exports.diff = new (librequire('diff').DiffProto)(diffPatch),
exports.time = srvrequire('time');
exports.rest = srvrequire('rest').api,
exports.update = srvrequire('update'),
exports.ischanged = srvrequire('ischanged');

View file

@ -22,6 +22,7 @@
CloudFunc = main.cloudfunc,
dir = main.dir,
diff = main.diff,
time = main.time,
JSONDIR = main.JSONDIR,
OK = 200,
sendError = main.sendError,
@ -116,6 +117,14 @@
sendResponse(p, lSize);
});
});
else if (Util.strCmp(lQuery, 'time'))
time.get(p.name, function(error, time) {
checkSendError(error, p, function() {
var timeStr = time.toString();
sendResponse(p, timeStr);
});
});
else if (Util.strCmp(lQuery, 'hash')) {
hash = Hash.create();

27
lib/server/time.js Normal file
View file

@ -0,0 +1,27 @@
(function (object) {
'use strict';
if(!global.cloudcmd)
return console.log(
'# dir.js' + '\n' +
'# -----------' + '\n' +
'# Module is part of Cloud Commander,' + '\n' +
'# used for getting file change time.' + '\n' +
'# http://cloudcmd.io' + '\n');
var main = global.cloudcmd.main,
fs = require('fs'),
Util = main.util;
object.get = function(filename, callback) {
fs.stat(filename, function(error, stat) {
var time;
if (!error)
time = stat.mtime.getTime();
Util.exec(callback, error, time);
});
};
})(this);