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
405 changes: 192 additions & 213 deletions apps/files/src/actions/moveOrCopyAction.ts

Large diffs are not rendered by default.

68 changes: 33 additions & 35 deletions apps/files/src/services/DropService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Folder, IFolder, INode } from '@nextcloud/files'
import type { Upload } from '@nextcloud/upload'
import type { RootDirectory } from './DropServiceUtils'
import type { RootDirectory } from './DropServiceUtils.ts'

import { Folder, Node, NodeStatus, davRootPath } from '@nextcloud/files'
import { getUploader, hasConflict } from '@nextcloud/upload'
import { join } from 'path'
import { joinPaths } from '@nextcloud/paths'
import { createDirectoryIfNotExists, Directory, resolveConflict, traverseTree } from './DropServiceUtils.ts'
import { showError, showInfo, showSuccess, showWarning } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import Vue from 'vue'

import { Directory, traverseTree, resolveConflict, createDirectoryIfNotExists } from './DropServiceUtils'
import { handleCopyMoveNodeTo } from '../actions/moveOrCopyAction'
import { MoveCopyAction } from '../actions/moveOrCopyActionUtils'
import { t } from '@nextcloud/l10n'
import { join } from '@nextcloud/paths'
import { getUploader, hasConflict } from '@nextcloud/upload'
import { handleCopyMoveNodesTo, HintException } from '../actions/moveOrCopyAction.ts'
import { MoveCopyAction } from '../actions/moveOrCopyActionUtils.ts'
import logger from '../logger.ts'
import { defaultRootPath } from '@nextcloud/files/dav'

/**
* This function converts a list of DataTransferItems to a file tree.
Expand Down Expand Up @@ -100,7 +98,7 @@ export async function onDropExternalFiles(root: RootDirectory, destination: Fold
const uploader = getUploader()

// Check for conflicts on root elements
if (await hasConflict(root.contents, contents)) {
if (hasConflict(root.contents, contents)) {
root.contents = await resolveConflict(root.contents, destination, contents)
if (root.contents.length === 0) {
// user cancelled the upload
Expand All @@ -125,7 +123,7 @@ export async function onDropExternalFiles(root: RootDirectory, destination: Fold
// If the file is a directory, we need to create it first
// then browse its tree and upload its contents.
if (file instanceof Directory) {
const absolutePath = joinPaths(davRootPath, destination.path, relativePath)
const absolutePath = join(defaultRootPath, destination.path, relativePath)
try {
console.debug('Processing directory', { relativePath })
await createDirectoryIfNotExists(absolutePath)
Expand Down Expand Up @@ -171,11 +169,17 @@ export async function onDropExternalFiles(root: RootDirectory, destination: Fold
return Promise.all(queue)
}

export const onDropInternalFiles = async (nodes: Node[], destination: Folder, contents: Node[], isCopy = false) => {
const queue = [] as Promise<void>[]

/**
* Handle dropping internal files
*
* @param nodes - The nodes being dropped
* @param destination - The destination folder
* @param contents - The contents of the destination folder
* @param isCopy - Whether the operation is a copy
*/
export async function onDropInternalFiles(nodes: INode[], destination: IFolder, contents: INode[], isCopy = false) {
// Check for conflicts on root elements
if (await hasConflict(nodes, contents)) {
if (hasConflict(nodes, contents)) {
nodes = await resolveConflict(nodes, destination, contents)
}

Expand All @@ -185,23 +189,17 @@ export const onDropInternalFiles = async (nodes: Node[], destination: Folder, co
return
}

for (const node of nodes) {
Vue.set(node, 'status', NodeStatus.LOADING)
queue.push(handleCopyMoveNodeTo(node, destination, isCopy ? MoveCopyAction.COPY : MoveCopyAction.MOVE, true))
}

// Wait for all promises to settle
const results = await Promise.allSettled(queue)
nodes.forEach(node => Vue.set(node, 'status', undefined))

// Check for errors
const errors = results.filter(result => result.status === 'rejected')
if (errors.length > 0) {
logger.error('Error while copying or moving files', { errors })
showError(isCopy ? t('files', 'Some files could not be copied') : t('files', 'Some files could not be moved'))
return
try {
const promises = Array.fromAsync(handleCopyMoveNodesTo(nodes, destination, isCopy ? MoveCopyAction.COPY : MoveCopyAction.MOVE))
await promises
logger.debug('Files copy/move successful')
showSuccess(isCopy ? t('files', 'Files copied successfully') : t('files', 'Files moved successfully'))
} catch (error) {
logger.error('Error while processing dropped files', { error })
if (error instanceof HintException) {
showError(error.message)
} else {
showError(isCopy ? t('files', 'Some files could not be copied') : t('files', 'Some files could not be moved'))
}
}

logger.debug('Files copy/move successful')
showSuccess(isCopy ? t('files', 'Files copied successfully') : t('files', 'Files moved successfully'))
}
10 changes: 5 additions & 5 deletions cypress/e2e/files/files-copy-move.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
copyFile('original.txt', '.')

getRowForFile('original.txt').should('be.visible')
getRowForFile('original (copy).txt').should('be.visible')
getRowForFile('original (1).txt').should('be.visible')
})

it('Can copy a file multiple times to same folder', () => {
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (1).txt')
cy.login(currentUser)
cy.visit('/apps/files')

copyFile('original.txt', '.')

getRowForFile('original.txt').should('be.visible')
getRowForFile('original (copy 2).txt').should('be.visible')
getRowForFile('original (2).txt').should('be.visible')
})

/**
* Test that a copied folder with a dot will be renamed correctly ('foo.bar' -> 'foo.bar (copy)')
* Test that a copied folder with a dot will be renamed correctly ('foo.bar' -> 'foo.bar (1)')
* Test for: https://github.com/nextcloud/server/issues/43843
*/
it('Can copy a folder to same folder', () => {
Expand All @@ -135,7 +135,7 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
copyFile('foo.bar', '.')

getRowForFile('foo.bar').should('be.visible')
getRowForFile('foo.bar (copy)').should('be.visible')
getRowForFile('foo.bar (1)').should('be.visible')
})

/** Test for https://github.com/nextcloud/server/issues/43329 */
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/files/live_photos.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ describe('Files: Live photos', { testIsolation: true }, () => {

getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
getRowForFile(`${randomFileName} (1).jpg`).should('have.length', 1)
getRowForFile(`${randomFileName} (1).mov`).should('have.length', 1)
})

it('Copies both files when copying the .mov', () => {
copyFile(`${randomFileName}.mov`, '.')
clickOnBreadcrumbs('All files')

getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
getRowForFile(`${randomFileName} (1).jpg`).should('have.length', 1)
getRowForFile(`${randomFileName} (1).mov`).should('have.length', 1)
})

it('Keeps live photo link when copying folder', () => {
createFolder('folder')
moveFile(`${randomFileName}.jpg`, 'folder')
copyFile('folder', '.')
navigateToFolder('folder (copy)')
navigateToFolder('folder (1)')

getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
Expand All @@ -94,7 +94,7 @@ describe('Files: Live photos', { testIsolation: true }, () => {
cy.get('[data-cy-files-list-row-fileid]').should('have.length', 1)
getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 0)
getRowForFile(`${randomFileName} (1).jpg`).should('have.length', 0)
})

it('Moves files when moving the .jpg', () => {
Expand Down
4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/dav-settings-personal-availability.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dav-settings-personal-availability.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/profile-main.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-vue-settings-personal-password.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-personal-password.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/sharebymail-vue-settings-admin-sharebymail.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sharebymail-vue-settings-admin-sharebymail.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/weather_status-weather-status.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/weather_status-weather-status.js.map

Large diffs are not rendered by default.

Loading