Commit 139ab0be authored by François Billioud's avatar François Billioud

propose different storage nodes not tested yet

parent ad9d385a
......@@ -552,15 +552,8 @@
}
getIndex: function() {return this.index},
save: function() {
this.storage.saveDocument(JSON.stringify(this.getIndex()), "jio.index", "text", true);
}
}
/***************************************************************
*********************** CryptedStorage *************************/
/***************************************************************
*********************** CryptedStorage *************************/
/**
* Class CryptedStorage
* @class provides usual API to encrypte data storing documents
......@@ -570,30 +563,100 @@
* "method" : (optional) the algorythm to use - Only sjcl available for the moment
* @param applicant : object containing inforamtion about the person/application needing this JIO object
*/
JIO.ReplicateStorage = function(data, applicant) {
JIO.CryptedStorage = function(data, applicant) {
this.storage = createStorage(data.storage, applicant);
this.password = data.password;
}
JIO.ReplicateStorage.prototype = {
JIO.CryptedStorage.prototype = {
userNameAvailable: function(name, option) {return this.storage.userNameAvailable.apply(this.storage,arguments)},
loadDocument: function(fileName, option) {
var cryptedStorage = this;
var newOption = copy(option);
newOption.success = function(data) {
if(option.success) {option.success(sjcl.decrypt(data,cryptedStorage.password))}//case asynchronous
if(option.success) {option.success(sjcl.decrypt(cryptedStorage.password,data))}//case asynchronous
}
var data = this.storage.loadDocument(fileName, newOption);
return data ? sjcl.decrypt(data,cryptedStorage.password) : data //case synchronous
return data ? sjcl.decrypt(cryptedStorage.password,data) : data //case synchronous
},
saveDocument: function(data, fileName, option) {
return this.storage.saveDocument(sjcl.encrypt(data,this.password), fileName, option)
var encryptedData = sjcl.encrypt(this.password,data);
return this.storage.saveDocument(encryptedData, fileName, option)
},
deleteDocument: function(file, option) {return this.storage.deleteDocument.apply(this.storage,arguments)},
getDocumentList: function(option) {return this.storage.getDocumentList.apply(this.storage,arguments)}
}
/***************************************************************
*********************** ReplicateStorage *************************/
/***************************************************************
*********************** AsynchronousStorage *************************/
/**
* Class AsynchronousStorage
* @class manage the pending list of requests
* @param data : object containing every element needed to build the storage :
* "storage" : the storage to manage
* @param applicant : object containing inforamtion about the person/application needing this JIO object
*/
JIO.AsynchronousStorage = function(data, applicant) {
this.storage = createStorage(data.storage, applicant);
this.pendingList = {};//contains the list of pending actions
}
JIO.AsynchronousStorage.prototype = {
userNameAvailable: function(name, option) {
var asynchronousStorage = this;
var requestID = this.addPendingAction(this.userNameAvailable, arguments);
var instruction = function() {asynchronousStorage.removePendingAction(requestID)}
option.success = addInstruction(instruction,option.success,true);
option.errorHandler = addInstruction(instruction,option.errorHandler,true);
return this.storage.userNameAvailable(name, option);
},
loadDocument: function(fileName, option) {
var asynchronousStorage = this;
var requestID = this.addPendingAction(this.loadDocument, arguments);
var instruction = function() {asynchronousStorage.removePendingAction(requestID)}
option.success = addInstruction(instruction,option.success,true);
option.errorHandler = addInstruction(instruction,option.errorHandler,true);
return this.storage.loadDocument(fileName, option);
},
saveDocument: function(data, fileName, option) {
var asynchronousStorage = this;
var requestID = this.addPendingAction(this.saveDocument, arguments);
var instruction = function() {asynchronousStorage.removePendingAction(requestID)}
option.success = addInstruction(instruction,option.success,true);
option.errorHandler = addInstruction(instruction,option.errorHandler,true);
return this.storage.saveDocument(data, fileName, option);
},
deleteDocument: function(file, option) {
var asynchronousStorage = this;
var requestID = this.addPendingAction(this.deleteDocument, arguments);
var instruction = function() {asynchronousStorage.removePendingAction(requestID)}
option.success = addInstruction(instruction,option.success,true);
option.errorHandler = addInstruction(instruction,option.errorHandler,true);
return this.storage.deleteDocument(file, option);
},
getDocumentList: function(option) {
var asynchronousStorage = this;
var requestID = this.addPendingAction(this.getDocumentList, arguments);
var instruction = function() {asynchronousStorage.removePendingAction(requestID)}
option.success = addInstruction(instruction,option.success,true);
option.errorHandler = addInstruction(instruction,option.errorHandler,true);
return this.storage.getDocumentList(option);
},
addPendingAction: function(action, argument) {
var ID = Date.now();
var task = {action: action, arguments:argument}
this.getPendingList()[ID] = task;
return ID;
},
removePendingAction: function(ID) {
delete this.getPendingList()[ID];
},
getPendingList: function() {return this.pendingList}
}
/***************************************************************
*********************** ReplicateStorage *************************/
/**
* Class ReplicateStorage
* @class provides usual API to replicate save/load/delete in a list of storages
......@@ -700,8 +763,8 @@
}
}
/***************************************************************
*********************** MultipleStorage *************************/
/***************************************************************
*********************** MultipleStorage *************************/
/**
* Class MultipleStorage
* @class provides usual API to save/load/delete documents in a list of storages
......@@ -786,7 +849,7 @@
},
updateDocumentList: function() {
for(var storage in this.storageList) { this.documentList[storage] = this.storageList[storage].getDocumentList() }
for(var storage in this.storageList) {this.documentList[storage] = this.storageList[storage].getDocumentList()}
},
analysePath: function(path) {
var storage = path.shift();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment