fix(files): ensure creating folders in public shares work

The root of the webdav client needs to be the public share root,
as accessing the `/files` folder is not possible for public shares.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-12-15 16:21:29 +01:00 committed by nextcloud-command
parent a887e0f639
commit 6008694b93
2 changed files with 23 additions and 19 deletions

View file

@ -3,19 +3,18 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Folder, IFolder, INode } from '@nextcloud/files'
import type { Folder, IFolder, INode, Node } from '@nextcloud/files'
import type { Upload } from '@nextcloud/upload'
import type { RootDirectory } from './DropServiceUtils.ts'
import { createDirectoryIfNotExists, Directory, resolveConflict, traverseTree } from './DropServiceUtils.ts'
import { showError, showInfo, showSuccess, showWarning } from '@nextcloud/dialogs'
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 { Directory, traverseTree, resolveConflict, createDirectoryIfNotExists } from './DropServiceUtils'
import { MoveCopyAction } from '../actions/moveOrCopyActionUtils'
import logger from '../logger.ts'
import { defaultRootPath } from '@nextcloud/files/dav'
import { handleCopyMoveNodesTo, HintException } from '../actions/moveOrCopyAction.ts'
/**
* This function converts a list of DataTransferItems to a file tree.
@ -123,14 +122,13 @@ 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 = join(defaultRootPath, destination.path, relativePath)
try {
console.debug('Processing directory', { relativePath })
await createDirectoryIfNotExists(absolutePath)
logger.debug('Processing directory', { relativePath })
await createDirectoryIfNotExists(relativePath)
await uploadDirectoryContents(file, relativePath)
} catch (error) {
showError(t('files', 'Unable to create the directory {directory}', { directory: file.name }))
logger.error('', { error, absolutePath, directory: file })
logger.error('Unable to create the directory', { error, relativePath, directory: file })
}
continue
}

View file

@ -2,14 +2,16 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Folder, Node } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import { showWarning, showInfo } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { Folder, Node, davGetClient, davGetDefaultPropfind, davResultToNode } from '@nextcloud/files'
import { defaultRemoteURL, defaultRootPath, getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
import { t } from '@nextcloud/l10n'
import { join } from '@nextcloud/paths'
import { openConflictPicker } from '@nextcloud/upload'
import { translate as t } from '@nextcloud/l10n'
import logger from '../logger.ts'
/**
@ -129,14 +131,18 @@ const readDirectory = (directory: FileSystemDirectoryEntry): Promise<FileSystemE
})
}
export const createDirectoryIfNotExists = async (absolutePath: string) => {
const davClient = davGetClient()
const dirExists = await davClient.exists(absolutePath)
/**
* @param path - The path relative to the dav root
*/
export async function createDirectoryIfNotExists(path: string) {
const davUrl = join(defaultRemoteURL, defaultRootPath)
const davClient = getClient(davUrl)
const dirExists = await davClient.exists(path)
if (!dirExists) {
logger.debug('Directory does not exist, creating it', { absolutePath })
await davClient.createDirectory(absolutePath, { recursive: true })
const stat = await davClient.stat(absolutePath, { details: true, data: davGetDefaultPropfind() }) as ResponseDataDetailed<FileStat>
emit('files:node:created', davResultToNode(stat.data))
logger.debug('Directory does not exist, creating it', { path })
await davClient.createDirectory(path, { recursive: true })
const stat = await davClient.stat(path, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
emit('files:node:created', resultToNode(stat.data, defaultRootPath, davUrl))
}
}