migration from localStorage to fileStorege
This commit is contained in:
parent
f47d6b0564
commit
cf557fe018
4 changed files with 65 additions and 16 deletions
|
|
@ -27,9 +27,14 @@ angular
|
|||
['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) {
|
||||
var orig = $delegate[level];
|
||||
$delegate[level] = function() {
|
||||
var args = [].slice.call(arguments).map(function(v){
|
||||
if (typeof v == 'undefined') return 'undefined';
|
||||
if (typeof v == 'object') return JSON.stringify(v).substr(0,200)+'...';
|
||||
var args = [].slice.call(arguments);
|
||||
args = args.map(function(v) {
|
||||
if (typeof v == 'undefined') v = 'undefined';
|
||||
if (typeof v == 'object') {
|
||||
v = JSON.stringify(v);
|
||||
if (v.length > 200)
|
||||
v = v.substr(0, 197) + '...';
|
||||
}
|
||||
return v;
|
||||
});
|
||||
historicLog.add(level, args.join(' '));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash) {
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log) {
|
||||
var root = {};
|
||||
|
||||
var defaultConfig = {
|
||||
|
|
@ -48,6 +48,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
};
|
||||
|
||||
root.get = function(cb) {
|
||||
|
||||
storageService.getConfig(function(err, localConfig) {
|
||||
if (localConfig) {
|
||||
configCache = JSON.parse(localConfig);
|
||||
|
|
@ -61,9 +62,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
}
|
||||
|
||||
} else {
|
||||
configCache = defaultConfig;
|
||||
configCache = lodash.clone(defaultConfig);
|
||||
};
|
||||
|
||||
$log.debug('Preferences read:', configCache)
|
||||
return cb(err, configCache);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -139,10 +139,21 @@ angular.module('copayApp.services')
|
|||
$rootScope.$emit('Local/DeviceError', err);
|
||||
return cb(err);
|
||||
}
|
||||
if (!profile) return cb(new Error('NOPROFILE: No profile'));
|
||||
$log.debug('Profile read');
|
||||
if (!profile) {
|
||||
// Migration??
|
||||
storageService.tryToMigrate(function(err, migratedProfile) {
|
||||
if (err) return cb(err);
|
||||
if (!migratedProfile)
|
||||
return cb(new Error('NOPROFILE: No profile'));
|
||||
|
||||
profile = migratedProfile;
|
||||
return root.bindProfile(profile, cb);
|
||||
})
|
||||
} else {
|
||||
$log.debug('Profile read');
|
||||
return root.bindProfile(profile, cb);
|
||||
}
|
||||
|
||||
return root.bindProfile(profile, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -268,11 +279,17 @@ angular.module('copayApp.services')
|
|||
|
||||
|
||||
root.create = function(cb) {
|
||||
root._createNewProfile(function(err, p) {
|
||||
if (err) return cb(err);
|
||||
root.bindProfile(p, function(err) {
|
||||
storageService.storeNewProfile(p, function(err) {
|
||||
return cb(err);
|
||||
$log.info('Creating profile');
|
||||
configService.get(function(err) {
|
||||
root.applyConfig();
|
||||
root._createNewProfile(function(err, p) {
|
||||
if (err) return cb(err);
|
||||
|
||||
console.log('[profileService.js.287]'); //TODO
|
||||
root.bindProfile(p, function(err) {
|
||||
storageService.storeNewProfile(p, function(err) {
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,6 +47,32 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
root.tryToMigrate = function(cb) {
|
||||
if (!isCordova) return cb();
|
||||
|
||||
localStorageService.get('profile', function(err, p) {
|
||||
if (err) cb(err);
|
||||
if (!p) return cb();
|
||||
$log.info('Starting Migration profile to File storage...')
|
||||
fileStorageService.create('profile', p, function(err) {
|
||||
if (err) cb(err);
|
||||
$log.info('Profile Migrated successfully');
|
||||
|
||||
localStorageService.get('config', function(err, c) {
|
||||
if (err) cb(err);
|
||||
if (!c) return cb(null, p);
|
||||
fileStorageService.create('config', c, function(err) {
|
||||
if (err) cb(err);
|
||||
$log.info('Config Migrated successfully');
|
||||
return cb(null, p)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
root.storeNewProfile = function(profile, cb) {
|
||||
encryptOnMobile(profile.toObj(), function(err, x) {
|
||||
storage.create('profile', x, cb);
|
||||
|
|
@ -62,8 +88,8 @@ angular.module('copayApp.services')
|
|||
root.getProfile = function(cb) {
|
||||
storage.get('profile', function(err, str) {
|
||||
|
||||
if (err || !str)
|
||||
// Migrate ?
|
||||
if (err || !str)
|
||||
// Migrate ?
|
||||
return cb(err);
|
||||
|
||||
decryptOnMobile(str, function(err, str) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue