mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 17:05:17 +00:00
minor changes
This commit is contained in:
parent
661562e64f
commit
e8de73985e
5 changed files with 171 additions and 134 deletions
|
|
@ -182,6 +182,8 @@ generation of json of directory listing.
|
|||
|
||||
* Added rename menu item.
|
||||
|
||||
* Added to html templating.
|
||||
|
||||
|
||||
2012.12.12, Version 0.1.8
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ CloudCmd._loadDir = function(pLink, pNeedRefresh){
|
|||
lHref = lCurrentLink.href,
|
||||
lParent = lCurrentLink.textContent,
|
||||
lLink = pLink || Util.removeStr(lHref, CloudCmd.HOST),
|
||||
lDir = DOM.getCurrentDir();
|
||||
lDir = DOM.getCurrentDirName();
|
||||
|
||||
lLink += '?json';
|
||||
|
||||
|
|
|
|||
|
|
@ -846,9 +846,9 @@ var CloudCommander, Util,
|
|||
};
|
||||
|
||||
/**
|
||||
* get current direcotory path
|
||||
* get current direcotory name
|
||||
*/
|
||||
DOM.getCurrentDir = function(){
|
||||
DOM.getCurrentDirName = function(){
|
||||
var lRet,
|
||||
lSubstr,
|
||||
lPanel = DOM.getPanel(),
|
||||
|
|
@ -859,7 +859,20 @@ var CloudCommander, Util,
|
|||
|
||||
lHref = CloudFunc.removeLastSlash(lHref);
|
||||
lSubstr = lHref.substr(lHref , lHref.lastIndexOf('/'));
|
||||
lRet = Util.removeStr(lHref, lSubstr + '/');
|
||||
lRet = Util.removeStr(lHref, lSubstr + '/') || '/';
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
/**
|
||||
* get current direcotory path
|
||||
*/
|
||||
DOM.getCurrentDirPath = function(){
|
||||
var lPath = DOM.getByClass('path')[0],
|
||||
lRet;
|
||||
|
||||
if(lPath)
|
||||
lRet = lPath.textContent;
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
|
@ -1019,6 +1032,7 @@ var CloudCommander, Util,
|
|||
|
||||
lRet = true;
|
||||
}
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
|
|
@ -1334,11 +1348,32 @@ var CloudCommander, Util,
|
|||
pCurrentFile = null;
|
||||
|
||||
var lCurrent = pCurrentFile || DOM.getCurrentFile(),
|
||||
lName = DOM.getCurrentName(lCurrent);
|
||||
lName = DOM.getCurrentName(lCurrent),
|
||||
lNewName = prompt("Rename", lName) || lName;
|
||||
|
||||
lName = prompt("Rename", lName);
|
||||
|
||||
DOM.setCurrentName(lName, lCurrent);
|
||||
if( !Util.strCmp(lName, lNewName) ){
|
||||
var lFiles = {
|
||||
from : lName,
|
||||
to : lNewName
|
||||
};
|
||||
|
||||
CloudCommander.getConfig(function(pConfig){
|
||||
var lUrl = DOM.getCurrentDirPath();
|
||||
lUrl = pConfig && pConfig.api_url + '/mv';
|
||||
|
||||
DOM.ajax({
|
||||
method : 'put',
|
||||
data : Util.stringifyJSON(lFiles),
|
||||
url : lUrl,
|
||||
error : DOM.Images.showError,
|
||||
success : function(pData){
|
||||
DOM.Images.hideLoad();
|
||||
DOM.setCurrentName(lName, lCurrent);
|
||||
Util.log(pData);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,109 +1,109 @@
|
|||
var CloudCommander, Util, DOM, gapi;
|
||||
|
||||
(function(CloudCmd, Util, DOM){
|
||||
'use strict';
|
||||
|
||||
var GDrive = {};
|
||||
|
||||
|
||||
/* PRIVATE FUNCTIONS */
|
||||
|
||||
/**
|
||||
* load google api library
|
||||
*/
|
||||
function load(pCallBack){
|
||||
/* https://code.google.com/p/google-api-javascript-client/ */
|
||||
var lUrl = 'https://apis.google.com/js/client.js';
|
||||
|
||||
DOM.jsload(lUrl, function(){
|
||||
CloudCmd.getModules(function(pModules){
|
||||
var lStorage = Util.findObjByNameInArr(pModules, 'storage'),
|
||||
lGDrive = Util.findObjByNameInArr(lStorage.data, 'GDrive'),
|
||||
GDriveId = lGDrive && lGDrive.data.id;
|
||||
/* https://developers.google.com/drive/credentials */
|
||||
|
||||
var lCLIENT_ID = GDriveId + '.apps.googleusercontent.com',
|
||||
lSCOPES = 'https://www.googleapis.com/auth/drive',
|
||||
|
||||
lParams = {
|
||||
'client_id' : lCLIENT_ID,
|
||||
'scope' : lSCOPES,
|
||||
'immediate' : false
|
||||
};
|
||||
|
||||
setTimeout(function() {
|
||||
gapi.auth.authorize(lParams, function(pAuthResult){
|
||||
|
||||
if (pAuthResult && !pAuthResult.error)
|
||||
gapi.client.load('drive', 'v2', function() {
|
||||
Util.exec(pCallBack);
|
||||
});
|
||||
});
|
||||
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert new file.
|
||||
*
|
||||
* @param {File} fileData {name, data} File object to read data from.
|
||||
* @param {Function} callback Function to call when the request is complete.
|
||||
*/
|
||||
GDrive.uploadFile = function(pParams, pCallBack) {
|
||||
var lContent = pParams.data,
|
||||
lName = pParams.name,
|
||||
boundary = '-------314159265358979323846',
|
||||
delimiter = "\r\n--" + boundary + "\r\n",
|
||||
close_delim = "\r\n--" + boundary + "--",
|
||||
|
||||
contentType = pParams.type || 'application/octet-stream',
|
||||
metadata = {
|
||||
'title' : lName,
|
||||
'mimeType' : contentType
|
||||
},
|
||||
|
||||
base64Data = btoa(lContent),
|
||||
|
||||
multipartRequestBody =
|
||||
delimiter +
|
||||
'Content-Type: application/json\r\n\r\n' +
|
||||
JSON.stringify(metadata) +
|
||||
delimiter +
|
||||
'Content-Type: ' + contentType + '\r\n' +
|
||||
'Content-Transfer-Encoding: base64\r\n' +
|
||||
'\r\n' +
|
||||
base64Data +
|
||||
close_delim;
|
||||
|
||||
var request = gapi.client.request({
|
||||
'path': '/upload/drive/v2/files',
|
||||
'method': 'POST',
|
||||
'params': {'uploadType': 'multipart'},
|
||||
'headers': {
|
||||
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
|
||||
},
|
||||
|
||||
'body': multipartRequestBody
|
||||
});
|
||||
|
||||
if (!pCallBack)
|
||||
pCallBack = function(file) {
|
||||
Util.log(file);
|
||||
};
|
||||
|
||||
request.execute(pCallBack);
|
||||
};
|
||||
|
||||
|
||||
GDrive.init = function(pCallBack){
|
||||
Util.loadOnLoad([
|
||||
Util.retExec(pCallBack),
|
||||
load
|
||||
]);
|
||||
};
|
||||
|
||||
CloudCmd.GDrive = GDrive;
|
||||
var CloudCommander, Util, DOM, gapi;
|
||||
|
||||
(function(CloudCmd, Util, DOM){
|
||||
'use strict';
|
||||
|
||||
var GDrive = {};
|
||||
|
||||
|
||||
/* PRIVATE FUNCTIONS */
|
||||
|
||||
/**
|
||||
* load google api library
|
||||
*/
|
||||
function load(pCallBack){
|
||||
/* https://code.google.com/p/google-api-javascript-client/ */
|
||||
var lUrl = 'https://apis.google.com/js/client.js';
|
||||
|
||||
DOM.jsload(lUrl, function(){
|
||||
CloudCmd.getModules(function(pModules){
|
||||
var lStorage = Util.findObjByNameInArr(pModules, 'storage'),
|
||||
lGDrive = Util.findObjByNameInArr(lStorage, 'GDrive'),
|
||||
GDriveId = lGDrive && lGDrive.id;
|
||||
/* https://developers.google.com/drive/credentials */
|
||||
|
||||
var lCLIENT_ID = GDriveId + '.apps.googleusercontent.com',
|
||||
lSCOPES = 'https://www.googleapis.com/auth/drive',
|
||||
|
||||
lParams = {
|
||||
'client_id' : lCLIENT_ID,
|
||||
'scope' : lSCOPES,
|
||||
'immediate' : false
|
||||
};
|
||||
|
||||
setTimeout(function() {
|
||||
gapi.auth.authorize(lParams, function(pAuthResult){
|
||||
|
||||
if (pAuthResult && !pAuthResult.error)
|
||||
gapi.client.load('drive', 'v2', function() {
|
||||
Util.exec(pCallBack);
|
||||
});
|
||||
});
|
||||
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert new file.
|
||||
*
|
||||
* @param {File} fileData {name, data} File object to read data from.
|
||||
* @param {Function} callback Function to call when the request is complete.
|
||||
*/
|
||||
GDrive.uploadFile = function(pParams, pCallBack) {
|
||||
var lContent = pParams.data,
|
||||
lName = pParams.name,
|
||||
boundary = '-------314159265358979323846',
|
||||
delimiter = "\r\n--" + boundary + "\r\n",
|
||||
close_delim = "\r\n--" + boundary + "--",
|
||||
|
||||
contentType = pParams.type || 'application/octet-stream',
|
||||
metadata = {
|
||||
'title' : lName,
|
||||
'mimeType' : contentType
|
||||
},
|
||||
|
||||
base64Data = btoa(lContent),
|
||||
|
||||
multipartRequestBody =
|
||||
delimiter +
|
||||
'Content-Type: application/json\r\n\r\n' +
|
||||
JSON.stringify(metadata) +
|
||||
delimiter +
|
||||
'Content-Type: ' + contentType + '\r\n' +
|
||||
'Content-Transfer-Encoding: base64\r\n' +
|
||||
'\r\n' +
|
||||
base64Data +
|
||||
close_delim;
|
||||
|
||||
var request = gapi.client.request({
|
||||
'path': '/upload/drive/v2/files',
|
||||
'method': 'POST',
|
||||
'params': {'uploadType': 'multipart'},
|
||||
'headers': {
|
||||
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
|
||||
},
|
||||
|
||||
'body': multipartRequestBody
|
||||
});
|
||||
|
||||
if (!pCallBack)
|
||||
pCallBack = function(file) {
|
||||
Util.log(file);
|
||||
};
|
||||
|
||||
request.execute(pCallBack);
|
||||
};
|
||||
|
||||
|
||||
GDrive.init = function(pCallBack){
|
||||
Util.loadOnLoad([
|
||||
Util.retExec(pCallBack),
|
||||
load
|
||||
]);
|
||||
};
|
||||
|
||||
CloudCmd.GDrive = GDrive;
|
||||
})(CloudCommander, Util, DOM);
|
||||
|
|
@ -64,27 +64,27 @@
|
|||
function sendData(pParams){
|
||||
var lRet = main.checkParams(pParams);
|
||||
if(lRet){
|
||||
var p = pParams;
|
||||
var p = pParams;
|
||||
|
||||
if( Util.isContainStr(p.name, CloudFunc.FS) )
|
||||
lRet = onFS(pParams);
|
||||
lRet = Util.isContainStr(p.name, CloudFunc.FS);
|
||||
if( lRet)
|
||||
onFS(pParams);
|
||||
|
||||
if(p.name[0] === '/')
|
||||
p.command = Util.removeStr(p.name, '/');
|
||||
|
||||
if(!lRet)
|
||||
switch(p.request.method){
|
||||
case 'GET':
|
||||
lRet = onGET(pParams);
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
getBody(pParams.request, function(pBody){
|
||||
pParams.body = pBody;
|
||||
onPUT(pParams);
|
||||
});
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -144,7 +144,6 @@
|
|||
}
|
||||
break;
|
||||
case 'DELETE':
|
||||
console.log('1111111111111')
|
||||
if(lQuery === 'dir')
|
||||
fs.rmdir(p.name, function(pError){
|
||||
if(!pError)
|
||||
|
|
@ -214,7 +213,7 @@
|
|||
var p = pParams,
|
||||
lCmd = p.command,
|
||||
lFiles = Util.stringifyJSON(p.body);
|
||||
|
||||
console.log(p.body);
|
||||
switch(lCmd){
|
||||
case 'auth':
|
||||
main.auth(p.body, function(pTocken){
|
||||
|
|
@ -236,6 +235,7 @@
|
|||
break;
|
||||
case 'mv':
|
||||
if(lFiles)
|
||||
Util.log(lFiles);
|
||||
fs.rename(lFiles.from, lFiles.to, function(pError){
|
||||
if(!pError)
|
||||
main.sendResponse(pParams);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue