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",
|
||||
"dropboxLinkCustom": "Own Dropbox app",
|
||||
|
||||
"webdavSaveMethod": "Save method",
|
||||
"webdavSaveMove": "Upload temporary file and move",
|
||||
"webdavSavePut": "Overwrite file with PUT",
|
||||
|
||||
"launcherSave": "Save Passwords Database",
|
||||
"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) {
|
||||
this._request({
|
||||
op: 'Load',
|
||||
|
@ -66,43 +80,57 @@ const StorageWebDav = StorageBase.extend({
|
|||
that.logger.debug('Save error', path, 'rev conflict', stat.rev, rev);
|
||||
return cb({ revConflict: true }, xhr, stat);
|
||||
}
|
||||
that._request(_.defaults({
|
||||
op: 'Save:put', method: 'PUT', path: tmpPath, data: data, nostat: true
|
||||
}, saveOpts), (err) => {
|
||||
if (err) { return cb(err); }
|
||||
const useTmpPath = this.appSettings.get('webdavSaveMethod') !== 'put';
|
||||
if (useTmpPath) {
|
||||
that._request(_.defaults({
|
||||
op: 'Save:stat', method: 'HEAD'
|
||||
}, saveOpts), (err, xhr, stat) => {
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
op: 'Save:put', method: 'PUT', path: tmpPath, data: data, nostat: true
|
||||
}, saveOpts), (err) => {
|
||||
if (err) { return cb(err); }
|
||||
that._request(_.defaults({
|
||||
op: 'Save:move', method: 'MOVE', path: tmpPath, nostat: true,
|
||||
headers: { Destination: movePath, 'Overwrite': 'T' }
|
||||
}, saveOpts), (err) => {
|
||||
if (err) { return cb(err); }
|
||||
op: 'Save:stat', method: 'HEAD'
|
||||
}, saveOpts), (err, xhr, stat) => {
|
||||
if (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({
|
||||
op: 'Save:stat', method: 'HEAD'
|
||||
}, saveOpts), (err, xhr, stat) => {
|
||||
cb(err, xhr, stat);
|
||||
op: 'Save:move', method: 'MOVE', path: tmpPath, nostat: true,
|
||||
headers: {Destination: movePath, 'Overwrite': 'T'}
|
||||
}, 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
|
||||
`+` keyboard-accessible autocomplete
|
||||
`+` entry auto-type context menu
|
||||
`+` `kw.require` now provides access to modules
|
||||
`+` save to WebDAV with PUT
|
||||
`+` showOnlyFilesFromConfig config option
|
||||
`+` mac os window style options
|
||||
`+` lock on hide mac os hide
|
||||
|
|
Loading…
Reference in New Issue