mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
minor changes
This commit is contained in:
parent
37847df395
commit
0db6d3370b
4 changed files with 78 additions and 33 deletions
|
|
@ -17,7 +17,9 @@
|
|||
'.mp3' : 'audio/mpeg'
|
||||
};
|
||||
|
||||
/* Global var accessible from any loaded module */
|
||||
global.cloudcmd = {},
|
||||
|
||||
/* Constants */
|
||||
exports.DIR = DIR = process.cwd() + '/',
|
||||
exports.LIBDIR = LIBDIR = DIR + 'lib/',
|
||||
|
|
@ -39,18 +41,27 @@
|
|||
exports.https = require('https'),
|
||||
exports.path = require('path'),
|
||||
exports.url = require('url'),
|
||||
exports.querystring = require('querystring'),
|
||||
exports.querystring = require('querystring'),
|
||||
|
||||
/* Needed Modules */
|
||||
exports.util = Util = require(LIBDIR + 'util'),
|
||||
|
||||
exports.zlib = mrequire('zlib'),
|
||||
|
||||
/* Main Information */
|
||||
exports.config = rootrequire('config');
|
||||
exports.mainpackage = rootrequire('package');
|
||||
|
||||
/* Additional Modules */
|
||||
|
||||
/*
|
||||
* Any of loaded below modules could work with global var so
|
||||
* it should be initialized first. Becouse of almost any of
|
||||
* moudles do not depends on each other all needed information
|
||||
* for all modules is initialized hear.
|
||||
*/
|
||||
global.cloudcmd.main = exports;
|
||||
|
||||
exports.auth = srvrequire('auth').auth,
|
||||
exports.appcache = srvrequire('appcache'),
|
||||
exports.cache = srvrequire('cache').Cache,
|
||||
|
|
@ -58,8 +69,12 @@
|
|||
exports.rest = srvrequire('rest').api,
|
||||
exports.socket = srvrequire('socket'),
|
||||
exports.update = srvrequire('update'),
|
||||
exports.minify = srvrequire('minify').Minify,
|
||||
exports.zlib = mrequire('zlib');
|
||||
exports.minify = srvrequire('minify').Minify;
|
||||
|
||||
/*
|
||||
* second initializing after all modules load, so global var is
|
||||
* totally filled of all information that should know all modules
|
||||
*/
|
||||
global.cloudcmd.main = exports;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
var main = global.cloudcmd.main,
|
||||
Util = main.util,
|
||||
fs = main.fs,
|
||||
zlib = main.zlib,
|
||||
APIURL = '/api/v1',
|
||||
OK = 200,
|
||||
Header = main.generateHeaders('api.json', false);
|
||||
|
|
@ -86,21 +88,24 @@
|
|||
* @param pParams {command, method, body, response}
|
||||
*/
|
||||
function onGET(pParams){
|
||||
var lResult,
|
||||
var lResult = {error: 'command not found'},
|
||||
lCmd = pParams.command;
|
||||
|
||||
switch(lCmd){
|
||||
case '':
|
||||
lResult = {info: 'Cloud Commander API v1'};
|
||||
break;
|
||||
case 'kill':
|
||||
process.exit();
|
||||
break;
|
||||
|
||||
case 'client_id':
|
||||
var lEnv = process.env,
|
||||
lConfig = main.config;
|
||||
|
||||
|
||||
lResult = lEnv.oauth_client_id || lConfig.oauth_client_id;
|
||||
break;
|
||||
|
||||
case 'kill':
|
||||
process.exit();
|
||||
break;
|
||||
}
|
||||
|
||||
return lResult;
|
||||
|
|
@ -112,7 +117,7 @@
|
|||
* @param pParams {command, method, body, response}
|
||||
*/
|
||||
function onPUT(pParams){
|
||||
var lResult,
|
||||
var lResult = {error: 'command not found'},
|
||||
lCmd = pParams.command,
|
||||
lBody = pParams.body,
|
||||
lRes = pParams.response;
|
||||
|
|
@ -124,11 +129,39 @@
|
|||
});
|
||||
lResult = false;
|
||||
break;
|
||||
|
||||
/* Example:
|
||||
* read=[lib/dom.js, lib/cloudfunc.js, client.js]
|
||||
*/
|
||||
case 'read':
|
||||
console.log(lBody);
|
||||
var lFiles = lBody;
|
||||
|
||||
if( Util.isString(lFiles) ){
|
||||
lRes.writeHead(OK, main.generateHeaders(lFiles, true) );
|
||||
|
||||
fs.createReadStream(lFiles, {
|
||||
'bufferSize': 4 * 1024
|
||||
})
|
||||
.pipe( zlib.createGzip() )
|
||||
.pipe(lRes);
|
||||
|
||||
lResult = null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return lResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* get body of url query
|
||||
*
|
||||
* @param pReq
|
||||
* @param pCallBack
|
||||
*/
|
||||
function getBody(pReq, pCallBack){
|
||||
var lBody = '';
|
||||
pReq.on('data', function(chunk) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue