Skip to content

Commit a12a956

Browse files
committed
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 <[email protected]>
1 parent b15e294 commit a12a956

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

apps/files/src/services/DropService.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import type { RootDirectory } from './DropServiceUtils.ts'
99

1010
import { showError, showInfo, showSuccess, showWarning } from '@nextcloud/dialogs'
1111
import { NodeStatus } from '@nextcloud/files'
12-
import { getRootPath } from '@nextcloud/files/dav'
1312
import { translate as t } from '@nextcloud/l10n'
14-
import { joinPaths } from '@nextcloud/paths'
1513
import { getUploader, hasConflict } from '@nextcloud/upload'
1614
import { join } from 'path'
1715
import Vue from 'vue'
@@ -126,14 +124,13 @@ export async function onDropExternalFiles(root: RootDirectory, destination: Fold
126124
// If the file is a directory, we need to create it first
127125
// then browse its tree and upload its contents.
128126
if (file instanceof Directory) {
129-
const absolutePath = joinPaths(getRootPath(), destination.path, relativePath)
130127
try {
131128
logger.debug('Processing directory', { relativePath })
132-
await createDirectoryIfNotExists(absolutePath)
129+
await createDirectoryIfNotExists(relativePath)
133130
await uploadDirectoryContents(file, relativePath)
134131
} catch (error) {
135132
showError(t('files', 'Unable to create the directory {directory}', { directory: file.name }))
136-
logger.error('', { error, absolutePath, directory: file })
133+
logger.error('Unable to create the directory', { error, relativePath, directory: file })
137134
}
138135
continue
139136
}

apps/files/src/services/DropServiceUtils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import type { FileStat, ResponseDataDetailed } from 'webdav'
77

88
import { showInfo, showWarning } from '@nextcloud/dialogs'
99
import { emit } from '@nextcloud/event-bus'
10-
import { getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
10+
import { defaultRemoteURL, defaultRootPath, getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
1111
import { translate as t } from '@nextcloud/l10n'
12+
import { join } from '@nextcloud/paths'
1213
import { openConflictPicker } from '@nextcloud/upload'
1314
import logger from '../logger.ts'
1415

@@ -131,17 +132,17 @@ function readDirectory(directory: FileSystemDirectoryEntry): Promise<FileSystemE
131132
}
132133

133134
/**
134-
*
135-
* @param absolutePath
135+
* @param path - The path relative to the dav root
136136
*/
137-
export async function createDirectoryIfNotExists(absolutePath: string) {
138-
const davClient = getClient()
139-
const dirExists = await davClient.exists(absolutePath)
137+
export async function createDirectoryIfNotExists(path: string) {
138+
const davUrl = join(defaultRemoteURL, defaultRootPath)
139+
const davClient = getClient(davUrl)
140+
const dirExists = await davClient.exists(path)
140141
if (!dirExists) {
141-
logger.debug('Directory does not exist, creating it', { absolutePath })
142-
await davClient.createDirectory(absolutePath, { recursive: true })
143-
const stat = await davClient.stat(absolutePath, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
144-
emit('files:node:created', resultToNode(stat.data))
142+
logger.debug('Directory does not exist, creating it', { path })
143+
await davClient.createDirectory(path, { recursive: true })
144+
const stat = await davClient.stat(path, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
145+
emit('files:node:created', resultToNode(stat.data, defaultRootPath, davUrl))
145146
}
146147
}
147148

0 commit comments

Comments
 (0)