Skip to content

Commit 702787e

Browse files
solracsfsusnux
authored andcommitted
fix(filesDrop): drag-and-drop folder upload directories
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent f95011b commit 702787e

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

apps/files/src/services/DropService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function onDropExternalFiles(root: RootDirectory, destination: IFol
127127
if (file instanceof Directory) {
128128
try {
129129
logger.debug('Processing directory', { relativePath })
130-
await createDirectoryIfNotExists(relativePath)
130+
await createDirectoryIfNotExists(relativePath, destination)
131131
await uploadDirectoryContents(file, relativePath)
132132
} catch (error) {
133133
showError(t('files', 'Unable to create the directory {directory}', { directory: file.name }))

apps/files/src/services/DropServiceUtils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,21 @@ const readDirectory = (directory: FileSystemDirectoryEntry): Promise<FileSystemE
133133
}
134134

135135
/**
136-
* @param path - The path relative to the dav root
136+
* @param path - The path relative to the destination root
137+
* @param destination - The destination folder. When provided, directories are created relative
138+
* to its source URL instead of the default user root. This is needed for uploads into
139+
* non-default locations like team folders.
137140
*/
138-
export async function createDirectoryIfNotExists(path: string) {
139-
const davUrl = join(defaultRemoteURL, defaultRootPath)
141+
export async function createDirectoryIfNotExists(path: string, destination?: IFolder) {
142+
const davUrl = destination?.source ?? join(defaultRemoteURL, defaultRootPath)
143+
const davRoot = destination?.root ?? defaultRootPath
140144
const davClient = getClient(davUrl)
141145
const dirExists = await davClient.exists(path)
142146
if (!dirExists) {
143-
logger.debug('Directory does not exist, creating it', { path })
147+
logger.debug('Directory does not exist, creating it', { path, davUrl })
144148
await davClient.createDirectory(path, { recursive: true })
145149
const stat = await davClient.stat(path, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
146-
emit('files:node:created', resultToNode(stat.data, defaultRootPath, davUrl))
150+
emit('files:node:created', resultToNode(stat.data, davRoot, davUrl))
147151
}
148152
}
149153

0 commit comments

Comments
 (0)