mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
feature(flop) add
This commit is contained in:
parent
30d02fc790
commit
85e8911b0d
4 changed files with 134 additions and 55 deletions
20
cloudcmd.js
20
cloudcmd.js
|
|
@ -2,7 +2,10 @@
|
|||
'use strict';
|
||||
|
||||
var DIR = __dirname + '/',
|
||||
main = require(DIR + 'lib/server/main'),
|
||||
DIR_SERVER = DIR + 'lib/server/',
|
||||
|
||||
main = require(DIR_SERVER + 'main'),
|
||||
flop = require(DIR_SERVER + 'flop'),
|
||||
|
||||
HTMLDIR = main.HTMLDIR,
|
||||
JSONDIR = main.JSONDIR,
|
||||
|
|
@ -13,7 +16,6 @@
|
|||
AppCache = main.appcache,
|
||||
Util = main.util,
|
||||
update = main.update,
|
||||
dir = main.dir,
|
||||
|
||||
server = main.librequire('server'),
|
||||
Minify = main.minify,
|
||||
|
|
@ -233,7 +235,7 @@
|
|||
} else if (isFS) {
|
||||
name = Util.rmStrOnce(name, CloudFunc.FS) || main.SLASH;
|
||||
|
||||
getContent(name, function(error, data, isFile) {
|
||||
flop.read(name, function(error, data, isFile) {
|
||||
if (error)
|
||||
main.sendError(p, error);
|
||||
else if (isFile) {
|
||||
|
|
@ -255,18 +257,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
function getContent(name, callback) {
|
||||
dir.isDir(name, function(error, isDir) {
|
||||
var getDirContent = main.commander.getDirContent,
|
||||
func = Util.exec.ret(callback);
|
||||
|
||||
if (!error && isDir)
|
||||
getDirContent(name, callback);
|
||||
else
|
||||
func(error, null, !isDir);
|
||||
});
|
||||
}
|
||||
|
||||
function readIndex(json, callback) {
|
||||
var isMinify = Minify && Config.minify;
|
||||
|
||||
|
|
|
|||
123
lib/server/flop.js
Normal file
123
lib/server/flop.js
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* FLOP - FiLe OPerations
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var fs = require('fs'),
|
||||
DIR = './',
|
||||
|
||||
Util = require(DIR + '../util'),
|
||||
|
||||
dir = require(DIR + 'dir'),
|
||||
commander = require(DIR + 'commander'),
|
||||
time = require(DIR + 'time'),
|
||||
Hash = require(DIR + 'hash'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
|
||||
fse = {
|
||||
mkdir : tryRequire('mkdirp') || fs.mkdir.bind(fs),
|
||||
};
|
||||
|
||||
exports.create = function(path, type, callback) {
|
||||
Util.checkArgs(arguments, ['path', 'callback']);
|
||||
|
||||
if (!callback) {
|
||||
callback = type;
|
||||
type = 'file';
|
||||
}
|
||||
|
||||
if (!type)
|
||||
type = 'file';
|
||||
|
||||
switch(type) {
|
||||
case 'file':
|
||||
fs.writeFile(path, '', callback);
|
||||
break;
|
||||
|
||||
case 'dir':
|
||||
fse.mkdir(path, callback);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
exports.read = function(path, type, callback) {
|
||||
var hash, error;
|
||||
|
||||
Util.checkArgs(arguments, ['path', 'callback']);
|
||||
|
||||
if (!callback)
|
||||
callback = type;
|
||||
|
||||
switch (type) {
|
||||
case 'size':
|
||||
dir.getSize(path, callback);
|
||||
break;
|
||||
|
||||
case 'time':
|
||||
time.get(path, function(error, time) {
|
||||
var timeStr;
|
||||
|
||||
if (!error)
|
||||
timeStr = time.toString();
|
||||
|
||||
callback(error, timeStr);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'hash':
|
||||
hash = Hash.create();
|
||||
|
||||
if (!hash) {
|
||||
error = 'hash: not suported, try update node';
|
||||
callback(new Error(error));
|
||||
} else
|
||||
pipe.create(path, hash, function (error) {
|
||||
var hex;
|
||||
|
||||
if (!error)
|
||||
hex = hash.get();
|
||||
|
||||
callback(error, hex);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
dir.isDir(path, function(error, isDir) {
|
||||
var getDirContent = commander.getDirContent;
|
||||
|
||||
if (isDir && !error)
|
||||
getDirContent(path, callback);
|
||||
else
|
||||
callback(error, null, !isDir);
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
exports.write = function() {
|
||||
|
||||
};
|
||||
|
||||
exports.delete = function() {
|
||||
|
||||
};
|
||||
|
||||
exports.mv = function() {
|
||||
|
||||
};
|
||||
|
||||
exports.cp = function() {
|
||||
|
||||
};
|
||||
|
||||
function tryRequire(name) {
|
||||
var module;
|
||||
|
||||
Util.exec.try(function() {
|
||||
module = require(name);
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
})();
|
||||
|
|
@ -114,7 +114,6 @@
|
|||
exports.auth = srvrequire('auth').auth,
|
||||
exports.appcache = srvrequire('appcache'),
|
||||
exports.dir = dir = srvrequire('dir'),
|
||||
exports.hash = srvrequire('hash'),
|
||||
diffPatch = librequire('diff/diff-match-patch').diff_match_patch,
|
||||
exports.diff = new (librequire('diff').DiffProto)(diffPatch),
|
||||
exports.users = srvrequire('users');
|
||||
|
|
|
|||
|
|
@ -4,23 +4,18 @@
|
|||
var path = require('path'),
|
||||
DIR = path.resolve(__dirname + '/../../../') + '/',
|
||||
DIR_SERVER = DIR + 'server/',
|
||||
Hash = require(DIR_SERVER + 'hash'),
|
||||
dir = require(DIR_SERVER + 'dir'),
|
||||
time = require(DIR_SERVER + 'time'),
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
commander = require(DIR_SERVER + 'commander'),
|
||||
flop = require(DIR_SERVER + 'flop'),
|
||||
CloudFunc = require(DIR + 'cloudfunc'),
|
||||
Util = require(DIR + 'util');
|
||||
|
||||
exports.onGet = onGet;
|
||||
|
||||
function onGet(query, name, callback) {
|
||||
var error, hash,
|
||||
func = Util.exec.ret(callback);
|
||||
var func = Util.exec.ret(callback);
|
||||
|
||||
switch (query) {
|
||||
case 'size':
|
||||
dir.getSize(name, function(error, size) {
|
||||
flop.read(name, 'size', function(error, size) {
|
||||
if (!error)
|
||||
size = CloudFunc.getShortSize(size);
|
||||
|
||||
|
|
@ -29,43 +24,15 @@
|
|||
break;
|
||||
|
||||
case 'time':
|
||||
time.get(name, function(error, time) {
|
||||
var timeStr;
|
||||
|
||||
if (!error)
|
||||
timeStr = time.toString();
|
||||
|
||||
func(error, timeStr);
|
||||
});
|
||||
flop.read(name, 'time', func);
|
||||
break;
|
||||
|
||||
case 'hash':
|
||||
hash = Hash.create();
|
||||
|
||||
if (!hash) {
|
||||
error = 'not suported, try update node';
|
||||
error = CloudFunc.formatMsg('hash', error, 'error');
|
||||
func(error);
|
||||
} else
|
||||
pipe.create(name, hash, function (error) {
|
||||
var hex;
|
||||
|
||||
if (!error)
|
||||
hex = hash.get();
|
||||
|
||||
func(error, hex);
|
||||
});
|
||||
flop.read(name, 'hash', func);
|
||||
break;
|
||||
|
||||
default:
|
||||
dir.isDir(name, function(error, isDir) {
|
||||
var getDirContent = commander.getDirContent;
|
||||
|
||||
if (isDir && !error)
|
||||
getDirContent(name, func);
|
||||
else
|
||||
func(error, null, !isDir);
|
||||
});
|
||||
flop.read(name, func);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue