mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 18:23:35 +00:00
added ability to authorize on github thru new window, changed redirecting url to /auth and added rout function to cloudcmd.js
This commit is contained in:
parent
32ed528c38
commit
9ce26c1640
9 changed files with 76 additions and 80 deletions
|
|
@ -51,15 +51,16 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
});
|
||||
}
|
||||
|
||||
function init(pCallBack){
|
||||
|
||||
GithubStore.init = function(pCallBack, pCode){
|
||||
var lToken = Cache.get('token');
|
||||
if(lToken){
|
||||
GithubStore.Login(lToken);
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
else{
|
||||
var lCode = window.location.search;
|
||||
if ( Util.isContainStr(lCode, '?code=') ){
|
||||
var lCode = pCode || window.location.search;
|
||||
if (pCode || Util.isContainStr(lCode, '?code=') ){
|
||||
lCode = lCode.replace('?code=','');
|
||||
|
||||
var lSuccess = function(pData){
|
||||
|
|
@ -83,14 +84,17 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
DOM.ajax(lData);
|
||||
}
|
||||
else
|
||||
//window.open('welcome.html', 'welcome','width=300,height=200,menubar=yes,status=yes')">
|
||||
window.open('https://github.com/login/oauth/authorize?client_id=' +
|
||||
GitHub_ID + '&&scope=repo,user,gist', 'Cloud Commander Auth');
|
||||
/*
|
||||
window.location =
|
||||
'https://github.com/login/oauth/authorize?client_id=' +
|
||||
GitHub_ID + '&&scope=repo,user,gist';
|
||||
*/
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function getUserData(pCallBack){
|
||||
GithubStore.getUserData = function(pCallBack){
|
||||
var lName,
|
||||
|
||||
lShowUserInfo = function(pError, pData){
|
||||
|
|
@ -163,8 +167,8 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
cloudcmd.GitHub.init = function(pCallBack){
|
||||
Util.loadOnLoad([
|
||||
Util.retExec(pCallBack),
|
||||
getUserData,
|
||||
init,
|
||||
GithubStore.getUserData,
|
||||
GithubStore.init,
|
||||
setConfig,
|
||||
load
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ var CloudFunc, exports;
|
|||
/* length of longest file name */
|
||||
CloudFunc.SHORTNAMELENGTH = 16;
|
||||
|
||||
|
||||
/**
|
||||
* Функция убирает последний слеш,
|
||||
* если он - последний символ строки
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
Server : {},
|
||||
|
||||
/* КОНСТАНТЫ */
|
||||
INDEX : main.DIR + 'index.html'
|
||||
INDEX : main.DIR + 'html/index.html'
|
||||
},
|
||||
DirPath = '/',
|
||||
|
||||
|
|
@ -134,6 +134,7 @@
|
|||
|
||||
CloudServer.indexProcessing = pProcessing.index;
|
||||
CloudServer.rest = pProcessing.rest;
|
||||
CloudServer.route = pProcessing.route;
|
||||
|
||||
this.init(pProcessing.appcache);
|
||||
|
||||
|
|
@ -182,9 +183,9 @@
|
|||
{
|
||||
/* Читаем содержимое папки, переданное в url */
|
||||
var lConfig = CloudServer.Config,
|
||||
url = main.url,
|
||||
lParsedUrl = url.parse(pReq.url),
|
||||
pathname = lParsedUrl.pathname,
|
||||
lURL = main.url,
|
||||
lParsedUrl = lURL.parse(pReq.url),
|
||||
lPath = lParsedUrl.pathname,
|
||||
|
||||
/* varible contain one of queris:
|
||||
* download - change content-type for
|
||||
|
|
@ -196,13 +197,13 @@
|
|||
* query like this
|
||||
* ?json
|
||||
*/
|
||||
lQuery = lParsedUrl.query;
|
||||
lQuery = lParsedUrl.query;
|
||||
if(lQuery)
|
||||
console.log('query = ' + lQuery);
|
||||
|
||||
/* added supporting of Russian language in directory names */
|
||||
pathname = Querystring.unescape(pathname);
|
||||
console.log('pathname: ' + pathname);
|
||||
lPath = Querystring.unescape(lPath);
|
||||
console.log('pathname: ' + lPath);
|
||||
|
||||
/* получаем поддерживаемые браузером кодировки*/
|
||||
var lAcceptEncoding = pReq.headers['accept-encoding'];
|
||||
|
|
@ -213,14 +214,14 @@
|
|||
if (lAcceptEncoding &&
|
||||
lAcceptEncoding.match(/\bgzip\b/) && Zlib)
|
||||
CloudServer.Gzip = true;
|
||||
|
||||
|
||||
/* путь в ссылке, который говорит
|
||||
* что js отключен
|
||||
*/
|
||||
var lNoJS_s = CloudFunc.NOJS,
|
||||
lFS_s = CloudFunc.FS;
|
||||
|
||||
console.log("request for " + pathname + " received...");
|
||||
console.log("request for " + lPath + " received...");
|
||||
|
||||
if( lConfig.rest ){
|
||||
var lRestWas = Util.exec(CloudServer.rest, {
|
||||
|
|
@ -232,21 +233,32 @@
|
|||
return;
|
||||
}
|
||||
|
||||
if( CloudServer.route){
|
||||
var lRouteWas = Util.exec(CloudServer.route, {
|
||||
name : lPath,
|
||||
request : pReq,
|
||||
response : pRes
|
||||
});
|
||||
|
||||
if(lRouteWas)
|
||||
return;
|
||||
}
|
||||
|
||||
/* если в пути нет информации ни о ФС,
|
||||
* ни об отсутствии js,
|
||||
* ни о том, что это корневой
|
||||
* каталог - загружаем файлы проэкта
|
||||
*/
|
||||
if ( !Util.isContainStr(pathname, lFS_s) &&
|
||||
!Util.isContainStr(pathname, lNoJS_s) &&
|
||||
!Util.strCmp(pathname, '/') &&
|
||||
if ( !Util.isContainStr(lPath, lFS_s) &&
|
||||
!Util.isContainStr(lPath, lNoJS_s) &&
|
||||
!Util.strCmp(lPath, '/') &&
|
||||
!Util.strCmp(lQuery, 'json') ) {
|
||||
|
||||
/* если имена файлов проекта - загружаем их *
|
||||
* убираем слеш и читаем файл с текущец директории */
|
||||
|
||||
/* добавляем текующий каталог к пути */
|
||||
var lName = '.' + pathname;
|
||||
var lName = '.' + lPath;
|
||||
console.log('reading ' + lName);
|
||||
|
||||
/* watching is file changed */
|
||||
|
|
@ -346,16 +358,16 @@
|
|||
* длиннее
|
||||
*/
|
||||
|
||||
if(pathname.indexOf(lNoJS_s) !== lFS_s.length && pathname !== '/')
|
||||
if(lPath.indexOf(lNoJS_s) !== lFS_s.length && lPath !== '/')
|
||||
CloudServer.NoJS = false;
|
||||
else{
|
||||
CloudServer.NoJS = true;
|
||||
pathname = Util.removeStr(pathname, lNoJS_s);
|
||||
lPath = Util.removeStr(lPath, lNoJS_s);
|
||||
}
|
||||
|
||||
/* убираем индекс файловой системы */
|
||||
if(pathname.indexOf(lFS_s) === 0){
|
||||
pathname = Util.removeStr(pathname, lFS_s);
|
||||
if(lPath.indexOf(lFS_s) === 0){
|
||||
lPath = Util.removeStr(lPath, lFS_s);
|
||||
|
||||
/* если посетитель только зашел на сайт
|
||||
* no-js будет пустым, как и fs.
|
||||
|
|
@ -375,10 +387,10 @@
|
|||
/* если в итоге путь пустой
|
||||
* делаем его корневым
|
||||
*/
|
||||
if (pathname === '')
|
||||
pathname = '/';
|
||||
if (lPath === '')
|
||||
lPath = '/';
|
||||
|
||||
DirPath = pathname;
|
||||
DirPath = lPath;
|
||||
|
||||
CloudServer.Responses[DirPath] = pRes;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
exports.SRVDIR = SRVDIR = __dirname + SLASH,
|
||||
exports.LIBDIR = LIBDIR = path.normalize(SRVDIR + '../'),
|
||||
exports.DIR = DIR = path.normalize(LIBDIR + '../'),
|
||||
exports.HTMLDIR = DIR + 'html/',
|
||||
|
||||
/* Functions */
|
||||
exports.generateHeaders = generateHeaders,
|
||||
|
|
@ -180,7 +181,7 @@
|
|||
* @param pGzip - данные сжаты gzip'ом
|
||||
*/
|
||||
function sendFile(pParams){
|
||||
var lRet = false,
|
||||
var lRet,
|
||||
lName = pParams.name,
|
||||
lReq = pParams.request,
|
||||
lRes = pParams.response,
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
var main = global.cloudcmd.main,
|
||||
DIR = main.DIR,
|
||||
LIBDIR = main.LIBDIR;
|
||||
LIBDIR = main.LIBDIR,
|
||||
HTMLDIR = main.HTMLDIR;
|
||||
|
||||
exports.Minify = {
|
||||
/* pathes to directories */
|
||||
INDEX : DIR + 'index.html',
|
||||
INDEX : HTMLDIR + 'index.html',
|
||||
/* приватный переключатель минимизации */
|
||||
_allowed :{
|
||||
css : true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue