feature(config) mv apiURL to CloudFunc

This commit is contained in:
coderaiser 2014-05-11 15:14:12 -04:00
parent b9273f9166
commit 88713a9643
6 changed files with 59 additions and 54 deletions

View file

@ -170,9 +170,8 @@ All main configuration could be done via `json/config.json`.
"auth" : false, /* enable http authentication */
"username" : "root", /* username for authentication */
"password" : "toor", /* password hash in sha-1 for authentication*/
"apiURL" : "/api/v1",
"appCache" : false, /* cache files for offline use */
"analytics" : true, /* google analytics support */
"analytics" : true, /* google analytics support */
"diff" : true, /* when save - send patch, not whole file */
"zip" : true, /* zip text before send / unzip before save */
"notifications" : false, /* show notifications when tab is not active*/

View file

@ -318,7 +318,17 @@ var Util, DOM, CloudFunc;
}
this.setConfig = function(config) { Config = config; };
this.getConfig = getSystemFile(Config, '/api/v1/config');
this.getConfig = function(callback) {
Util.ifExec(Config, callback, function() {
var RESTful = DOM.RESTful;
RESTful.Config.read(function(config) {
Config = config;
callback(config);
});
});
};
this.getModules = getSystemFile(Modules, DIR_JSON + 'modules.json');
this.getExt = getSystemFile(Extensions, DIR_JSON + 'ext.json');
this.getFileTemplate = getSystemFile(FileTemplate, DIR_HTML_FS + 'file.html');

View file

@ -127,41 +127,37 @@ var Util, DOM, CloudFunc, CloudCmd;
};
function sendRequest(params) {
var p = params;
Images.showLoad(p.imgPosition);
var p = params,
apiURL = CloudFunc.apiURL,
data,
isString = Util.isString(p.data),
isArrayBuffer = Util.isArrayBuffer(p.data),
isFile = Util.isFile(p.data);
CloudCmd.getConfig(function(config) {
var data,
isString = Util.isString(p.data),
isArrayBuffer = Util.isArrayBuffer(p.data),
isFile = Util.isFile(p.data);
if (Util.isString(p.url))
p.url = decodeURI(p.url);
if (p.data && !isString && !isArrayBuffer && !isFile)
data = Util.stringifyJSON(p.data);
else
data = p.data;
p.url = config && config.apiURL + p.url;
DOM.ajax({
method : p.method,
url : p.url,
data : data,
error : Images.showError,
success : function(data) {
Images.hide();
if (!p.doNotLog)
Util.log(data);
Util.exec(p.callback, data);
}
});
});
if (Util.isString(p.url))
p.url = decodeURI(p.url);
if (p.data && !isString && !isArrayBuffer && !isFile)
data = Util.stringifyJSON(p.data);
else
data = p.data;
p.url = apiURL + p.url;
DOM.ajax({
method : p.method,
url : p.url,
data : data,
error : Images.showError,
success : function(data) {
Images.hide();
if (!p.doNotLog)
Util.log(data);
Util.exec(p.callback, data);
}
});
}
}
})(Util, DOM, CloudFunc);

View file

@ -54,6 +54,7 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb;
GitHub.autorize = function(callback, code) {
Storage.get('token', function(token) {
var isContain,
apiURL = CloudFunc.apiURL,
URL = '//' + window.location.host + '/auth/github';
if (token) {
@ -68,22 +69,20 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb;
if (!isContain)
DOM.openWindow(URL);
else
CloudCmd.getConfig(function(config) {
DOM.ajax({
type : 'put',
url : config && config.apiURL + '/auth',
data : Util.rmStr(code, '?code='),
success : function(data) {
if (data && data.token) {
token = data.token;
GitHub.Login(token);
Storage.set('token', token);
Util.exec(callback);
} else
Util.log('Worning: token not getted...');
}
});
DOM.ajax({
type : 'put',
url : apiURL + '/auth',
data : Util.rmStr(code, '?code='),
success : function(data) {
if (data && data.token) {
token = data.token;
GitHub.Login(token);
Storage.set('token', token);
Util.exec(callback);
} else
Util.log('Worning: token not getted...');
}
});
}
});

View file

@ -41,6 +41,7 @@ var Util;
/* название css-класа кнопки обновления файловой структуры*/
this.REFRESHICON = 'refresh-icon';
this.apiURL = '/api/v1';
/* id панелей с файлами */
this.PANEL_LEFT = 'js-left';
this.PANEL_RIGHT = 'js-right';

View file

@ -75,7 +75,7 @@
var apiURL, name, ret;
if (request && response) {
apiURL = main.config.apiURL;
apiURL = CloudFunc.apiURL;
name = main.getPathName(request);
ret = Util.isContainStr(name, apiURL);