Skip to content
Open
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
29 changes: 26 additions & 3 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
multiple
variant="primary"
data-cy-upload-picker
@finished="fetchContent"
@upload:finished="onUploadFinished" />
</Teleport>

Expand Down Expand Up @@ -140,6 +141,7 @@
:destination="currentFolder"
multiple
data-cy-upload-picker
@finished="fetchContent"
@upload:finished="onUploadFinished" />
<NcButton v-else :to="toPreviousDir" variant="primary">
{{ t('files', 'Go back') }}
Expand Down Expand Up @@ -193,6 +195,7 @@ import { useEnabledFileListActions } from '../composables/useFileListActions.ts'
import { useFileListWidth } from '../composables/useFileListWidth.ts'
import { useNewFileMenuActions } from '../composables/useNewFileMenuActions.ts'
import { useRouteParameters } from '../composables/useRouteParameters.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 @@ -633,10 +636,30 @@ export default defineComponent({

// Let's only refresh the current Folder
// Navigating to a different folder will refresh it anyway
// TODO: fetch uploaded files data only
if (dirname(upload.source) === this.currentFolder!.source) {
// fetchContent will cancel the previous ongoing promise
this.fetchContent()
this.fetchUploadedNode(upload)
}
},

/**
* Fetch the uploaded node and add it to the current folder
*
* @param upload - The finished upload
*/
async fetchUploadedNode(upload: IUpload) {
if (upload.source.endsWith('/')) {
return
}

if ((this.currentFolder!.permissions & Permission.READ) === 0) {
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
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 type { Request } from '@playwright/test'

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

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

test.describe('files: Upload', () => {
test.beforeEach(async ({ filesListPage }) => {
await filesListPage.open()
})

test('fetches only the uploaded files and reloads the folder once', async ({ page, user, filesListPage }) => {
const folderUrl = `/remote.php/dav/files/${user.userId}/`
const isFolderListing = (request: Request) => request.method() === 'PROPFIND'
&& request.headers().depth === '1'
&& new URL(request.url()).pathname.endsWith(folderUrl)

const folderListings: Request[] = []
page.on('request', (request) => {
if (isFolderListing(request)) {
folderListings.push(request)
}
})
const finalListing = page.waitForResponse((response) => isFolderListing(response.request()))

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()
}
await finalListing

expect(folderListings).toHaveLength(1)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,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