Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@
:destination="currentFolder"
:forbidden-characters="forbiddenCharacters"
multiple
@failed="onUploadFail"
@uploaded="onUpload" />
@failed="onUploadFail" />
<NcButton v-else :to="toPreviousDir" variant="primary">
{{ t('files', 'Go back') }}
</NcButton>
Expand All @@ -166,7 +165,7 @@ import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Permission, sortNodes } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { translate as t } from '@nextcloud/l10n'
import { dirname, join } from '@nextcloud/paths'
import { basename, dirname, join } from '@nextcloud/paths'
import { ShareType } from '@nextcloud/sharing'
import { UploadPicker, UploadStatus } from '@nextcloud/upload'
import { useThrottleFn } from '@vueuse/core'
Expand All @@ -192,6 +191,7 @@ import { useEnabledFileListActions } from '../composables/useFileListActions.ts'
import { useFileListWidth } from '../composables/useFileListWidth.ts'
import { useRouteParameters } from '../composables/useRouteParameters.ts'
import filesSortingMixin from '../mixins/filesSorting.ts'
import { fetchNode } from '../services/WebdavClient.ts'
import { useActiveStore } from '../store/active.ts'
import { useFilesStore } from '../store/files.ts'
import { useFiltersStore } from '../store/filters.ts'
Expand Down Expand Up @@ -625,11 +625,27 @@ export default defineComponent({
// Navigating to a different folder will refresh it anyway
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
if (needsRefresh) {
// fetchContent will cancel the previous ongoing promise
this.fetchUploadedNode(upload)
}
},

/**
* Fetch the uploaded node and add it to the current folder
*
* @param upload - The finished upload
*/
async fetchUploadedNode(upload: Upload) {
if (upload.source.endsWith('/') || (this.currentFolder!.permissions & Permission.READ) === 0) {
this.fetchContent()
return
}

try {
const node = await fetchNode(join(this.currentFolder!.path, basename(upload.source)))
emit('files:node:created', node)
} catch (error) {
logger.error('Could not fetch uploaded node', { error, upload })
}
},

Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions tests/playwright/e2e/files/files-upload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { expect, test } from '../../support/fixtures/files-page.ts'
import { mkdir } from '../../support/utils/dav.ts'

const FILES = [
'one.txt',
'two.txt',
'three.txt',
'four.txt',
'five.txt',
]

test.describe('files: Upload', () => {
test.beforeEach(async ({ page, user, filesListPage }) => {
await mkdir(page.request, user, '/empty')
await filesListPage.open()
await filesListPage.navigateToFolder('empty')
})

test('fetches each uploaded file once and reloads the folder once', async ({ page, user, filesListPage }) => {
const folderPath = `/remote.php/dav/files/${user.userId}/empty/`

let uploading = false
const propfinds: string[] = []
page.on('request', (request) => {
if (request.method() === 'PUT') {
uploading = true
} else if (uploading && request.method() === 'PROPFIND') {
propfinds.push(`${request.headers().depth} ${decodeURIComponent(new URL(request.url()).pathname)}`)
}
})

const chooser = page.waitForEvent('filechooser')
await page.locator('[data-cy-upload-picker]').first().getByRole('button', { name: 'New' }).click()
await page.getByRole('menuitem', { name: 'Upload files' }).click()
await (await chooser).setFiles(FILES.map((name) => ({ name, mimeType: 'text/plain', buffer: Buffer.from(name) })))

for (const name of FILES) {
await expect(filesListPage.getRowForFile(name)).toBeVisible()
}

const expected = [`1 ${folderPath}`, ...FILES.map((name) => `0 ${folderPath}${name}`)]
await expect.poll(() => [...propfinds].sort()).toEqual(expected.sort())
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ test.describe('files_sharing: Public share - file drop', () => {
await expect.poll(() => getFileContent(ownerRequest, user, `/${SHARE_NAME}/second.md`).catch(() => ''))
.toBe('x'.repeat(128))
})

test('lists the uploaded files without fetching them', async ({ page, publicShare }) => {
await expect(publicShare.fileDropDescription(SHARE_NAME)).toBeVisible()

const fileRequests: string[] = []
page.on('request', (request) => {
if (request.method() === 'PROPFIND' && /\/(first\.txt|second\.md)$/.test(request.url())) {
fileRequests.push(request.url())
}
})

await page.getByRole('button', { name: 'Upload', exact: true }).click()
await publicShare.uploadFiles('Upload files', [
{ name: 'first.txt', mimeType: 'text/plain', buffer: Buffer.from('first') },
{ name: 'second.md', mimeType: 'text/markdown', buffer: Buffer.from('second') },
])

await expect(page.getByText('Successfully uploaded files')).toBeVisible()
await expect(page.getByRole('listitem').filter({ hasText: 'first.txt' })).toBeVisible()
await expect(page.getByRole('listitem').filter({ hasText: 'second.md' })).toBeVisible()
expect(fileRequests).toHaveLength(0)
})
})
Loading