diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-06-24 21:53:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 21:53:01 +0200 |
commit | 3e64ad7ee760d22bc8fb332f5e3e9bebcffde970 (patch) | |
tree | 7cf239281b1f7b283a04d05223efe976bcf09a43 /apps/files/src | |
parent | 879eaa7681b83efb1ed7de2ec8abb6ac3c62ccdd (diff) | |
parent | 7590c767a7811a2c2ded897fc1bfa3db507a5a2b (diff) | |
download | nextcloud-server-3e64ad7ee760d22bc8fb332f5e3e9bebcffde970.tar.gz nextcloud-server-3e64ad7ee760d22bc8fb332f5e3e9bebcffde970.zip |
Merge pull request #45095 from nextcloud/feat/upload-folders
feat(files): Allow to upload folders
Diffstat (limited to 'apps/files/src')
-rw-r--r-- | apps/files/src/views/FilesList.vue | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index fabf1cae6b9..8ba5a85ddac 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -37,10 +37,12 @@ <!-- Uploader --> <UploadPicker v-else-if="currentFolder" - :content="dirContents" - :destination="currentFolder" - :multiple="true" + allow-folders class="files-list__header-upload-button" + :content="getContent" + :destination="currentFolder" + :forbidden-characters="forbiddenCharacters" + multiple @failed="onUploadFail" @uploaded="onUpload" /> </template> @@ -79,9 +81,11 @@ <template v-if="dir !== '/'" #action> <!-- Uploader --> <UploadPicker v-if="currentFolder && canUpload && !isQuotaExceeded" - :content="dirContents" - :destination="currentFolder" + allow-folders class="files-list__header-upload-button" + :content="getContent" + :destination="currentFolder" + :forbidden-characters="forbiddenCharacters" multiple @failed="onUploadFail" @uploaded="onUpload" /> @@ -118,10 +122,10 @@ import { getCapabilities } from '@nextcloud/capabilities' import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' import { Folder, Node, Permission } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' -import { join, dirname } from 'path' -import { showError } from '@nextcloud/dialogs' +import { join, dirname, normalize } from 'path' +import { showError, showWarning } from '@nextcloud/dialogs' import { Type } from '@nextcloud/sharing' -import { UploadPicker } from '@nextcloud/upload' +import { UploadPicker, UploadStatus } from '@nextcloud/upload' import { loadState } from '@nextcloud/initial-state' import { defineComponent } from 'vue' @@ -190,6 +194,7 @@ export default defineComponent({ const { currentView } = useNavigation() const enableGridView = (loadState('core', 'config', [])['enable_non-accessible_features'] ?? true) + const forbiddenCharacters = loadState<string[]>('files', 'forbiddenCharacters', []) return { currentView, @@ -200,9 +205,10 @@ export default defineComponent({ uploaderStore, userConfigStore, viewConfigStore, - enableGridView, // non reactive data + enableGridView, + forbiddenCharacters, Type, } }, @@ -228,6 +234,19 @@ export default defineComponent({ }, 500) }, + /** + * Get a callback function for the uploader to fetch directory contents for conflict resolution + */ + getContent() { + const view = this.currentView + return async (path?: string) => { + // as the path is allowed to be undefined we need to normalize the path ('//' to '/') + const normalizedPath = normalize(`${this.currentFolder?.path ?? ''}/${path ?? ''}`) + // use the current view to fetch the content for the requested path + return (await view.getContents(normalizedPath)).contents + } + }, + userConfig(): UserConfig { return this.userConfigStore.userConfig }, @@ -590,8 +609,7 @@ export default defineComponent({ onUpload(upload: Upload) { // Let's only refresh the current Folder // Navigating to a different folder will refresh it anyway - const destinationSource = dirname(upload.source) - const needsRefresh = destinationSource === this.currentFolder?.source + const needsRefresh = dirname(upload.source) === this.currentFolder!.source // TODO: fetch uploaded files data only // Use parseInt(upload.response?.headers?.['oc-fileid']) to get the fileid @@ -604,6 +622,11 @@ export default defineComponent({ async onUploadFail(upload: Upload) { const status = upload.response?.status || 0 + if (upload.status === UploadStatus.CANCELLED) { + showWarning(t('files', 'Upload was cancelled by user')) + return + } + // Check known status codes if (status === 507) { showError(t('files', 'Not enough free space')) |