Add method 'createItem' to DB plugins
This commit is contained in:
parent
126a57d5ab
commit
5eade81294
4 changed files with 34 additions and 0 deletions
|
|
@ -11,6 +11,9 @@ EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
|||
var key = cryptoUtil.kdfbinary(this.password + this.email);
|
||||
InsightStorage.prototype.getItem.apply(this, [name,
|
||||
function(err, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var decryptedJson = cryptoUtil.decrypt(key, body);
|
||||
if (!decryptedJson) {
|
||||
return callback('Internal Error');
|
||||
|
|
|
|||
|
|
@ -95,6 +95,16 @@ GoogleDrive.prototype._httpGet = function(theUrl) {
|
|||
return xmlHttp.responseText;
|
||||
}
|
||||
|
||||
GoogleDrive.prototype.createItem = function(name, value, callback) {
|
||||
this.getItem(name, function(err, retrieved) {
|
||||
if (err || !retrieved) {
|
||||
return this.setItem(name, value, callback);
|
||||
} else {
|
||||
return callback('EEXISTS');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.getItem = function(k, cb) {
|
||||
//console.log('[googleDrive.js.95:getItem:]', k); //TODO
|
||||
var self = this;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ InsightStorage.prototype.setCredentials = function(email, password, opts) {
|
|||
this.password = password;
|
||||
};
|
||||
|
||||
InsightStorage.prototype.createItem = function(name, value, callback) {
|
||||
var self = this;
|
||||
this.getItem(name, function(err, retrieved) {
|
||||
if (err || !retrieved) {
|
||||
return self.setItem(name, value, callback);
|
||||
} else {
|
||||
return callback('EEXISTS');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
InsightStorage.prototype.getItem = function(name, callback) {
|
||||
var key = cryptoUtil.kdf(this.password + this.email);
|
||||
var secret = cryptoUtil.kdf(key, this.password);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,16 @@ LocalStorage.prototype.getItem = function(k,cb) {
|
|||
return cb(null, localStorage.getItem(k));
|
||||
};
|
||||
|
||||
/**
|
||||
* Same as setItem, but fails if an item already exists
|
||||
*/
|
||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||
if (localStorage.getItem(name)) {
|
||||
return callback('EEXISTS');
|
||||
}
|
||||
return this.setItem(name, value, callback);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.setItem = function(k,v,cb) {
|
||||
localStorage.setItem(k,v);
|
||||
return cb();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue