mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(dom) saveDatatToStorage && getDataFromStorage do not call checkStorageHash
This commit is contained in:
parent
c28bae15cc
commit
ffca56f7cd
2 changed files with 40 additions and 32 deletions
|
|
@ -1520,14 +1520,15 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
error : pCallBack.error
|
||||
};
|
||||
|
||||
DOM.getDataFromStorage(lPath, function(data, hash) {
|
||||
if (data)
|
||||
lFunc(data);
|
||||
else {
|
||||
lHash = hash;
|
||||
DOM.getCurrentFileContent(lParams, lCurrentFile);
|
||||
}
|
||||
});
|
||||
|
||||
DOM.checkStorageHash(lPath, function(error, equal, hash) {
|
||||
Util.ifExec(!error && equal, function() {
|
||||
DOM.getDataFromStorage(lPath, lFunc);
|
||||
}, function() {
|
||||
lHash = hash;
|
||||
DOM.getCurrentFileContent(lParams, lCurrentFile);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -1797,7 +1798,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
* @param data
|
||||
* @param callback
|
||||
*/
|
||||
this.saveDataToStorage = function(name, data, callback) {
|
||||
this.saveDataToStorage = function(name, data, hash, callback) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
var allowed = config.localStorage,
|
||||
isDir = DOM.isCurrentIsDir(),
|
||||
|
|
@ -1807,13 +1808,16 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
if (!allowed || isDir)
|
||||
Util.exec(callback);
|
||||
else
|
||||
DOM.checkStorageHash(name, function(error, equal, hash) {
|
||||
if (!error && !equal) {
|
||||
Storage.set(nameHash, hash);
|
||||
Storage.set(nameData, data);
|
||||
}
|
||||
Util.ifExec(hash, function() {
|
||||
Storage.set(nameHash, hash);
|
||||
Storage.set(nameData, data);
|
||||
|
||||
Util.exec(callback, hash);
|
||||
}, function(callback) {
|
||||
DOM.loadCurrentHash(function(loadHash) {
|
||||
hash = loadHash;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -1827,7 +1831,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
*/
|
||||
this.getDataFromStorage = function(name, callback) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
var hash,
|
||||
var data, hash,
|
||||
nameHash = name + '-hash',
|
||||
nameData = name + '-data',
|
||||
allowed = config.localStorage,
|
||||
|
|
@ -1835,15 +1839,12 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
|
||||
if (!allowed || isDir)
|
||||
Util.exec(callback);
|
||||
else
|
||||
DOM.checkStorageHash(name, function(error, equal, hash) {
|
||||
var data;
|
||||
|
||||
if (!error && equal)
|
||||
data = Storage.get(nameData, data);
|
||||
|
||||
Util.exec(callback, data, hash);
|
||||
});
|
||||
else {
|
||||
data = Storage.get(nameData);
|
||||
hash = Storage.get(nameHash);
|
||||
|
||||
Util.exec(callback, data, hash);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,12 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch;
|
|||
var query,
|
||||
isAllowed = DOM.Storage.isAllowed(),
|
||||
isString = Util.isString(patch),
|
||||
lessLength = patch.length < lValue.length;
|
||||
lessLength = patch.length < lValue.length,
|
||||
onSave = function(hash) {
|
||||
return function(data) {
|
||||
onSave(data, hash);
|
||||
};
|
||||
};
|
||||
|
||||
Value = lValue;
|
||||
|
||||
|
|
@ -169,15 +174,15 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch;
|
|||
}
|
||||
|
||||
|
||||
Util.ifExec(!isAllowed, function() {
|
||||
DOM.RESTful.save(lPath, lValue, onSave, query);
|
||||
Util.ifExec(!isAllowed, function(loadHash) {
|
||||
DOM.RESTful.save(lPath, lValue, onSave(loadHash), query);
|
||||
}, function(callback) {
|
||||
DOM.checkStorageHash(lPath, function(error, equal) {
|
||||
DOM.checkStorageHash(lPath, function(error, equal, loadHash) {
|
||||
if (!error) {
|
||||
if (!equal)
|
||||
query = '';
|
||||
|
||||
callback();
|
||||
callback(loadHash);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -206,8 +211,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch;
|
|||
patch = Diff.createPatch(Value, pNewValue);
|
||||
Util.exec(pCallBack, patch);
|
||||
}, function(callback) {
|
||||
DOM.getCurrentData(function(data) {
|
||||
Value = data.data;
|
||||
var path = DOM.getCurrentPath();
|
||||
|
||||
DOM.getDataFromStorage(path, function(data) {
|
||||
Value = data;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
|
@ -254,7 +261,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch;
|
|||
|
||||
if (!isError) {
|
||||
Edit.showMessage(text);
|
||||
DOM.saveDataToStorage(path, Value);
|
||||
DOM.saveDataToStorage(path, Value, hash);
|
||||
} else {
|
||||
ret = Dialog.confirm(text + msg);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue