Skip to content

Commit

Permalink
Merge pull request #45095 from nextcloud/feat/upload-folders
Browse files Browse the repository at this point in the history
feat(files): Allow to upload folders
  • Loading branch information
susnux authored Jun 24, 2024
2 parents 879eaa7 + 7590c76 commit 3e64ad7
Show file tree
Hide file tree
Showing 157 changed files with 519 additions and 437 deletions.
8 changes: 8 additions & 0 deletions __mocks__/@nextcloud/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
export default {
interceptors: {
response: {
use: () => {},
},
request: {
use: () => {},
},
},
get: async () => ({ status: 200, data: {} }),
delete: async () => ({ status: 200, data: {} }),
post: async () => ({ status: 200, data: {} }),
Expand Down
45 changes: 34 additions & 11 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -200,9 +205,10 @@ export default defineComponent({
uploaderStore,
userConfigStore,
viewConfigStore,
enableGridView,
// non reactive data
enableGridView,
forbiddenCharacters,
Type,
}
},
Expand All @@ -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
},
Expand Down Expand Up @@ -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
Expand All @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions dist/1521-1521.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand Down
6 changes: 3 additions & 3 deletions dist/1642-1642.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -81,7 +81,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- base64-js
- version: 1.5.1
Expand Down
6 changes: 3 additions & 3 deletions dist/2452-2452.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -68,7 +68,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- base64-js
- version: 1.5.1
Expand Down
8 changes: 4 additions & 4 deletions dist/3920-3920.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/components
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -115,7 +115,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- balanced-match
- version: 1.0.2
Expand Down
4 changes: 2 additions & 2 deletions dist/5390-5390.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand Down
4 changes: 2 additions & 2 deletions dist/5455-5455.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/5455-5455.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ This file is generated from multiple sources. Included packages:
- version: 1.2.0
- license: ISC
- @vueuse/components
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -171,7 +171,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- bail
- version: 2.0.2
Expand Down
2 changes: 1 addition & 1 deletion dist/5455-5455.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/5528-5528.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ This file is generated from multiple sources. Included packages:
- version: 1.2.0
- license: ISC
- @vueuse/components
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -128,7 +128,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- bail
- version: 2.0.2
Expand Down
8 changes: 4 additions & 4 deletions dist/5733-5733.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/components
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -136,7 +136,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- base64-js
- version: 1.5.1
Expand Down
2 changes: 0 additions & 2 deletions dist/6075-6075.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/6075-6075.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/6075-6075.js.map.license

This file was deleted.

2 changes: 2 additions & 0 deletions dist/6778-6778.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions dist/6075-6075.js.license → dist/6778-6778.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SPDX-FileCopyrightText: Varun A P
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <[email protected]>
SPDX-FileCopyrightText: Stefan-Gabriel Muscalu <[email protected]>
SPDX-FileCopyrightText: Sindre Sorhus
SPDX-FileCopyrightText: Roman Shtylman <[email protected]>
SPDX-FileCopyrightText: Raynos <[email protected]>
SPDX-FileCopyrightText: Perry Mitchell <[email protected]>
Expand Down Expand Up @@ -81,23 +82,20 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/router
- version: 3.0.1
- license: GPL-3.0-or-later
- @nextcloud/logger
- version: 2.7.0
- license: GPL-3.0-or-later
- eventemitter3
- version: 5.0.1
- license: MIT
- @nextcloud/upload
- version: 1.1.1
- version: 1.4.1
- license: AGPL-3.0-or-later
- @nextcloud/vue
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -106,7 +104,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- base64-js
- version: 1.5.1
Expand Down Expand Up @@ -198,6 +196,9 @@ This file is generated from multiple sources. Included packages:
- is-nan
- version: 1.3.2
- license: MIT
- is-retry-allowed
- version: 2.2.0
- license: MIT
- is-typed-array
- version: 1.1.13
- license: MIT
Expand Down
1 change: 1 addition & 0 deletions dist/6778-6778.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/6778-6778.js.map.license
8 changes: 4 additions & 4 deletions dist/7462-7462.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ This file is generated from multiple sources. Included packages:
- version: 8.11.2
- license: AGPL-3.0-or-later
- @vueuse/components
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/core
- version: 10.9.0
- version: 10.11.0
- license: MIT
- @vueuse/shared
- version: 10.9.0
- version: 10.11.0
- license: MIT
- assert
- version: 2.1.0
Expand All @@ -115,7 +115,7 @@ This file is generated from multiple sources. Included packages:
- version: 1.0.7
- license: MIT
- axios
- version: 1.6.8
- version: 1.7.2
- license: MIT
- balanced-match
- version: 1.0.2
Expand Down
Loading

0 comments on commit 3e64ad7

Please sign in to comment.