diff --git a/app/scripts/locales/base.json b/app/scripts/locales/base.json index 37324f79..cbec5309 100644 --- a/app/scripts/locales/base.json +++ b/app/scripts/locales/base.json @@ -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", diff --git a/app/scripts/storage/storage-webdav.js b/app/scripts/storage/storage-webdav.js index 0dce8764..9bdf352d 100644 --- a/app/scripts/storage/storage-webdav.js +++ b/app/scripts/storage/storage-webdav.js @@ -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); + }); + }); + } }); }, diff --git a/release-notes.md b/release-notes.md index 8173ce5a..96a25166 100644 --- a/release-notes.md +++ b/release-notes.md @@ -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