mirror of https://github.com/keeweb/keeweb.git
fix #514: save to WebDAV with PUT
This commit is contained in:
parent
9e16a8dac3
commit
b452c9c837
|
@ -510,6 +510,10 @@
|
||||||
"dropboxLinkFull": "Full Dropbox or any folder",
|
"dropboxLinkFull": "Full Dropbox or any folder",
|
||||||
"dropboxLinkCustom": "Own Dropbox app",
|
"dropboxLinkCustom": "Own Dropbox app",
|
||||||
|
|
||||||
|
"webdavSaveMethod": "Save method",
|
||||||
|
"webdavSaveMove": "Upload temporary file and move",
|
||||||
|
"webdavSavePut": "Overwrite file with PUT",
|
||||||
|
|
||||||
"launcherSave": "Save Passwords Database",
|
"launcherSave": "Save Passwords Database",
|
||||||
"launcherFileFilter": "KeePass files",
|
"launcherFileFilter": "KeePass files",
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,20 @@ const StorageWebDav = StorageBase.extend({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSettingsConfig: function() {
|
||||||
|
return {
|
||||||
|
fields: [
|
||||||
|
{ id: 'webdavSaveMethod', title: 'webdavSaveMethod', type: 'select',
|
||||||
|
value: this.appSettings.get('webdavSaveMethod') || 'default',
|
||||||
|
options: { default: 'webdavSaveMove', put: 'webdavSavePut' } }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
applySetting: function(key, value) {
|
||||||
|
this.appSettings.set(key, value);
|
||||||
|
},
|
||||||
|
|
||||||
load: function(path, opts, callback) {
|
load: function(path, opts, callback) {
|
||||||
this._request({
|
this._request({
|
||||||
op: 'Load',
|
op: 'Load',
|
||||||
|
@ -66,43 +80,57 @@ const StorageWebDav = StorageBase.extend({
|
||||||
that.logger.debug('Save error', path, 'rev conflict', stat.rev, rev);
|
that.logger.debug('Save error', path, 'rev conflict', stat.rev, rev);
|
||||||
return cb({ revConflict: true }, xhr, stat);
|
return cb({ revConflict: true }, xhr, stat);
|
||||||
}
|
}
|
||||||
that._request(_.defaults({
|
const useTmpPath = this.appSettings.get('webdavSaveMethod') !== 'put';
|
||||||
op: 'Save:put', method: 'PUT', path: tmpPath, data: data, nostat: true
|
if (useTmpPath) {
|
||||||
}, saveOpts), (err) => {
|
|
||||||
if (err) { return cb(err); }
|
|
||||||
that._request(_.defaults({
|
that._request(_.defaults({
|
||||||
op: 'Save:stat', method: 'HEAD'
|
op: 'Save:put', method: 'PUT', path: tmpPath, data: data, nostat: true
|
||||||
}, saveOpts), (err, xhr, stat) => {
|
}, saveOpts), (err) => {
|
||||||
if (err) {
|
if (err) { return cb(err); }
|
||||||
that._request(_.defaults({ op: 'Save:delete', method: 'DELETE', path: tmpPath }, saveOpts));
|
|
||||||
return cb(err, xhr, stat);
|
|
||||||
}
|
|
||||||
if (stat.rev !== rev) {
|
|
||||||
that.logger.debug('Save error', path, 'rev conflict', stat.rev, rev);
|
|
||||||
that._request(_.defaults({ op: 'Save:delete', method: 'DELETE', path: tmpPath }, saveOpts));
|
|
||||||
return cb({ revConflict: true }, xhr, stat);
|
|
||||||
}
|
|
||||||
let movePath = path;
|
|
||||||
if (movePath.indexOf('://') < 0) {
|
|
||||||
if (movePath.indexOf('/') === 0) {
|
|
||||||
movePath = location.protocol + '//' + location.host + movePath;
|
|
||||||
} else {
|
|
||||||
movePath = location.href.replace(/\?(.*)/, '').replace(/[^/]*$/, movePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
that._request(_.defaults({
|
that._request(_.defaults({
|
||||||
op: 'Save:move', method: 'MOVE', path: tmpPath, nostat: true,
|
op: 'Save:stat', method: 'HEAD'
|
||||||
headers: { Destination: movePath, 'Overwrite': 'T' }
|
}, saveOpts), (err, xhr, stat) => {
|
||||||
}, saveOpts), (err) => {
|
if (err) {
|
||||||
if (err) { return cb(err); }
|
that._request(_.defaults({op: 'Save:delete', method: 'DELETE', path: tmpPath}, saveOpts));
|
||||||
|
return cb(err, xhr, stat);
|
||||||
|
}
|
||||||
|
if (stat.rev !== rev) {
|
||||||
|
that.logger.debug('Save error', path, 'rev conflict', stat.rev, rev);
|
||||||
|
that._request(_.defaults({op: 'Save:delete', method: 'DELETE', path: tmpPath}, saveOpts));
|
||||||
|
return cb({revConflict: true}, xhr, stat);
|
||||||
|
}
|
||||||
|
let movePath = path;
|
||||||
|
if (movePath.indexOf('://') < 0) {
|
||||||
|
if (movePath.indexOf('/') === 0) {
|
||||||
|
movePath = location.protocol + '//' + location.host + movePath;
|
||||||
|
} else {
|
||||||
|
movePath = location.href.replace(/\?(.*)/, '').replace(/[^/]*$/, movePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
that._request(_.defaults({
|
that._request(_.defaults({
|
||||||
op: 'Save:stat', method: 'HEAD'
|
op: 'Save:move', method: 'MOVE', path: tmpPath, nostat: true,
|
||||||
}, saveOpts), (err, xhr, stat) => {
|
headers: {Destination: movePath, 'Overwrite': 'T'}
|
||||||
cb(err, xhr, stat);
|
}, saveOpts), (err) => {
|
||||||
|
if (err) { return cb(err); }
|
||||||
|
that._request(_.defaults({
|
||||||
|
op: 'Save:stat', method: 'HEAD'
|
||||||
|
}, saveOpts), (err, xhr, stat) => {
|
||||||
|
cb(err, xhr, stat);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
that._request(_.defaults({
|
||||||
|
op: 'Save:put', method: 'PUT', data: data, nostat: true
|
||||||
|
}, saveOpts), (err) => {
|
||||||
|
if (err) { return cb(err); }
|
||||||
|
that._request(_.defaults({
|
||||||
|
op: 'Save:stat', method: 'HEAD'
|
||||||
|
}, saveOpts), (err, xhr, stat) => {
|
||||||
|
cb(err, xhr, stat);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ Release notes
|
||||||
`+` cacheConfigSettings config option
|
`+` cacheConfigSettings config option
|
||||||
`+` keyboard-accessible autocomplete
|
`+` keyboard-accessible autocomplete
|
||||||
`+` entry auto-type context menu
|
`+` entry auto-type context menu
|
||||||
`+` `kw.require` now provides access to modules
|
`+` save to WebDAV with PUT
|
||||||
`+` showOnlyFilesFromConfig config option
|
`+` showOnlyFilesFromConfig config option
|
||||||
`+` mac os window style options
|
`+` mac os window style options
|
||||||
`+` lock on hide mac os hide
|
`+` lock on hide mac os hide
|
||||||
|
|
Loading…
Reference in New Issue