working!
This commit is contained in:
parent
6efa4f86de
commit
f2cc272f16
7 changed files with 202 additions and 104 deletions
|
|
@ -86,8 +86,9 @@ angular.module('copayApp.controllers').controller('CreateController',
|
||||||
privateKeyHex: $scope.private,
|
privateKeyHex: $scope.private,
|
||||||
networkName: $scope.networkName,
|
networkName: $scope.networkName,
|
||||||
};
|
};
|
||||||
var w = walletFactory.create(opts);
|
walletFactory.create(opts, function(err, w) {
|
||||||
controllerUtils.startNetwork(w, $scope);
|
controllerUtils.startNetwork(w, $scope);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,19 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
walletFactory.getWallets(function(wallets) {
|
walletFactory.getWallets(function(wallets) {
|
||||||
$scope.wallets = wallets.sort(cmp);
|
$scope.wallets = wallets.sort(cmp);
|
||||||
});
|
|
||||||
|
|
||||||
walletFactory.storage.getLastOpened(function(ret) {
|
if (!$scope.wallets.length) {
|
||||||
$scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id);
|
$location.path('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
walletFactory.storage.getLastOpened(function(ret) {
|
||||||
|
$scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.openPassword = '';
|
$scope.openPassword = '';
|
||||||
$scope.isMobile = !!window.cordova;
|
$scope.isMobile = !!window.cordova;
|
||||||
|
|
||||||
if (!$scope.wallets.length) {
|
|
||||||
$location.path('/');
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.open = function(form) {
|
$scope.open = function(form) {
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
notification.error('Error', 'Please enter the required fields');
|
notification.error('Error', 'Please enter the required fields');
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ Storage.prototype.getGlobal = function(k, cb) {
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
|
|
||||||
this.storage.getItem(k, function(item) {
|
this.storage.getItem(k, function(item) {
|
||||||
|
console.log('[Storage.js.96:item:]',item); //TODO
|
||||||
cb(item == 'undefined' ? undefined : item);
|
cb(item == 'undefined' ? undefined : item);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -118,18 +119,34 @@ Storage.prototype.get = function(walletId, k, cb) {
|
||||||
this._read(this._key(walletId, k), cb);
|
this._read(this._key(walletId, k), cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Storage.prototype._readHelper = function(walletId, k, cb) {
|
||||||
|
console.log('[Storage.js.134:walletId:]',walletId,k); //TODO
|
||||||
|
var wk = this._key(walletId, k);
|
||||||
|
|
||||||
|
this._read(wk, function(v){
|
||||||
|
return cb(v,k);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Storage.prototype.getMany = function(walletId, keys, cb) {
|
Storage.prototype.getMany = function(walletId, keys, cb) {
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var ret = {};
|
var ret = {};
|
||||||
|
console.log('[Storage.js.142:keys:]',keys); //TODO
|
||||||
|
|
||||||
|
var l = keys.length, i=0;
|
||||||
|
|
||||||
var l = keys.length - 1;
|
|
||||||
for (var ii in keys) {
|
for (var ii in keys) {
|
||||||
var k = keys[ii];
|
this._readHelper(walletId, keys[ii], function(v, k) {
|
||||||
this._read(this._key(walletId, k), function(v) {
|
|
||||||
ret[k] = v;
|
ret[k] = v;
|
||||||
if (ii == l) return cb(ret);
|
console.log('[Storage.js.144:ret:]',k,i,l,v); //TODO
|
||||||
|
if (++i == l) {
|
||||||
|
|
||||||
|
console.log('[Storage.js.157] LKIST', ret); //TODO
|
||||||
|
return cb(ret);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -148,9 +165,8 @@ Storage.prototype.setName = function(walletId, name, cb) {
|
||||||
this.setGlobal('nameFor::' + walletId, name, cb);
|
this.setGlobal('nameFor::' + walletId, name, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.getName = function(walletId) {
|
Storage.prototype.getName = function(walletId, cb) {
|
||||||
var ret = this.getGlobal('nameFor::' + walletId);
|
this.getGlobal('nameFor::' + walletId, cb);
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.getWalletIds = function(cb) {
|
Storage.prototype.getWalletIds = function(cb) {
|
||||||
|
|
@ -185,17 +201,21 @@ Storage.prototype.getWallets = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.getWalletIds(function(ids) {
|
this.getWalletIds(function(ids) {
|
||||||
var l = ids.length - 1;
|
console.log('[Storage.js.197:ids:]',ids); //TODO
|
||||||
|
var l = ids.length, i=0;
|
||||||
if (!l)
|
if (!l)
|
||||||
return cb([]);
|
return cb([]);
|
||||||
|
|
||||||
for (var i in ids) {
|
for (var ii in ids) {
|
||||||
self.getName(ids[i], function(name) {
|
var id = ids[ii];
|
||||||
|
console.log('[Storage.js.206:id:]',id); //TODO
|
||||||
|
self.getName(id, function(name) {
|
||||||
wallets.push({
|
wallets.push({
|
||||||
id: ids[i],
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
});
|
});
|
||||||
if (i == l) {
|
console.log('[Storage.js.208:wallets:]',wallets); //TODO
|
||||||
|
if (++i == l) {
|
||||||
return cb(wallets);
|
return cb(wallets);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -232,7 +252,6 @@ Storage.prototype.setFromObj = function(walletId, obj, cb) {
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
console.log('[Storage.js.241]'); //TODO
|
|
||||||
var l = Object.keys(obj).length,
|
var l = Object.keys(obj).length,
|
||||||
i = 0;
|
i = 0;
|
||||||
for (var k in obj) {
|
for (var k in obj) {
|
||||||
|
|
|
||||||
|
|
@ -178,10 +178,10 @@ WalletFactory.prototype.read = function(walletId, skipFields, cb) {
|
||||||
* @TODO: Figure out in what unit is this reconnect delay.
|
* @TODO: Figure out in what unit is this reconnect delay.
|
||||||
* @param {number} opts.reconnectDelay milliseconds?
|
* @param {number} opts.reconnectDelay milliseconds?
|
||||||
* @param {number=} opts.version
|
* @param {number=} opts.version
|
||||||
|
* @param {callback} opts.version
|
||||||
* @return {Wallet}
|
* @return {Wallet}
|
||||||
*/
|
*/
|
||||||
WalletFactory.prototype.create = function(opts) {
|
WalletFactory.prototype.create = function(opts, cb) {
|
||||||
|
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.networkName = opts.networkName || 'testnet';
|
opts.networkName = opts.networkName || 'testnet';
|
||||||
|
|
||||||
|
|
@ -230,9 +230,12 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
opts.version = opts.version || this.version;
|
opts.version = opts.version || this.version;
|
||||||
|
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
w.store();
|
var self = this;
|
||||||
this.storage.setLastOpened(w.id);
|
w.store(function() {
|
||||||
return w;
|
self.storage.setLastOpened(w.id, function() {
|
||||||
|
return cb(null, w);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -364,15 +367,13 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
connectedOnce = true;
|
connectedOnce = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
<< << << < HEAD
|
joinNetwork.on('serverError', function() {
|
||||||
joinNetwork.on('serverError', function() { === === =
|
return cb('joinError');
|
||||||
self.network.on('serverError', function() { >>> >>> > wallet listing working
|
});
|
||||||
return cb('joinError');
|
|
||||||
});
|
|
||||||
|
|
||||||
joinNetwork.start(opts, function() {
|
joinNetwork.start(opts, function() {
|
||||||
joinNetwork.greet(decodedSecret.pubKey, opts.secretNumber);
|
joinNetwork.greet(decodedSecret.pubKey, opts.secretNumber);
|
||||||
joinNetwork.on('data', function(sender, data) {
|
joinNetwork.on('data', function(sender, data) {
|
||||||
if (data.type === 'walletId') {
|
if (data.type === 'walletId') {
|
||||||
if (data.networkName !== decodedSecret.networkName) {
|
if (data.networkName !== decodedSecret.networkName) {
|
||||||
return cb('badNetwork');
|
return cb('badNetwork');
|
||||||
|
|
@ -382,14 +383,18 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
data.opts.nickname = nickname;
|
data.opts.nickname = nickname;
|
||||||
data.opts.passphrase = passphrase;
|
data.opts.passphrase = passphrase;
|
||||||
data.opts.id = data.walletId;
|
data.opts.id = data.walletId;
|
||||||
var w = self.create(data.opts);
|
self.create(data.opts, function(err, w) {
|
||||||
w.sendWalletReady(decodedSecret.pubKey);
|
if (!err & w) {
|
||||||
return cb(null, w);
|
w.sendWalletReady(s.pubKey);
|
||||||
} else {
|
} else {
|
||||||
return cb('walletFull', w);
|
if (!err) err = 'walletFull';
|
||||||
}
|
}
|
||||||
});
|
return cb(err, w);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = WalletFactory;
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = WalletFactory;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function WalletLock(storage, walletId, timeoutMin) {
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
this.timeoutMin = timeoutMin || 5;
|
this.timeoutMin = timeoutMin || 5;
|
||||||
this.key = WalletLock._keyFor(walletId);
|
this.key = WalletLock._keyFor(walletId);
|
||||||
this._setLock(function() {});
|
// this._setLock(function() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletLock._keyFor = function(walletId) {
|
WalletLock._keyFor = function(walletId) {
|
||||||
|
|
@ -18,7 +18,9 @@ WalletLock._keyFor = function(walletId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletLock.prototype._isLockedByOther = function(cb) {
|
WalletLock.prototype._isLockedByOther = function(cb) {
|
||||||
var self=this;
|
var self = this;
|
||||||
|
|
||||||
|
console.log('[WalletLock.js.22]'); //TODO
|
||||||
this.storage.getGlobal(this.key, function(json) {
|
this.storage.getGlobal(this.key, function(json) {
|
||||||
var wl = json ? JSON.parse(json) : null;
|
var wl = json ? JSON.parse(json) : null;
|
||||||
var t = wl ? (Date.now() - wl.expireTs) : false;
|
var t = wl ? (Date.now() - wl.expireTs) : false;
|
||||||
|
|
@ -33,10 +35,13 @@ WalletLock.prototype._isLockedByOther = function(cb) {
|
||||||
|
|
||||||
|
|
||||||
WalletLock.prototype._setLock = function(cb) {
|
WalletLock.prototype._setLock = function(cb) {
|
||||||
|
|
||||||
this.storage.setGlobal(this.key, {
|
this.storage.setGlobal(this.key, {
|
||||||
sessionId: this.sessionId,
|
sessionId: this.sessionId,
|
||||||
expireTs: Date.now() + this.timeoutMin * 60 * 1000,
|
expireTs: Date.now() + this.timeoutMin * 60 * 1000,
|
||||||
}, cb);
|
}, function() {
|
||||||
|
cb(null);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -45,6 +50,7 @@ WalletLock.prototype.keepAlive = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this._isLockedByOther(function(t) {
|
this._isLockedByOther(function(t) {
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
return cb(new Error('Wallet is already open. Close it to proceed or wait ' + t + ' seconds if you close it already'));
|
return cb(new Error('Wallet is already open. Close it to proceed or wait ' + t + ' seconds if you close it already'));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ angular
|
||||||
// IDLE timeout
|
// IDLE timeout
|
||||||
var timeout = config.wallet.idleDurationMin * 60 || 300;
|
var timeout = config.wallet.idleDurationMin * 60 || 300;
|
||||||
$idleProvider.idleDuration(timeout); // in seconds
|
$idleProvider.idleDuration(timeout); // in seconds
|
||||||
$idleProvider.warningDuration(20); // in seconds
|
$idleProvider.warningDuration(40); // in seconds
|
||||||
$keepaliveProvider.interval(2); // in seconds
|
$keepaliveProvider.interval(30); // in seconds
|
||||||
})
|
})
|
||||||
.run(function($rootScope, $location, $idle, gettextCatalog) {
|
.run(function($rootScope, $location, $idle, gettextCatalog) {
|
||||||
gettextCatalog.currentLanguage = config.defaultLanguage;
|
gettextCatalog.currentLanguage = config.defaultLanguage;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ function GoogleDrive(config) {
|
||||||
|
|
||||||
window.InitGoogleDrive = function() {
|
window.InitGoogleDrive = function() {
|
||||||
|
|
||||||
console.log('[googleDrive.js.18] setting loaded'); //TODO
|
// console.log('[googleDrive.js.18] setting loaded'); //TODO
|
||||||
loaded = 1;
|
loaded = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ GoogleDrive.prototype.initLoaded = function() {
|
||||||
*/
|
*/
|
||||||
GoogleDrive.prototype.checkAuth = function() {
|
GoogleDrive.prototype.checkAuth = function() {
|
||||||
|
|
||||||
console.log('\tChecking google Auth'); //TODO
|
console.log('\tChecking google Auth');
|
||||||
gapi.auth.authorize({
|
gapi.auth.authorize({
|
||||||
'client_id': this.clientId,
|
'client_id': this.clientId,
|
||||||
'scope': SCOPES,
|
'scope': SCOPES,
|
||||||
|
|
@ -61,7 +61,7 @@ GoogleDrive.prototype.checkAuth = function() {
|
||||||
*/
|
*/
|
||||||
GoogleDrive.prototype.handleAuthResult = function(authResult) {
|
GoogleDrive.prototype.handleAuthResult = function(authResult) {
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log('[googleDrive.js.39:authResult:]', authResult); //TODO
|
// console.log('[googleDrive.js.39:authResult:]', authResult); //TODO
|
||||||
|
|
||||||
if (authResult.error) {
|
if (authResult.error) {
|
||||||
if (authResult.error) {
|
if (authResult.error) {
|
||||||
|
|
@ -81,61 +81,121 @@ GoogleDrive.prototype.checkReady = function() {
|
||||||
throw new Error('goggle drive is not ready!');
|
throw new Error('goggle drive is not ready!');
|
||||||
};
|
};
|
||||||
|
|
||||||
GoogleDrive.prototype.getItem = function(k) {
|
GoogleDrive.prototype._httpGet = function(theUrl) {
|
||||||
this.checkReady();
|
var accessToken = gapi.auth.getToken().access_token;
|
||||||
throw new Error('getItem not implemented');
|
var xmlHttp = null;
|
||||||
|
|
||||||
|
xmlHttp = new XMLHttpRequest();
|
||||||
|
xmlHttp.open("GET", theUrl, false);
|
||||||
|
xmlHttp.setRequestHeader('Authorization', 'Bearer ' + accessToken);
|
||||||
|
xmlHttp.send(null);
|
||||||
|
return xmlHttp.responseText;
|
||||||
|
}
|
||||||
|
|
||||||
|
GoogleDrive.prototype.getItem = function(k, cb) {
|
||||||
|
console.log('[googleDrive.js.95:getItem:]', k); //TODO
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.checkReady();
|
||||||
|
self._idForName(k, function(kId) {
|
||||||
|
// console.log('[googleDrive.js.89:kId:]', kId); //TODO
|
||||||
|
if (!kId)
|
||||||
|
return cb(null);
|
||||||
|
|
||||||
|
|
||||||
|
var args = {
|
||||||
|
'path': '/drive/v2/files/' + kId,
|
||||||
|
'method': 'GET',
|
||||||
|
};
|
||||||
|
// console.log('[googleDrive.js.95:args:]', args); //TODO
|
||||||
|
|
||||||
|
var request = gapi.client.request(args);
|
||||||
|
request.execute(function(res) {
|
||||||
|
// console.log('[googleDrive.js.175:res:]', res); //TODO
|
||||||
|
if (!res || !res.downloadUrl)
|
||||||
|
return cb(null);
|
||||||
|
|
||||||
|
return cb(self._httpGet(res.downloadUrl));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
GoogleDrive.prototype.setItem = function(k, v, cb) {
|
GoogleDrive.prototype.setItem = function(k, v, cb) {
|
||||||
|
// console.log('[googleDrive.js.111:setItem:]', k, v); //TODO
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.checkReady();
|
self.checkReady();
|
||||||
|
self._idForName(this.home, function(parentId) {
|
||||||
|
preconditions.checkState(parentId);
|
||||||
|
// console.log('[googleDrive.js.118:parentId:]', parentId); //TODO
|
||||||
|
self._idForName(k, function(kId) {
|
||||||
|
|
||||||
var parendId = self._idForName[this.home];
|
// console.log('[googleDrive.js.105]', parentId, kId); //TODO
|
||||||
preconditions.checkState(parentId);
|
|
||||||
|
|
||||||
|
|
||||||
var boundary = '-------314159265358979323846';
|
var boundary = '-------314159265358979323846';
|
||||||
var delimiter = "\r\n--" + boundary + "\r\n";
|
var delimiter = "\r\n--" + boundary + "\r\n";
|
||||||
var close_delim = "\r\n--" + boundary + "--";
|
var close_delim = "\r\n--" + boundary + "--";
|
||||||
|
|
||||||
var metadata = {
|
var metadata = {
|
||||||
'title': k,
|
'title': k,
|
||||||
'mimeType': 'application/octet-stream',
|
'mimeType': 'application/octet-stream',
|
||||||
'parents': [parentId],
|
'parents': [{
|
||||||
};
|
'id': parentId
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
var base64Data = btoa(v);
|
var base64Data = btoa(v);
|
||||||
var multipartRequestBody =
|
var multipartRequestBody =
|
||||||
delimiter +
|
delimiter +
|
||||||
'Content-Type: application/json\r\n\r\n' +
|
'Content-Type: application/json\r\n\r\n' +
|
||||||
JSON.stringify(metadata) +
|
JSON.stringify(metadata) +
|
||||||
delimiter +
|
delimiter +
|
||||||
'Content-Type: application/octet-stream \r\n' +
|
'Content-Type: application/octet-stream \r\n' +
|
||||||
'Content-Transfer-Encoding: base64\r\n' +
|
'Content-Transfer-Encoding: base64\r\n' +
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
base64Data +
|
base64Data +
|
||||||
close_delim;
|
close_delim;
|
||||||
console.log('[googleDrive.js.105:multipartRequestBody:]',multipartRequestBody); //TODO
|
|
||||||
|
|
||||||
var request = gapi.client.request({
|
var args = {
|
||||||
'path': '/upload/drive/v2/files',
|
'path': '/upload/drive/v2/files' + (kId ? '/' + kId : ''),
|
||||||
'method': 'POST',
|
'method': kId ? 'PUT' : 'POST',
|
||||||
'params': {
|
'params': {
|
||||||
'uploadType': 'multipart',
|
'uploadType': 'multipart',
|
||||||
},
|
},
|
||||||
'headers': {
|
'headers': {
|
||||||
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
|
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
|
||||||
},
|
},
|
||||||
'body': multipartRequestBody
|
'body': multipartRequestBody
|
||||||
|
}
|
||||||
|
// console.log('[googleDrive.js.148:args:]', args); //TODO
|
||||||
|
|
||||||
|
var request = gapi.client.request(args);
|
||||||
|
request.execute(cb);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
request.execute(cb);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GoogleDrive.prototype.removeItem = function(k) {
|
GoogleDrive.prototype.removeItem = function(k, cb) {
|
||||||
this.checkReady();
|
var self = this;
|
||||||
|
|
||||||
throw new Error('removeItem not implemented');
|
self.checkReady();
|
||||||
|
self._idForName(this.home, function(parentId) {
|
||||||
|
preconditions.checkState(parentId);
|
||||||
|
self._idForName(k, function(kId) {
|
||||||
|
|
||||||
|
var args = {
|
||||||
|
'path': '/drive/v2/files/' + kId,
|
||||||
|
'method': 'DELETE',
|
||||||
|
};
|
||||||
|
var request = gapi.client.request(args);
|
||||||
|
request.execute(function() {
|
||||||
|
if (cb)
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
GoogleDrive.prototype.clear = function() {
|
GoogleDrive.prototype.clear = function() {
|
||||||
|
|
@ -158,13 +218,14 @@ GoogleDrive.prototype._mkdir = function(cb) {
|
||||||
'mimeType': "application/vnd.google-apps.folder",
|
'mimeType': "application/vnd.google-apps.folder",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
request.execute(function(){
|
request.execute(function() {
|
||||||
self._idForName(this.home, cb);
|
self._idForName(self.home, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GoogleDrive.prototype._idForName = function(name, cb) {
|
GoogleDrive.prototype._idForName = function(name, cb) {
|
||||||
|
// console.log('[googleDrive.js.199:_idForName:]', name); //TODO
|
||||||
preconditions.checkArgument(name);
|
preconditions.checkArgument(name);
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -174,17 +235,24 @@ GoogleDrive.prototype._idForName = function(name, cb) {
|
||||||
self.ts = self.ts * 1.5;
|
self.ts = self.ts * 1.5;
|
||||||
return setTimeout(self._idForName.bind(self, name, cb), self.ts);
|
return setTimeout(self._idForName.bind(self, name, cb), self.ts);
|
||||||
}
|
}
|
||||||
console.log('[googleDrive.js.178:name:]',name); //TODO
|
// console.log('[googleDrive.js.178:name:]', name); //TODO
|
||||||
|
|
||||||
if (self.idCache[name])
|
if (self.idCache[name]) {
|
||||||
|
// console.log('[googleDrive.js.212:] FROM CACHE', name, self.idCache[name]); //TODO
|
||||||
return cb(self.idCache[name]);
|
return cb(self.idCache[name]);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Querying for: ', name); //TODO
|
console.log('Querying for: ', name); //TODO
|
||||||
var args;
|
var args;
|
||||||
|
|
||||||
var idParent = name == this.home ? 'root' : self.idCache[this.home] ;
|
var idParent = name == this.home ? 'root' : self.idCache[this.home];
|
||||||
|
|
||||||
console.log('[googleDrive.js.177:idParent:]',idParent); //TODO
|
if (!idParent) {
|
||||||
|
return self._mkdir(function() {
|
||||||
|
self._idForName(name, cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// console.log('[googleDrive.js.177:idParent:]', idParent); //TODO
|
||||||
preconditions.checkState(idParent);
|
preconditions.checkState(idParent);
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
|
|
@ -195,13 +263,12 @@ console.log('[googleDrive.js.177:idParent:]',idParent); //TODO
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[googleDrive.js.196:args:]', args); //TODO
|
|
||||||
var request = gapi.client.request(args);
|
var request = gapi.client.request(args);
|
||||||
request.execute(function(res) {
|
request.execute(function(res) {
|
||||||
console.log('[googleDrive.js.175:res:]', res); //TODO
|
|
||||||
var i = res.items && res.items[0] ? res.items[0].id : false;
|
var i = res.items && res.items[0] ? res.items[0].id : false;
|
||||||
if (i)
|
if (i)
|
||||||
self.idCache[name] = i;
|
self.idCache[name] = i;
|
||||||
|
// console.log('[googleDrive.js.238] CACHING ' + name + ':' + i); //TODO
|
||||||
return cb(self.idCache[name]);
|
return cb(self.idCache[name]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -232,13 +299,13 @@ GoogleDrive.prototype.allKeys = function(cb) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
request.execute(function(res) {
|
request.execute(function(res) {
|
||||||
console.log('[googleDrive.js.152:res:]', res); //TODO
|
// console.log('[googleDrive.js.152:res:]', res); //TODO
|
||||||
if (res.error)
|
if (res.error)
|
||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
|
|
||||||
var ret = [];
|
var ret = [];
|
||||||
for (var ii in res.items) {
|
for (var ii in res.items) {
|
||||||
ret.push(res[ii].id);
|
ret.push(res.items[ii].title);
|
||||||
}
|
}
|
||||||
return cb(ret);
|
return cb(ret);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue