@@ -132,17 +132,21 @@ const readDirectory = (directory: FileSystemDirectoryEntry): Promise<FileSystemE
132132}
133133
134134/**
135- * @param path - The path relative to the dav root
135+ * @param path - The path relative to the destination root
136+ * @param destination - The destination folder. When provided, directories are created relative
137+ * to its source URL instead of the default user root. This is needed for uploads into
138+ * non-default locations like team folders.
136139 */
137- export async function createDirectoryIfNotExists ( path : string ) {
138- const davUrl = join ( defaultRemoteURL , defaultRootPath )
140+ export async function createDirectoryIfNotExists ( path : string , destination ?: IFolder ) {
141+ const davUrl = destination ?. source ?? join ( defaultRemoteURL , defaultRootPath )
142+ const davRoot = destination ?. root ?? defaultRootPath
139143 const davClient = getClient ( davUrl )
140144 const dirExists = await davClient . exists ( path )
141145 if ( ! dirExists ) {
142- logger . debug ( 'Directory does not exist, creating it' , { path } )
146+ logger . debug ( 'Directory does not exist, creating it' , { path, davUrl } )
143147 await davClient . createDirectory ( path , { recursive : true } )
144148 const stat = await davClient . stat ( path , { details : true , data : getDefaultPropfind ( ) } ) as ResponseDataDetailed < FileStat >
145- emit ( 'files:node:created' , resultToNode ( stat . data , defaultRootPath , davUrl ) )
149+ emit ( 'files:node:created' , resultToNode ( stat . data , davRoot , davUrl ) )
146150 }
147151}
148152
0 commit comments