mirror of https://github.com/BTCPrivate/copay.git
fix storing files at dataDirectory
This commit is contained in:
parent
648d754556
commit
55d8c00658
|
@ -29,11 +29,17 @@ angular
|
||||||
$delegate[level] = function() {
|
$delegate[level] = function() {
|
||||||
var args = [].slice.call(arguments);
|
var args = [].slice.call(arguments);
|
||||||
args = args.map(function(v) {
|
args = args.map(function(v) {
|
||||||
|
try {
|
||||||
if (typeof v == 'undefined') v = 'undefined';
|
if (typeof v == 'undefined') v = 'undefined';
|
||||||
if (typeof v == 'object') {
|
if (typeof v == 'object') {
|
||||||
v = JSON.stringify(v);
|
v = JSON.stringify(v);
|
||||||
|
}
|
||||||
|
v = v.toString();
|
||||||
if (v.length > 200)
|
if (v.length > 200)
|
||||||
v = v.substr(0, 197) + '...';
|
v = v.substr(0, 197) + '...';
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error at log decorator:', e);
|
||||||
|
v = 'undefined';
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('fileStorageService', function(lodash, $log) {
|
.factory('fileStorageService', function(lodash, $log) {
|
||||||
var root = {}, fs;
|
var root = {},
|
||||||
|
fs;
|
||||||
|
|
||||||
|
|
||||||
root.init = function(cb) {
|
root.init = function(cb) {
|
||||||
|
@ -27,7 +28,9 @@ angular.module('copayApp.services')
|
||||||
root.get = function(k, cb) {
|
root.get = function(k, cb) {
|
||||||
root.init(function(err, fs) {
|
root.init(function(err, fs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
fs.root.getFile(k, {
|
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
|
||||||
|
$log.debug(".get: Got main dir:", dir.nativeURL);
|
||||||
|
dir.getFile(k, {
|
||||||
create: false,
|
create: false,
|
||||||
}, function(fileEntry) {
|
}, function(fileEntry) {
|
||||||
if (!fileEntry) return cb();
|
if (!fileEntry) return cb();
|
||||||
|
@ -35,7 +38,8 @@ angular.module('copayApp.services')
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
|
|
||||||
reader.onloadend = function(e) {
|
reader.onloadend = function(e) {
|
||||||
console.log("Read: " + this.result);
|
if (this.result)
|
||||||
|
$log.debug("Read: ", this.result);
|
||||||
return cb(null, this.result)
|
return cb(null, this.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +50,16 @@ angular.module('copayApp.services')
|
||||||
if (err.code == 1) return cb();
|
if (err.code == 1) return cb();
|
||||||
else return cb(err);
|
else return cb(err);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
root.set = function(k, v, cb) {
|
root.set = function(k, v, cb) {
|
||||||
root.init(function(err, fs) {
|
root.init(function(err, fs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
fs.root.getFile(k, {
|
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
|
||||||
|
$log.debug(".set: Got main dir:", dir.nativeURL);
|
||||||
|
dir.getFile(k, {
|
||||||
create: true,
|
create: true,
|
||||||
}, function(fileEntry) {
|
}, function(fileEntry) {
|
||||||
// Create a FileWriter object for our FileEntry (log.txt).
|
// Create a FileWriter object for our FileEntry (log.txt).
|
||||||
|
@ -71,22 +78,23 @@ angular.module('copayApp.services')
|
||||||
if (lodash.isObject(v))
|
if (lodash.isObject(v))
|
||||||
v = JSON.stringify(v);
|
v = JSON.stringify(v);
|
||||||
|
|
||||||
|
$log.debug('Writing:', k, v);
|
||||||
var blob = new Blob([v], {
|
var blob = new Blob([v], {
|
||||||
type: "application/json"
|
type: "text/plain"
|
||||||
});
|
});
|
||||||
|
|
||||||
fileWriter.write(blob);
|
fileWriter.write(blob);
|
||||||
|
|
||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.remove = function(k, cb) {
|
root.remove = function(k, cb) {
|
||||||
root.init(function(err, fs) {
|
root.init(function(err, fs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
fs.root.getFile(k, {
|
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
|
||||||
|
dir.getFile(k, {
|
||||||
create: false,
|
create: false,
|
||||||
}, function(fileEntry) {
|
}, function(fileEntry) {
|
||||||
// Create a FileWriter object for our FileEntry (log.txt).
|
// Create a FileWriter object for our FileEntry (log.txt).
|
||||||
|
@ -96,6 +104,7 @@ angular.module('copayApp.services')
|
||||||
}, cb, cb);
|
}, cb, cb);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue