Skip to content

Commit 2c3872f

Browse files
authored
Merge pull request #57095 from nextcloud/fix/public-upload
fix(files): ensure creating folders in public shares work
2 parents 5f33fee + bdd379e commit 2c3872f

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

apps/files/src/services/DropService.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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 { t } from '@nextcloud/l10n'
1413
import { join } from '@nextcloud/paths'
1514
import { getUploader, hasConflict } from '@nextcloud/upload'
@@ -125,14 +124,13 @@ export async function onDropExternalFiles(root: RootDirectory, destination: IFol
125124
// If the file is a directory, we need to create it first
126125
// then browse its tree and upload its contents.
127126
if (file instanceof Directory) {
128-
const absolutePath = join(getRootPath(), destination.path, relativePath)
129127
try {
130128
logger.debug('Processing directory', { relativePath })
131-
await createDirectoryIfNotExists(absolutePath)
129+
await createDirectoryIfNotExists(relativePath)
132130
await uploadDirectoryContents(file, relativePath)
133131
} catch (error) {
134132
showError(t('files', 'Unable to create the directory {directory}', { directory: file.name }))
135-
logger.error('', { error, absolutePath, directory: file })
133+
logger.error('Unable to create the directory', { error, relativePath, directory: file })
136134
}
137135
continue
138136
}

apps/files/src/services/DropServiceUtils.ts

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

99
import { showInfo, showWarning } from '@nextcloud/dialogs'
1010
import { emit } from '@nextcloud/event-bus'
11-
import { getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
11+
import { defaultRemoteURL, defaultRootPath, getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
1212
import { t } from '@nextcloud/l10n'
13+
import { join } from '@nextcloud/paths'
1314
import { openConflictPicker } from '@nextcloud/upload'
1415
import logger from '../logger.ts'
1516

@@ -132,18 +133,17 @@ function readDirectory(directory: FileSystemDirectoryEntry): Promise<FileSystemE
132133
}
133134

134135
/**
135-
* Create a directory if it does not exist
136-
*
137-
* @param absolutePath - the absolute path of the directory to create
136+
* @param path - The path relative to the dav root
138137
*/
139-
export async function createDirectoryIfNotExists(absolutePath: string) {
140-
const davClient = getClient()
141-
const dirExists = await davClient.exists(absolutePath)
138+
export async function createDirectoryIfNotExists(path: string) {
139+
const davUrl = join(defaultRemoteURL, defaultRootPath)
140+
const davClient = getClient(davUrl)
141+
const dirExists = await davClient.exists(path)
142142
if (!dirExists) {
143-
logger.debug('Directory does not exist, creating it', { absolutePath })
144-
await davClient.createDirectory(absolutePath, { recursive: true })
145-
const stat = await davClient.stat(absolutePath, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
146-
emit('files:node:created', resultToNode(stat.data))
143+
logger.debug('Directory does not exist, creating it', { path })
144+
await davClient.createDirectory(path, { recursive: true })
145+
const stat = await davClient.stat(path, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
146+
emit('files:node:created', resultToNode(stat.data, defaultRootPath, davUrl))
147147
}
148148
}
149149

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)