mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(config) mv apiURL to CloudFunc
This commit is contained in:
parent
b9273f9166
commit
88713a9643
6 changed files with 59 additions and 54 deletions
3
HELP.md
3
HELP.md
|
|
@ -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*/
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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...');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue