mirror of https://github.com/keeweb/keeweb.git
backup to file
This commit is contained in:
parent
24d18cd296
commit
c12fa8ffdb
|
@ -71,6 +71,23 @@ if (window.process && window.process.versions && window.process.versions.electro
|
|||
statFile: function(path) {
|
||||
return this.req('fs').statSync(path);
|
||||
},
|
||||
mkdir: function(dir) {
|
||||
let fs = this.req('fs');
|
||||
let path = this.req('path');
|
||||
let stack = [];
|
||||
while (true) {
|
||||
if (fs.existsSync(dir)) {
|
||||
break;
|
||||
}
|
||||
stack.unshift(dir);
|
||||
let newDir = path.dirname(dir);
|
||||
if (newDir === dir || !newDir || newDir === '.' || newDir === '/') {
|
||||
break;
|
||||
}
|
||||
dir = newDir;
|
||||
}
|
||||
stack.forEach(dir => fs.mkdirSync(dir));
|
||||
},
|
||||
parsePath: function(fileName) {
|
||||
var path = this.req('path');
|
||||
return { path: fileName, dir: path.dirname(fileName), file: path.basename(fileName) };
|
||||
|
|
|
@ -10,6 +10,7 @@ var StorageDropbox = StorageBase.extend({
|
|||
icon: 'dropbox',
|
||||
enabled: true,
|
||||
uipos: 20,
|
||||
backup: true,
|
||||
|
||||
_convertError: function(err) {
|
||||
if (!err) {
|
||||
|
|
|
@ -10,6 +10,7 @@ var StorageFile = StorageBase.extend({
|
|||
icon: 'hdd-o',
|
||||
enabled: !!Launcher,
|
||||
system: true,
|
||||
backup: true,
|
||||
|
||||
load: function(path, opts, callback) {
|
||||
this.logger.debug('Load', path);
|
||||
|
@ -68,6 +69,19 @@ var StorageFile = StorageBase.extend({
|
|||
}
|
||||
},
|
||||
|
||||
mkdir: function(path, callback) {
|
||||
this.logger.debug('Make dir', path);
|
||||
var ts = this.logger.ts();
|
||||
try {
|
||||
Launcher.mkdir(path);
|
||||
this.logger.debug('Made dir', path, this.logger.ts(ts));
|
||||
if (callback) { callback(); }
|
||||
} catch (e) {
|
||||
this.logger.error('Error making local dir', path, e);
|
||||
if (callback) { callback(e); }
|
||||
}
|
||||
},
|
||||
|
||||
watch: function(path, callback) {
|
||||
var names = Launcher.parsePath(path);
|
||||
if (!fileWatchers[names.dir]) {
|
||||
|
|
|
@ -58,7 +58,9 @@ var SettingsFileView = Backbone.View.extend({
|
|||
Object.keys(Storage).forEach(name => {
|
||||
var prv = Storage[name];
|
||||
if (!prv.system && prv.enabled) {
|
||||
storageProviders.push({ name: prv.name, icon: prv.icon, iconSvg: prv.iconSvg, own: name === fileStorage });
|
||||
storageProviders.push({
|
||||
name: prv.name, icon: prv.icon, iconSvg: prv.iconSvg, own: name === fileStorage, backup: prv.backup
|
||||
});
|
||||
}
|
||||
});
|
||||
storageProviders.sort((x, y) => (x.uipos || Infinity) - (y.uipos || Infinity));
|
||||
|
@ -371,28 +373,33 @@ var SettingsFileView = Backbone.View.extend({
|
|||
let backup = this.model.get('backup');
|
||||
if (!backup) {
|
||||
backup = { enabled: enabled, schedule: DefaultBackupSchedule };
|
||||
let defaultPath = DefaultBackupPath.replace('{name}', this.model.get('name'));
|
||||
if (Launcher) {
|
||||
backup.storage = 'file';
|
||||
backup.path = Launcher.getDocumentsPath(DefaultBackupPath);
|
||||
} else if (this.model.get('storage') === 'webdav') {
|
||||
backup.storage = 'webdav';
|
||||
backup.path = this.model.get('path') + '.{date}.bak';
|
||||
} else if (this.model.get('storage')) {
|
||||
backup.storage = this.model.get('storage');
|
||||
backup.path = DefaultBackupPath.replace('{name}', this.model.get('name'));
|
||||
backup.path = Launcher.getDocumentsPath(defaultPath);
|
||||
} else {
|
||||
Object.keys(Storage).forEach(name => {
|
||||
var prv = Storage[name];
|
||||
if (!backup.storage && !prv.system && prv.enabled) {
|
||||
backup.storage = name;
|
||||
}
|
||||
});
|
||||
if (!backup.storage) {
|
||||
e.target.checked = false;
|
||||
return;
|
||||
}
|
||||
backup.path = DefaultBackupPath.replace('{name}', this.model.get('name'));
|
||||
backup.storage = 'dropbox';
|
||||
backup.path = defaultPath;
|
||||
}
|
||||
// } else if (this.model.get('storage') === 'webdav') {
|
||||
// backup.storage = 'webdav';
|
||||
// backup.path = this.model.get('path') + '.{date}.bak';
|
||||
// } else if (this.model.get('storage')) {
|
||||
// backup.storage = this.model.get('storage');
|
||||
// backup.path = DefaultBackupPath.replace('{name}', this.model.get('name'));
|
||||
// } else {
|
||||
// Object.keys(Storage).forEach(name => {
|
||||
// var prv = Storage[name];
|
||||
// if (!backup.storage && !prv.system && prv.enabled) {
|
||||
// backup.storage = name;
|
||||
// }
|
||||
// });
|
||||
// if (!backup.storage) {
|
||||
// e.target.checked = false;
|
||||
// return;
|
||||
// }
|
||||
// backup.path = DefaultBackupPath.replace('{name}', this.model.get('name'));
|
||||
// }
|
||||
this.$el.find('#settings__file-backup-storage').val(backup.storage);
|
||||
this.$el.find('#settings__file-backup-path').val(backup.path);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@
|
|||
<select class="settings__select input-base" id="settings__file-backup-storage">
|
||||
{{#if supportFiles}}<option value="file" {{#ifeq backupStorage 'file'}}selected{{/ifeq}}>{{Res 'file'}}</option>{{/if}}
|
||||
{{#each storageProviders as |prv|}}
|
||||
{{#if prv.backup}}
|
||||
<option value="{{prv.name}}" {{#ifeq ../backupStorage prv.name}}selected{{/ifeq}}>{{res prv.name}}</option>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</select>
|
||||
<label for="settings__file-backup-path">{{res 'setFileBackupPath'}}:</label>
|
||||
|
|
Loading…
Reference in New Issue