refactored

This commit is contained in:
coderaiser 2013-01-28 05:35:40 -05:00
parent 67e32118d9
commit a537c56e46
9 changed files with 57 additions and 68 deletions

View file

@ -104,9 +104,8 @@
merge : true
};
if (pAllowed.js) {
if (pAllowed.js)
lOptimizeParams.push(LIBDIR + 'client.js');
}
if (pAllowed.html)
lOptimizeParams.push(lIndex);
@ -121,7 +120,7 @@
}
if (lOptimizeParams.length)
lMinify.optimize(lOptimizeParams);
lMinify.optimize(lOptimizeParams,{cache:true});
}
/**

View file

@ -5,11 +5,13 @@
<script>
(function(){
"use strict";
if(window.opener){
var cloudcmd = window.opener.CloudCommander;
cloudcmd.getConfig(function(pConfig){
var GitHub_ID = pConfig.github_key;
var lGitHub = pConfig.github,
GitHub_ID = lGitHub && lGitHub.key;
window.location =
'https://github.com/login/oauth/authorize?client_id=' +

View file

@ -1,4 +1,4 @@
{
{
"api_url" : "/api/v1",
"appcache" : false,
"cache" : {"allowed" : false},
@ -8,8 +8,10 @@
"html" : true,
"img" : true
},
"github_key" : "891c251b925e4e967fa9",
"github_secret" : "afe9bed1e810c5dc44c4c2a953fc6efb1e5b0545",
"github":{
"key" : "891c251b925e4e967fa9",
"secret" : "afe9bed1e810c5dc44c4c2a953fc6efb1e5b0545"
},
"dropbox_key" : "0nd3ssnp5fp7tqs",
"dropbox_secret" : "r61lxpchmk8l06o",
"dropbox_encoded_key" : "DkMz4FYHQTA=|GW6pf2dONkrGvckMwBsl1V1vysrCPktPiUWN7UpDjw==",

View file

@ -32,23 +32,24 @@ var CloudCmd = {
/* ПРИВАТНЫЕ ФУНКЦИИ */
/* функция загружает json-данные о файловой системе */
_ajaxLoad : null,
_ajaxLoad : null,
/* Функция генерирует JSON из html-таблицы файлов */
_getJSONfromFileTable : null,
_getJSONfromFileTable : null,
/* функция меняет ссыки на ajax-овые */
_changeLinks : null,
_changeLinks : null,
/* КОНСТАНТЫ*/
LIBDIR : '/lib/',
LIBDIRCLIENT : '/lib/client/',
LIBDIR : '/lib/',
LIBDIRCLIENT : '/lib/client/',
JSONDIR : '/json/',
/* height of Cloud Commander
* seting up in init()
*/
HEIGHT : 0,
MIN_ONE_PANEL_WIDTH : 1155,
OLD_BROWSER : false,
HEIGHT : 0,
MIN_ONE_PANEL_WIDTH : 1155,
OLD_BROWSER : false,
HOST : (function(){
var lLocation = document.location;
@ -387,8 +388,8 @@ function baseInit(pCallBack){
CloudCmd.getConfig = function(pCallBack){
Util.ifExec(Config, pCallBack, function(pCallBack){
DOM.ajax({
url:'/json/config.json',
success: function(pConfig){
url : CloudCmd.JSONDIR + 'config.json',
success : function(pConfig){
Config = pConfig;
Util.exec(pCallBack, pConfig);
}
@ -399,8 +400,8 @@ CloudCmd.getConfig = function(pCallBack){
CloudCmd.getModules = function(pCallBack){
Util.ifExec(Modules, pCallBack, function(pCallBack){
DOM.ajax({
url:'/json/modules.json',
success: Util.retExec(pCallBack)
url : CloudCmd.JSONDIR + 'modules.json',
success : Util.retExec(pCallBack)
});
});
};

View file

@ -8,8 +8,6 @@ var CloudCommander, Util, DOM, $, Github, cb;
APIURL,
AuthURL,
GitHub_ID,
GithubLocal,
User,
GitHubStore = {};
@ -40,16 +38,6 @@ var CloudCommander, Util, DOM, $, Github, cb;
});
}
function setConfig(pCallBack){
CloudCmd.getConfig(function(pConfig){
GitHub_ID = pConfig.github_key;
APIURL = pConfig.api_url;
AuthURL = APIURL + '/auth';
Util.exec(pCallBack);
});
}
GitHubStore.autorize = function(pCallBack, pCode){
var lToken = Cache.get('token');
@ -59,29 +47,25 @@ var CloudCommander, Util, DOM, $, Github, cb;
}
else{
var lCode = pCode || window.location.search;
if (pCode || Util.isContainStr(lCode, '?code=') ){
lCode = lCode.replace('?code=','');
var lSuccess = function(pData){
if(pData && pData.token){
lToken = pData.token;
GitHubStore.Login(lToken);
Cache.set('token', lToken);
Util.exec(pCallBack);
}
else
Util.log('Worning: token not getted...');
},
lData = {
if (lCode || Util.isContainStr(lCode, '?code=') )
CloudCmd.getConfig(function(pConfig){
DOM.ajax({
type : 'put',
url : AuthURL,
data : lCode,
success : lSuccess
};
DOM.ajax(lData);
}
url : pConfig && pConfig.api_url + '/auth',
data : Util.removeStr(lCode, '?code='),
success : function(pData){
if(pData && pData.token){
lToken = pData.token;
GitHubStore.Login(lToken);
Cache.set('token', lToken);
Util.exec(pCallBack);
}
else
Util.log('Worning: token not getted...');
}
});
});
else{
var lUrl = '//' + window.location.host + '/auth/github';
DOM.openWindow(lUrl);
@ -95,8 +79,7 @@ var CloudCommander, Util, DOM, $, Github, cb;
lShowUserInfo = function(pError, pData){
if(!pError){
lName = pData.name;
console.log('Hello ' + lName + ' :)!');
Util.log('Hello ' + lName + ' :)!');
}
else
DOM.Cache.remove('token');
@ -105,7 +88,7 @@ var CloudCommander, Util, DOM, $, Github, cb;
User.show(null, lShowUserInfo);
Util.exec(pCallBack);
}
};
/* PUBLIC FUNCTIONS */
GitHubStore.basicLogin = function(pUser, pPasswd){
@ -169,7 +152,6 @@ var CloudCommander, Util, DOM, $, Github, cb;
Util.retExec(pCallBack),
GitHubStore.getUserData,
GitHubStore.autorize,
setConfig,
load
]);

View file

@ -164,8 +164,8 @@
if(lConfig.socket && CloudServer.Socket){
lListen = CloudServer.Socket.listen(this.Server);
}
Util.log('* Sockets ' + (lListen ? 'running' : 'disabled') + '\n' +
'* Server running at http://' + this.IP + ':' + this.Port);
Util.log('* Sockets ' + (lListen ? 'running' : 'disabled'));
Util.log('* Server running at http://' + this.IP + ':' + this.Port);
}, this));
if(lError){

View file

@ -36,34 +36,35 @@
*/
exports.auth = function(pCode, pCallBack){
pCode = pCode.replace('code=','');
pCode = pCode.replace('code=', '');
console.log(pCode);
authenticate(pCode, function(token) {
var result = { "token": token };
console.log(result);
Util.log(result);
Util.exec(pCallBack, result);
});
};
function authenticate(pCode, pCallBack) {
var lId = Config.github_key,
lSecret = Config.github_secret,
var lGitHub = Config.github,
lId = lGitHub && lGitHub.key,
lSecret = lGitHub && lGitHub.secret,
lEnv = process.env,
lClientId = lEnv.github_key || lId,
lClientSecret = lEnv.github_secret || lSecret;
console.log(lClientId);
console.log(lClientSecret);
Util.log(lClientId);
Util.log(lClientSecret);
var data = qs.stringify({
client_id : lClientId,
client_secret : lClientSecret,
code : pCode
});
console.log(data);
Util.log(data);
GithubAuth.headers = { 'content-length': data.length };

View file

@ -71,7 +71,7 @@
});
}
isFileChanged(DIR + 'manifest.yml', true, function(pData){
exports.isFileChanged(DIR + 'manifest.yml', true, function(pData){
console.log(pData);
});
})();

View file

@ -7,6 +7,7 @@
var DIR,
LIBDIR,
SRVDIR,
JSONDIR,
Util,
SLASH,
@ -49,6 +50,7 @@
exports.LIBDIR = LIBDIR = path.normalize(SRVDIR + '../'),
exports.DIR = DIR = path.normalize(LIBDIR + '../'),
exports.HTMLDIR = DIR + 'html/',
exports.JSONDIR = JSONDIR = DIR + 'json/',
/* Functions */
exports.generateHeaders = generateHeaders,
@ -68,7 +70,7 @@
exports.zlib = zlib = mrequire('zlib'),
/* Main Information */
exports.config = rootrequire('json/config');
exports.config = mrequire(JSONDIR + 'config');
exports.mainpackage = rootrequire('package');