mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-27 01:36:28 +00:00
feature(storage) change to async
This commit is contained in:
parent
059b2f054b
commit
961584ba65
4 changed files with 106 additions and 102 deletions
|
|
@ -1340,18 +1340,20 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
*/
|
||||
this.checkStorageHash = function(name, callback) {
|
||||
DOM.loadCurrentHash(function(loadHash) {
|
||||
var equal, error,
|
||||
nameHash = name + '-hash',
|
||||
Storage = DOM.Storage,
|
||||
storeHash = Storage.get(name + '-hash'),
|
||||
isContain = Util.isContainStr(loadHash, 'error');
|
||||
var Storage = DOM.Storage;
|
||||
|
||||
if (isContain)
|
||||
error = loadHash;
|
||||
else if (loadHash === storeHash)
|
||||
equal = true;
|
||||
|
||||
Util.exec(callback, error, equal, loadHash);
|
||||
Storage.get(name + '-hash', function(storeHash) {
|
||||
var equal, error,
|
||||
nameHash = name + '-hash',
|
||||
isContain = Util.isContainStr(loadHash, 'error');
|
||||
|
||||
if (isContain)
|
||||
error = loadHash;
|
||||
else if (loadHash === storeHash)
|
||||
equal = true;
|
||||
|
||||
Util.exec(callback, error, equal, loadHash);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -1407,10 +1409,20 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
if (!allowed || isDir)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
data = Storage.get(nameData);
|
||||
hash = Storage.get(nameHash);
|
||||
Util.asyncCall([
|
||||
function(callback) {
|
||||
Storage.get(nameData, function(data) {
|
||||
Util.exec(callback, data);
|
||||
});
|
||||
},
|
||||
function(callback) {
|
||||
Storage.get(nameHash, function(hash) {
|
||||
Util.exec(callback, hash);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
|
||||
|
||||
Util.exec(callback, data, hash);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,56 +29,57 @@ var Util, DOM;
|
|||
};
|
||||
|
||||
/** remove element */
|
||||
this.remove = function(item) {
|
||||
var ret = this;
|
||||
this.remove = function(item, callback) {
|
||||
var ret = Allowed;
|
||||
|
||||
if (Allowed)
|
||||
if (ret)
|
||||
localStorage.removeItem(item);
|
||||
|
||||
Util.exec(callback, ret);
|
||||
|
||||
return ret;
|
||||
return this;
|
||||
};
|
||||
|
||||
/** если доступен localStorage и
|
||||
* в нём есть нужная нам директория -
|
||||
* записываем данные в него
|
||||
*/
|
||||
this.set = function(name, data) {
|
||||
var ret = this;
|
||||
this.set = function(name, data, callback) {
|
||||
var str, ret = Allowed && name;
|
||||
|
||||
if (Util.isObject(data))
|
||||
str = Util.stringifyJSON(data);
|
||||
|
||||
if (Allowed && name)
|
||||
localStorage.setItem(name, data);
|
||||
localStorage.setItem(name, str || data);
|
||||
|
||||
return ret;
|
||||
Util.exec(callback, ret);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** Если доступен Storage принимаем из него данные*/
|
||||
this.get = function(name) {
|
||||
this.get = function(name, callback) {
|
||||
var ret;
|
||||
|
||||
if (Allowed)
|
||||
ret = localStorage.getItem(name);
|
||||
|
||||
Util.exec(callback, ret);
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/* get all Storage from local storage */
|
||||
this.getAll = function() {
|
||||
var ret = null;
|
||||
|
||||
if (Allowed)
|
||||
ret = localStorage;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/** функция чистит весь кэш для всех каталогов*/
|
||||
this.clear = function() {
|
||||
var ret = this;
|
||||
this.clear = function(callback) {
|
||||
var ret = Allowed;
|
||||
|
||||
if (Allowed)
|
||||
if (ret)
|
||||
localStorage.clear();
|
||||
|
||||
return ret;
|
||||
Util.exec(callback, ret);
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
})(Util, DOM);
|
||||
|
|
|
|||
|
|
@ -51,40 +51,42 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb;
|
|||
}
|
||||
|
||||
|
||||
GitHub.autorize = function(pCallBack, pCode) {
|
||||
var lCode, lToken = Storage.get('token');
|
||||
|
||||
if (lToken) {
|
||||
GitHub.Login(lToken);
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
else {
|
||||
lCode = pCode || window.location.search;
|
||||
|
||||
if (lCode || Util.isContainStr(lCode, '?code=') )
|
||||
CloudCmd.getConfig(function(pConfig) {
|
||||
DOM.ajax({
|
||||
type : 'put',
|
||||
url : pConfig && pConfig.apiURL + '/auth',
|
||||
data : Util.removeStr(lCode, '?code='),
|
||||
success : function(pData) {
|
||||
if (pData && pData.token) {
|
||||
lToken = pData.token;
|
||||
|
||||
GitHub.Login(lToken);
|
||||
Storage.set('token', lToken);
|
||||
Util.exec(pCallBack);
|
||||
GitHub.autorize = function(callback, code) {
|
||||
Storage.get('token', function(token) {
|
||||
var code, isContain,
|
||||
URL = '//' + window.location.host + '/auth/github';
|
||||
|
||||
if (token) {
|
||||
GitHub.Login(token);
|
||||
Util.exec(callback);
|
||||
} else {
|
||||
if (!code)
|
||||
code = window.location.search;
|
||||
|
||||
isContain = Util.isContainStr(code, '?code=');
|
||||
|
||||
if (!isContain)
|
||||
DOM.openWindow(URL);
|
||||
else
|
||||
CloudCmd.getConfig(function(config) {
|
||||
DOM.ajax({
|
||||
type : 'put',
|
||||
url : config && config.apiURL + '/auth',
|
||||
data : Util.removeStr(code, '?code='),
|
||||
success : function(data) {
|
||||
if (data && data.token) {
|
||||
token = data.token;
|
||||
|
||||
GitHub.Login(token);
|
||||
Storage.set('token', token);
|
||||
Util.exec(callback);
|
||||
} else
|
||||
Util.log('Worning: token not getted...');
|
||||
}
|
||||
else
|
||||
Util.log('Worning: token not getted...');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
else{
|
||||
var lUrl = '//' + window.location.host + '/auth/github';
|
||||
DOM.openWindow(lUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GitHub.getUserData = function(pCallBack) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue