From fd3838f5eca9eca07d40664b700df9854d2edae0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 27 Feb 2013 09:53:15 -0500 Subject: [PATCH] fixed bug with reading folder with no access --- json/config.json | 4 +-- json/modules.json | 73 ++++++++++++++++++++++------------------- lib/client/dom.js | 22 +++++++++---- lib/client/menu.js | 4 ++- lib/server/commander.js | 4 +-- lib/server/main.js | 1 - lib/server/rest.js | 35 ++++++++++---------- lib/util.js | 14 +++++++- 8 files changed, 93 insertions(+), 64 deletions(-) diff --git a/json/config.json b/json/config.json index 18d891b7..a99ff7dc 100644 --- a/json/config.json +++ b/json/config.json @@ -2,12 +2,12 @@ "api_url" : "/api/v1", "appcache" : false, "minification" : { - "js" : false, + "js" : true, "css" : true, "html" : true, "img" : true }, - "cache" : false, + "cache" : true, "logs" : false, "show_keys_panel" : true, "server" : true, diff --git a/json/modules.json b/json/modules.json index bf7bc37a..3ea504f4 100644 --- a/json/modules.json +++ b/json/modules.json @@ -1,35 +1,40 @@ -[ - "editor/_codemirror", - "menu", - "viewer", - "terminal", { - "name": "storage", - "data": [{ - "name": "DropBox", - "data":{ - "key" : "0nd3ssnp5fp7tqs", - "secret" : "r61lxpchmk8l06o", - "encodedKey": "DkMz4FYHQTA=|GW6pf2dONkrGvckMwBsl1V1vysrCPktPiUWN7UpDjw==", - "chooserKey": "o7d6llji052vijk" - } - }, { - "name": "GitHub", - "data": { - "key" : "891c251b925e4e967fa9", - "secret" : "afe9bed1e810c5dc44c4c2a953fc6efb1e5b0545" - } - }, { - "name": "GDrive", - "data": { - "id" : "255175681917" - } - }, { - "name": "VK", - "data": { - "id" : "3336188" - } - }, - "SkyDrive" - ] - } +[ + "editor/_codemirror", + "menu", + "viewer", + "terminal", { + "name": "storage", + "data": [{ + "name": "DropBox", + "data":{ + "key" : "0nd3ssnp5fp7tqs", + "secret" : "r61lxpchmk8l06o", + "encodedKey": "DkMz4FYHQTA=|GW6pf2dONkrGvckMwBsl1V1vysrCPktPiUWN7UpDjw==", + "chooserKey": "o7d6llji052vijk" + } + }, { + "name": "GitHub", + "data": { + "key" : "891c251b925e4e967fa9", + "secret" : "afe9bed1e810c5dc44c4c2a953fc6efb1e5b0545" + } + }, { + "name": "GDrive", + "data": { + "id" : "255175681917" + } + }, { + "name": "VK", + "data": { + "id" : "3336188" + } + }, + { + "name": "SkyDrive", + "data": { + "id" : "00000000440E696F" + } + } + ] + } ] \ No newline at end of file diff --git a/lib/client/dom.js b/lib/client/dom.js index ee459de9..ab8bfef3 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -46,7 +46,7 @@ var CloudCommander, Util, DOM.Images.showLoad(); sendRequest({ method : 'DELETE', - url : pUrl, + url : CloudFunc.FS + pUrl, callback : pCallBack }); }; @@ -54,12 +54,20 @@ var CloudCommander, Util, this.save = function(pUrl, pData, pCallBack){ sendRequest({ method : 'PUT', - url : pUrl, + url : CloudFunc.FS + pUrl, data : pData, callback : pCallBack }); }; + this.read = function(pUrl, pCallBack){ + sendRequest({ + method : 'GET', + url : CloudFunc.FS + pUrl, + callback : pCallBack + }); + }; + this.mv = function(pData, pCallBack){ sendRequest({ method : 'PUT', @@ -79,8 +87,10 @@ var CloudCommander, Util, if( Util.isString(p.url) ) p.url = decodeURI(p.url); - if(p.data) + if( p.data && !Util.isString(p.data)) lData = Util.stringifyJSON(p.data); + else + lData = p.data; p.url = pConfig && pConfig.api_url + p.url, DOM.ajax({ @@ -91,7 +101,7 @@ var CloudCommander, Util, success : function(pData){ DOM.Images.hideLoad(); Util.log(pData); - Util.exec(p.callback); + Util.exec(p.callback, pData); } }); }); @@ -1002,7 +1012,7 @@ var CloudCommander, Util, lPath += '?json'; if(!lParams.url) - lParams.url = lPath; + lParams.url = CloudFunc.FS + lPath; lRet = DOM.ajax(lParams); @@ -1186,7 +1196,7 @@ var CloudCommander, Util, var lCurrent = pCurrentFile || DOM.getCurrentFile(), lPath = DOM.getCurrentLink( lCurrent ).href; /* убираем адрес хоста*/ - lPath = Util.removeStr(lPath, CloudCommander.HOST); + lPath = Util.removeStr( lPath, [CloudCommander.HOST, CloudFunc.FS] ); return lPath; }; diff --git a/lib/client/menu.js b/lib/client/menu.js index b9630c5d..0f245960 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -159,7 +159,9 @@ var CloudCommander, Util, DOM, $; lMenuItems = { 'View' : Util.retExec(showEditor, true), 'Edit' : Util.retExec(showEditor, false), - 'Rename' : DOM.renameCurrentFile, + 'Rename' : function(){ + setTimeout( Util.retExec(DOM.renameCurrentFile), 100); + }, 'Delete' : Util.retExec(DOM.promptDeleteCurrent), }; diff --git a/lib/server/commander.js b/lib/server/commander.js index 4bcb06f1..784b0008 100644 --- a/lib/server/commander.js +++ b/lib/server/commander.js @@ -41,7 +41,7 @@ c = pParams.params, lFiles = p.data, lDirPath = getDirPath(c.path); - + if(!p.error && lFiles){ lFiles.data = lFiles.sort(); @@ -76,7 +76,7 @@ fillJSON(lFilesData); } else - Util.exec(p.callback, p.error.toString()); + Util.exec(c.callback, p.error.toString()); } } diff --git a/lib/server/main.js b/lib/server/main.js index 60cc5336..04c5147d 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -215,7 +215,6 @@ lRes = pParams.response; lGziped = pParams.gziped; } - if(lName && lRes && lReq){ var lGzip = isGZIP(lReq), diff --git a/lib/server/rest.js b/lib/server/rest.js index 30102fcd..e49add33 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -69,22 +69,23 @@ lRet = Util.isContainStr(p.name, CloudFunc.FS); if( lRet) onFS(pParams); - - if(p.name[0] === '/') - p.command = Util.removeStr(p.name, '/'); - - switch(p.request.method){ - case 'GET': - lRet = onGET(pParams); - break; - - case 'PUT': - getBody(pParams.request, function(pBody){ - pParams.body = pBody; - onPUT(pParams); - }); - break; - } + else{ + if(p.name[0] === '/') + p.command = Util.removeStr(p.name, '/'); + + switch(p.request.method){ + case 'GET': + lRet = onGET(pParams); + break; + + case 'PUT': + getBody(pParams.request, function(pBody){ + pParams.body = pBody; + onPUT(pParams); + }); + break; + } + } } return lRet; } @@ -95,7 +96,7 @@ var p = pParams, lQuery = main.getQuery(p.request); - p.name = Util.removeStr(p.name, [CloudFunc.FS, '?dir']) || '/'; + p.name = Util.removeStrOneTime(p.name, [CloudFunc.FS, '?dir']) || '/'; switch(p.request.method){ case 'GET': fs.stat(p.name, function(pError, pStat){ diff --git a/lib/util.js b/lib/util.js index 7884152e..cafe5cf9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -361,12 +361,24 @@ Util = exports || {}; Util.replaceStr = function(pStr, pFrom, pTo){ var lRet = pStr; - if(pStr && pFrom) + if(pStr && pFrom){ + pFrom = Util.escapeRegExp(pFrom); lRet = pStr.replace(new RegExp(pFrom, 'g'), pTo); + } return lRet; }; + + Util.escapeRegExp = function(pStr) { + var lRet = pStr; + + if( Util.isString(pStr) ) + lRet = pStr.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + + return lRet; + }; + /** * function render template with view * @pTempl