feature(storage) rm vk, skydrive, github, dropbox

This commit is contained in:
coderaiser 2015-08-26 06:57:51 -04:00
parent 4e1079f272
commit fca61f7314
10 changed files with 0 additions and 765 deletions

View file

@ -1,17 +0,0 @@
<!doctype html>
<html>
<head></head>
<body>
<script>
(function() {
'use strict';
window.opener
.CloudCmd
.GitHub
.authorize(window.location.search);
})();
</script>
</body>
</html>

View file

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script src=//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.10.2/dropbox.min.js></script>
</head>
<body>
<script>
Dropbox.AuthDriver.Popup.oauthReceiver()
</script>
</body>
</html>

View file

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<script src="/join:modules/promise-polyfill/Promise.js:lib/util.js:lib/client/dom.js:lib/client/events.js:lib/client/load.js:lib/client/files.js:lib/client.js"></script>
<script>
(function() {
"use strict";
DOM.Files.get('modules', function(error, modules) {
var URL = 'https://github.com/login/oauth/authorize?client_id=',
Storage = Util.findObjByNameInArr(modules, 'storage'),
GitHub = Util.findObjByNameInArr(Storage, 'GitHub'),
GitHub_ID = GitHub && GitHub.key;
window.location =
URL + GitHub_ID + '&&scope=repo,user,gist';
});
})();
</script>
</body>
</html>

View file

@ -46,25 +46,6 @@
}, {
"name": "storage",
"data": [{
"name" : "DropBox",
"key" : "0nd3ssnp5fp7tqs",
"secret" : "r61lxpchmk8l06o",
"encodedKey": "DkMz4FYHQTA=|GW6pf2dONkrGvckMwBsl1V1vysrCPktPiUWN7UpDjw==",
"chooserKey": "o7d6llji052vijk"
}, {
"name" : "GitHub",
"key" : "891c251b925e4e967fa9",
"secret" : "afe9bed1e810c5dc44c4c2a953fc6efb1e5b0545"
}, {
"name" : "GDrive",
"id" : "255175681917"
}, {
"name" : "VK",
"id" : "3336188"
}, {
"name" : "SkyDrive",
"id" : "00000000440E696F"
}, {
"name" : "FilePicker",
"key" : "AACq5fTfzRY2E_Rw_4kyaz"
}]

View file

@ -1,216 +0,0 @@
var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client;
(function(CloudCmd, Util, DOM, CloudFunc) {
'use strict';
CloudCmd.DropBox = DropBoxProto;
function DropBoxProto(callback) {
var DropBoxStore = this;
function init(callback) {
Util.exec.series([
load,
DropBoxStore.login,
getUserData,
Util.exec.ret(callback)
]);
}
cb = function (err, data) {
console.log(err || data);
};
/**
* function loads dropbox.js
*/
function load(callback) {
Util.time('dropbox load');
var src = '//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.10.2/dropbox.min.js';
DOM.load.js(src, function() {
Util.timeEnd('dropbox load');
DOM.Images.hide();
Util.exec(callback);
});
}
function getUserData(callback) {
Client.getUserInfo(function(pError, pData) {
var lHello = 'Hello ' + pData.name + ' :)!',
lMsg = pError ? pError : lHello;
console.log(lMsg);
});
Util.exec(callback);
}
/**
* function logins on dropbox
*
* @param pData = {key, secret}
*/
this.login = function(callback) {
DOM.Files.get('modules', function(error, modules) {
var url = CloudCmd.HOST + '/html/auth/dropbox.html',
storage = Util.findObjByNameInArr(modules, 'storage'),
dropbox = Util.findObjByNameInArr(storage, 'DropBox'),
key = dropbox.key;
Client = new Dropbox.Client({
key: key
});
//Client.authDriver(new Dropbox.Drivers.Redirect({rememberUser: true}));
Client.authDriver(new Dropbox.AuthDriver.Popup({
receiverUrl : url,
noFragment : true
}));
Client.authenticate(function(error, client) {
console.log(error);
Client = client;
Util.exec(callback);
});
});
};
this.read = function(path, callback) {
Client.stat(path, function(error, stat) {
var msg, read;
if (error)
msg = error.responseText;
else {
if (stat.isFile)
read = readFile;
else
read = readDir;
read(path, callback);
}
});
};
this.save = function(path, data, callback, query) {
if (query === '?dir')
mkDir(path, callback);
else
writeFile(path, data, callback);
};
this.delete = function(path, callback) {
Client.delete(path, callback);
};
this.cp = function(from, to, callback) {
Client.copy(from, to, callback);
};
this.mv = function(from, to, callback) {
Client.move(from, to, callback);
};
this.getToken = function() {
return Client.credentials().token;
};
/**
* upload file to DropBox
*/
this.uploadFile = function(params, callback) {
var data = params.data,
name = params.name;
if (data) {
if (!name)
name = new Date();
DOM.Images.show.load();
Client.writeFile(name, data, function(error, data) {
DOM.Images.hide();
console.log(error || data);
Util.exec(callback);
});
}
return this;
};
function readDir(dirPath, callback) {
var path = dirPath || '/';
Client.readdir(path, function(error, names, obj, files) {
var i, n, name, size, file, msg,
json = {
path : path,
files : []
};
if (path !== '/')
json.path += '/';
if (error)
msg = error.responseText;
n = files && files.length;
for (i = 0; i < n; i++) {
file = files[i];
name = file.name;
if (!file.isFile)
size = 'dir';
else
size = CloudFunc.getShortSize(file.size);
json.files.push({
name: name,
size: size,
mode: '.'
});
}
Util.exec(callback, msg, json);
});
}
function mkDir(path, callback) {
Client.mkdir(path, callback);
}
function readFile(name, callback) {
Client.readFile(name, function(error, data) {
var msg;
if (error)
msg = error.responseText;
callback(msg, data);
});
}
function writeFile(name, data, callback) {
Client.writeFile(name, data, function(error, data) {
var msg;
if (error)
msg = error.responseText;
callback(msg, data);
});
}
init(callback);
}
})(CloudCmd, Util, DOM, CloudFunc);

View file

@ -1,51 +0,0 @@
var Util, CloudCmd, DOM, Dropbox;
(function(Util, CloudCmd, DOM) {
'use strict';
var CHOOSER_API = 'https://www.dropbox.com/static/api/1/dropbox.js',
DropBoxStore = {},
options = {
linkType: 'direct',
success: function(files) {
console.log('Here\'s the file link:' + files[0].link);
},
cancel: function() {
console.log('Chose something');
}
};
/* PRIVATE FUNCTIONS */
/**
* function loads dropbox.js
*/
function load() {
Util.time('dropbox load');
DOM.Files.get('config', function(error, config) {
var lDropBoxId = config.dropbox_chooser_key,
element = DOM.load({
src : CHOOSER_API,
notAppend : true,
id : 'dropboxjs',
func : DropBoxStore.choose
});
element.setAttribute('data-app-key', lDropBoxId);
document.body.appendChild(element);
Util.timeEnd('dropbox load');
});
}
DropBoxStore.choose = function() {
Dropbox.choose(options);
};
DropBoxStore.init = function() {
load();
};
CloudCmd.DropBox = DropBoxStore;
})(Util, CloudCmd, DOM);

View file

@ -1,106 +0,0 @@
var CloudCmd, Util, DOM, gapi;
(function(CloudCmd, Util, DOM) {
'use strict';
var GDrive = {};
/* PRIVATE FUNCTIONS */
/**
* load google api library
*/
function load(callback) {
/* https://code.google.com/p/google-api-javascript-client/ */
var lUrl = 'https://apis.google.com/js/client.js';
DOM.load.js(lUrl, function() {
DOM.Files.get('modules', function(error, modules) {
var storage = Util.findObjByNameInArr(modules, 'storage'),
gDrive = Util.findObjByNameInArr(storage, 'GDrive'),
gDriveId = gDrive && gDrive.id,
/* https://developers.google.com/drive/credentials */
clientId = gDriveId + '.apps.googleusercontent.com',
scopes = 'https://www.googleapis.com/auth/drive',
lParams = {
'client_id' : clientId,
'scope' : scopes,
'immediate' : false
};
setTimeout(function() {
gapi.auth.authorize(lParams, function(pAuthResult) {
if (pAuthResult && !pAuthResult.error)
gapi.client.load('drive', 'v2', Util.exec.ret(callback));
});
}, 1500);
});
});
}
/**
* 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,
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) {
console.log(file);
};
request.execute(pCallBack);
};
GDrive.init = function(callback) {
Util.exec.series([
load,
Util.exec.ret(callback)
]);
};
CloudCmd.GDrive = GDrive;
})(CloudCmd, Util, DOM);

View file

@ -1,151 +0,0 @@
var CloudCmd, Util, join, DOM, CloudFunc, Github, cb;
(function(CloudCmd, Util, join, DOM, CloudFunc) {
'use strict';
CloudCmd.GitHub = GitHubProto;
function GitHubProto(callback) {
var GitHub = this,
Storage = DOM.Storage,
GH,
User;
cb = function (err, data) {
console.log(err || data);
};
function init(callback) {
Util.exec.series([
load,
GitHub.authorize,
Util.exec.ret(callback)
]);
}
function load(callback) {
var dir = '/modules/github/',
url = CloudCmd.join([
dir + 'lib/underscore-min.js',
dir + 'github.js'
]);
Util.time('github');
DOM.load.js(url, function() {
Util.timeEnd('github');
DOM.Images.hide();
Util.exec(callback);
});
}
GitHub.authorize = function(code) {
Storage.get('token', function(error, token) {
var is = Util.type.string(code),
apiURL = CloudFunc.apiURL,
URL = '//' + window.location.host + '/auth/github';
if (token) {
GitHub.Login(token);
Util.exec(callback);
} else {
is = is && ~code.indexOf('?code=');
if (!is)
DOM.openWindow(URL);
else
DOM.load.ajax({
type : 'put',
url : apiURL + '/auth',
data : code.replace('?code=', ''),
success : function(data) {
var token = Util.json.parse(data).data.token;
GitHub.Login(token);
Storage.set('token', token);
GitHub.getUserData(callback);
}
});
}
});
};
GitHub.getUserData = function(callback) {
User.show(null, function(error, data) {
var name;
if (!error) {
name = data.name;
console.log('Hello ' + name + ' :)!');
} else
DOM.Storage.remove('token');
});
Util.exec(callback);
};
/* PUBLIC FUNCTIONS */
GitHub.basicLogin = function(user, passwd) {
GH = new Github({
username: user,
password: passwd,
auth : 'basic'
});
};
GitHub.Login = function(token) {
GH = new Github({
token : token,
auth : 'oauth'
});
User = GH.getUser();
};
/**
* function creates gist
*/
GitHub.uploadFile = function(params, callback) {
var gist, files, options,
content = params.data,
name = params.name;
if (content) {
DOM.Images.show.load();
if (!name)
name = new Date();
gist = GH.getGist();
files = {};
options = {
description: 'Uplouded by http://cloudcmd.io',
public: true
};
files[name] = {
content: content
};
options.files = files;
gist.create(options, function(error, data) {
if (error)
console.log(error);
else
console.log(data, data.html_url);
Util.exec(callback);
DOM.Images.hide();
});
}
return content;
};
init(callback);
}
})(CloudCmd, Util, join, DOM, CloudFunc);

View file

@ -1,78 +0,0 @@
//http://isdk.dev.live.com/ISDK.aspx?category=scenarioGroup_skyDrive&index=0
var CloudCmd, Util, DOM, WL;
(function(CloudCmd, Util, DOM) {
'use strict';
var SkyDrive = {};
/* PRIVATE FUNCTIONS */
/**
* load google api library
*/
function load(callback) {
console.time('SkyDrive');
var lUrl = '//js.live.net/v5.0/wl.js';
DOM.load.js(lUrl, function() {
console.timeEnd('SkyDrive load');
DOM.Images.hide();
Util.exec(callback);
});
}
function auth() {
DOM.Files.get('modules', function(error, modules) {
var lStorage = Util.findObjByNameInArr(modules, 'storage'),
lSkyDrive = Util.findObjByNameInArr(lStorage, 'SkyDrive'),
lSkyDriveKey = lSkyDrive && lSkyDrive.id;
WL.init({
client_id: lSkyDriveKey,
redirect_uri: CloudCmd.HOST,
});
WL.login({
scope: ['wl.skydrive wl.signin']
}).then(
function(response) {
console.log(response);
},
function() {
console.log('Failed to authenticate.');
});
WL.Event.subscribe('auth.login', onLogin);
});
}
function onLogin() {
var strGreeting = '';
WL.api({
path: 'me',
method: 'GET'
},
function (response) {
if (!response.error) {
strGreeting = 'Hi, ' + response.first_name + '!';
console.log(strGreeting);
}
});
}
SkyDrive.init = function(callback) {
Util.exec.series([
load,
auth,
Util.exec.ret(callback)
]);
};
CloudCmd.SkyDrive = SkyDrive;
})(CloudCmd, Util, DOM);

View file

@ -1,94 +0,0 @@
var CloudCmd, Util, DOM, VK;
(function(CloudCmd, Util, DOM) {
'use strict';
var VKStorage = {};
/* PRIVATE FUNCTIONS */
/**
* load google api library
*/
function load(pCallBack) {
console.time('vk');
var lUrl = 'http://vkontakte.ru/js/api/openapi.js',
lLocal = CloudCmd.PREFIX + '/modules/vk-openapi/openapi/vk-openapi.js',
lOnload = function() {
console.timeEnd('vk load');
DOM.Images.hide();
Util.exec(pCallBack);
};
DOM.load.js(lUrl, {
onload : lOnload,
error : DOM.retJSLoad(lLocal, lOnload)
});
}
function auth(callback) {
DOM.Files.get('config', function(error, config) {
var lDOCUMENTS_ACCESS = 131072;
VK.init({ apiId: config.vk_id});
VK.Auth.login(function() {
var lNAME = 1281;
VK.Api.call('getVariable', {key: lNAME}, function(r) {
var lName = r.response;
if (lName)
console.log ('Hello, ' + lName + ':)');
});
Util.exec(callback);
}, lDOCUMENTS_ACCESS); /* Доступ к документам пользователя */
});
}
/**
* Insert new file.
*
* @param {File} fileData {name, data} File object to read data from.
*/
VKStorage.uploadFile = function(params) {
/* http://vk.com/developers.php?oid=-1&p=docs.getUploadServer */
VK.Api.call('docs.getUploadServer', {}, function(result) {
var url = result.response.upload_url,
data = params.data,
name = params.name;
DOM.load.ajax({
type : 'POST',
url : url,
data : {
file: data,
name: name
},
dataType: 'application/x-www-form-urlencoded',
success : function(data) {
console.log(data);
VK.Api.call('docs.save', {}, console.log);
},
error : console.log
});
});
};
VKStorage.init = function(callback) {
Util.exec.series([
load,
auth,
Util.exec.ret(callback)
]);
};
CloudCmd.VK = VKStorage;
})(CloudCmd, Util, DOM);