diff --git a/packages/file-handling/package.json b/packages/file-handling/package.json index 4b8374b2a2cd88e71f6361c91c9e0a6cd9824a7e..28593978fd32ec67722182e893587c3153fa2d5e 100644 --- a/packages/file-handling/package.json +++ b/packages/file-handling/package.json @@ -43,7 +43,7 @@ "lit": "^2.0.0", "material-design-icons-svg": "^3.0.0", "tabulator-tables": "^4.8.4", - "webdav": "4.8.0" + "webdav": "^4.8.0" }, "scripts": { "clean": "rm dist/*", diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js index d9414d43c4579b8283e8f907a50f5d4a73954119..888835404541acd531cade39acfaa83ff0c17fda 100644 --- a/packages/file-handling/src/file-sink.js +++ b/packages/file-handling/src/file-sink.js @@ -174,7 +174,8 @@ export class FileSink extends ScopedElementsMixin(DbpFileHandlingLitElement) { async uploadToNextcloud(directory) { let that = this; const element = that._('#nextcloud-file-picker'); - await element.uploadFiles(that.files, directory); + const files = [...this.files]; + await element.uploadFiles(files, directory); } finishedFileUpload(event) { @@ -214,10 +215,12 @@ export class FileSink extends ScopedElementsMixin(DbpFileHandlingLitElement) { loadWebdavDirectory() { const filePicker = this._('#nextcloud-file-picker'); - if (filePicker) { + filePicker.checkLocalStorage().then((contents) => { + if (filePicker.webDavClient !== null) { + filePicker.loadDirectory(filePicker.directoryPath); } }); diff --git a/packages/file-handling/src/nextcloud-file-picker.js b/packages/file-handling/src/nextcloud-file-picker.js index ada5b27dc98ba5e1babec131cf09e84ac19b3228..d4e42f2435e697f51848adcca8809a2cc2178fb1 100644 --- a/packages/file-handling/src/nextcloud-file-picker.js +++ b/packages/file-handling/src/nextcloud-file-picker.js @@ -1480,18 +1480,17 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { const i18n = this._i18n; this.loading = true; this.statusText = i18n.t('nextcloud-file-picker.upload-to', {path: directory}); - this.fileList = files; - this.forAll = false; - this.setRepeatForAllConflicts(); - this.uploadFile(directory); - - if (files.length > 0) { + this.fileList = [...files]; + if (typeof this.fileList !== undefined && this.fileList.length > 0) { this.sendSetPropertyEvent('analytics-event', { category: 'FileHandlingNextcloud', action: 'UploadFiles', name: files.length, }); } + this.forAll = false; + this.setRepeatForAllConflicts(); + this.uploadFile(directory); } /** @@ -1522,31 +1521,28 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { await this.webDavClient .putFileContents(path, file, { contentLength: file.size, - overwrite: false, - onUploadProgress: (progress) => { - /* console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`);*/ - }, + overwrite: false }) - .then(function () { - that.uploadCount += 1; - that.fileList.shift(); - that.uploadFile(directory); - }) - .catch((error) => { - if (error.message.search('412') !== -1 || error.message.search('403') !== -1) { - this.generatedFilename = this.getNextFilename(); - this._('#replace-filename').value = this.generatedFilename; - if (this.forAll) { - this.uploadFileObject = file; - this.uploadFileDirectory = directory; - this.abortUploadButton = true; - this.uploadFileAfterConflict(); + .then(function (success) { + if (!success) { + that.generatedFilename = that.getNextFilename(); + that._('#replace-filename').value = that.generatedFilename; + if (that.forAll) { + that.uploadFileObject = file; + that.uploadFileDirectory = directory; + that.abortUploadButton = true; + that.uploadFileAfterConflict(); } else { - this.replaceModalDialog(file, directory); + that.replaceModalDialog(file, directory); } } else { - throw error; + that.uploadCount += 1; + that.fileList.shift(); + that.uploadFile(directory); } + }) + .catch((error) => { + throw error; }); } else { this.loadDirectory(this.directoryPath);