mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
added ability to upload files to GDrive
This commit is contained in:
parent
ce5b7baaa4
commit
56d891077c
6 changed files with 122 additions and 46 deletions
|
|
@ -3,6 +3,7 @@
|
|||
* Changed the way of getting github application id
|
||||
(now it's just from config, rest api removed).
|
||||
|
||||
* Added ability to upload files to GDrive.
|
||||
|
||||
2012.12.12, Version 0.1.8
|
||||
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ function initModules(pCallBack){
|
|||
lNames = {};
|
||||
lNames[lStorage + '_dropbox'] = 'DropBox',
|
||||
lNames[lStorage + '_github' ] = 'GitHub',
|
||||
lNames[lStorage + '_gdrive' ] = 'GDrive',
|
||||
|
||||
lDisableMenuFunc();
|
||||
|
||||
|
|
|
|||
|
|
@ -49,23 +49,32 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
|
||||
// define the elements of the menu
|
||||
items: {
|
||||
view: {name: 'View', callback: function(key, opt){
|
||||
showEditor(true);
|
||||
}},
|
||||
view: {
|
||||
name : 'View',
|
||||
callback : function(key, opt){
|
||||
showEditor(true);
|
||||
}
|
||||
},
|
||||
|
||||
edit: {name: 'Edit', callback: function(key, opt){
|
||||
showEditor();
|
||||
}},
|
||||
edit: {
|
||||
name : 'Edit',
|
||||
callback : function(key, opt){
|
||||
showEditor();
|
||||
}
|
||||
},
|
||||
|
||||
delete: {name: 'Delete',
|
||||
delete: {
|
||||
name: 'Delete',
|
||||
callback: function(key, opt){
|
||||
DOM.promptRemoveCurrent();
|
||||
}},
|
||||
}
|
||||
},
|
||||
|
||||
upload: {
|
||||
name: "Upload to",
|
||||
name: 'Upload to',
|
||||
items: {
|
||||
'upload_to_gist': {name: 'Gist',
|
||||
'gist': {
|
||||
name: 'Gist',
|
||||
callback: function(key, opt){
|
||||
var lCurrent = DOM.getCurrentFile(),
|
||||
lPath = DOM.getCurrentPath(),
|
||||
|
|
@ -93,42 +102,81 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
Util.log('Uploading to gist...');
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
download: {name: 'Download',callback: function(key, opt){
|
||||
DOM.Images.showLoad();
|
||||
|
||||
var lCurrent = DOM.getCurrentFile(),
|
||||
lLink = DOM.getByTag('a', lCurrent)[0].href;
|
||||
|
||||
console.log('downloading file ' + lLink +'...');
|
||||
|
||||
lLink = lLink + '?download';
|
||||
|
||||
lLink = Util.removeStr( lLink, CloudFunc.NOJS );
|
||||
var lId = DOM.getIdBySrc(lLink);
|
||||
|
||||
if(!DOM.getById(lId)){
|
||||
var lDownload = DOM.anyload({
|
||||
name : 'iframe',
|
||||
async : false,
|
||||
className : 'hidden',
|
||||
src : lLink,
|
||||
func : function(){
|
||||
DOM.Images.hideLoad();
|
||||
}
|
||||
});
|
||||
|
||||
DOM.Images.hideLoad();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(lDownload);
|
||||
}, 10000);
|
||||
'gdrive': {
|
||||
name: 'GDrive',
|
||||
|
||||
callback: function(key, opt){
|
||||
|
||||
|
||||
var lCurrent = DOM.getCurrentFile(),
|
||||
lPath = DOM.getCurrentPath(),
|
||||
lName = DOM.getCurrentName(lCurrent);
|
||||
|
||||
DOM.ajax({
|
||||
url : lPath,
|
||||
error : DOM.Images.showError,
|
||||
success : function(data, textStatus, jqXHR){
|
||||
if( Util.isObject(data) )
|
||||
data = JSON.stringify(data, null, 4);
|
||||
var lData = {
|
||||
data: data,
|
||||
name: lName
|
||||
};
|
||||
|
||||
var lGDrive = cloudcmd.GDrive;
|
||||
|
||||
if('init' in lGDrive)
|
||||
lGDrive.init(lData);
|
||||
else
|
||||
Util.exec(cloudcmd.GDrive, lData);
|
||||
}
|
||||
});
|
||||
|
||||
Util.log('Uploading to gdrive...');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
download: {
|
||||
name: 'Download',
|
||||
callback: function(key, opt){
|
||||
DOM.Images.showLoad();
|
||||
|
||||
var lCurrent = DOM.getCurrentFile(),
|
||||
lLink = DOM.getByTag('a', lCurrent)[0].href;
|
||||
|
||||
console.log('downloading file ' + lLink +'...');
|
||||
|
||||
lLink = lLink + '?download';
|
||||
|
||||
lLink = Util.removeStr( lLink, CloudFunc.NOJS );
|
||||
var lId = DOM.getIdBySrc(lLink);
|
||||
|
||||
if(!DOM.getById(lId)){
|
||||
var lDownload = DOM.anyload({
|
||||
name : 'iframe',
|
||||
async : false,
|
||||
className : 'hidden',
|
||||
src : lLink,
|
||||
func : function(){
|
||||
DOM.Images.hideLoad();
|
||||
}
|
||||
});
|
||||
|
||||
DOM.Images.hideLoad();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(lDownload);
|
||||
}, 10000);
|
||||
}
|
||||
else
|
||||
DOM.Images.showError({
|
||||
responseText: 'Error: You trying to' +
|
||||
'download same file to often'});
|
||||
}
|
||||
else
|
||||
DOM.Images.showError({
|
||||
responseText: 'Error: You trying to' +
|
||||
'download same file to often'});
|
||||
}}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
|
||||
APIURL = '/api/v1',
|
||||
AuthURL = APIURL + '/auth',
|
||||
GitHubIdURL = APIURL + '/github_key',
|
||||
|
||||
GitHub_ID,
|
||||
GithubLocal,
|
||||
|
|
@ -103,7 +102,7 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
Util.exec(pCallBack);
|
||||
}
|
||||
|
||||
/* PUBLICK FUNCTIONS */
|
||||
/* PUBLIC FUNCTIONS */
|
||||
GithubStore.basicLogin = function(pUser, pPasswd){
|
||||
GithubLocal = new Github({
|
||||
username: pUser,
|
||||
|
|
|
|||
26
lib/util.js
26
lib/util.js
|
|
@ -290,6 +290,32 @@ var Util, exports;
|
|||
return lRet;
|
||||
};
|
||||
|
||||
/**
|
||||
* set timout before callback would be called
|
||||
* @param pArgs {func, callback, time}
|
||||
*/
|
||||
Util.setTimeout = function(pArgs){
|
||||
var lDone,
|
||||
lFunc = pArgs.func,
|
||||
lTime = pArgs.time || 1000,
|
||||
lCallBack = function(pArgument){
|
||||
if(!lDone){
|
||||
lDone = Util.exec(pArgs.callback, pArgument);
|
||||
}
|
||||
};
|
||||
|
||||
var lTimeoutFunc = function(){
|
||||
setTimeout(function(){
|
||||
Util.exec(lFunc, lCallBack);
|
||||
if(!lDone)
|
||||
lTimeoutFunc();
|
||||
}, lTime);
|
||||
};
|
||||
|
||||
lTimeoutFunc();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* function execute param function in
|
||||
* try...catch block
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@
|
|||
"viewer",
|
||||
"storage/_github",
|
||||
"storage/_dropbox",
|
||||
"storage/_gdrive",
|
||||
"terminal"
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue