@@ -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