@@ -33,27 +33,41 @@ import { LyraWebDAVConnect } from "./webdav-connect";
3333// Import commands (registers themselves)
3434import './webdav-commands' ;
3535
36+ async function getNextWebdavWorkspaceName ( ) : Promise < string > {
37+ const folders = await workspaceService . getFolders ( ) ;
38+ const used = new Set ( folders . filter ( ( f ) => f . type === 'webdav' ) . map ( ( f ) => f . name ) ) ;
39+ let n = 1 ;
40+ while ( used . has ( `webdav${ n } ` ) ) {
41+ n += 1 ;
42+ }
43+ return `webdav${ n } ` ;
44+ }
45+
3646// Register WebDAV as a workspace contribution
3747workspaceService . registerContribution ( {
3848 type : 'webdav' ,
3949 name : 'webdav' ,
40-
50+
4151 canHandle ( input : any ) : boolean {
4252 // Accept any connection info with a URL (credentials are optional for public/shared folders)
4353 return input && typeof input === 'object' && 'url' in input && typeof input . url === 'string' ;
4454 } ,
45-
55+
4656 async connect ( input : WebDAVConnectionInfo ) {
57+ const name =
58+ typeof input . name === 'string' && input . name . trim ( ) . length > 0
59+ ? input . name . trim ( )
60+ : await getNextWebdavWorkspaceName ( ) ;
4761 const client = new WebDAVClient ( input ) ;
4862 const rootResource : WebDAVResource = {
4963 href : input . url ,
5064 displayName : extractWorkspaceNameFromUrl ( input . url ) ,
5165 isDirectory : true
5266 } ;
53- return new WebDAVDirectoryResource ( client , rootResource , undefined , input ) ;
67+ return new WebDAVDirectoryResource ( client , rootResource , undefined , { ... input , name } ) ;
5468 } ,
55-
56- async restore ( data : WebDAVConnectionInfo ) {
69+
70+ async restore ( data : WebDAVConnectionInfo & { name ?: string } ) {
5771 if ( ! data || ! data . url ) {
5872 return undefined ;
5973 }
@@ -64,20 +78,24 @@ workspaceService.registerContribution({
6478 username : data . username ,
6579 password : data . password ? decodePassword ( data . password ) : undefined
6680 } ;
81+ const name =
82+ typeof data . name === 'string' && data . name . trim ( ) . length > 0
83+ ? data . name . trim ( )
84+ : await getNextWebdavWorkspaceName ( ) ;
6785
6886 const client = new WebDAVClient ( restored ) ;
6987 const rootResource : WebDAVResource = {
7088 href : data . url ,
7189 displayName : extractWorkspaceNameFromUrl ( data . url ) ,
7290 isDirectory : true
7391 } ;
74- return new WebDAVDirectoryResource ( client , rootResource , undefined , restored ) ;
92+ return new WebDAVDirectoryResource ( client , rootResource , undefined , { ... restored , name } ) ;
7593 } catch ( error ) {
7694 logger . error ( 'Failed to restore WebDAV workspace:' , error ) ;
7795 return undefined ;
7896 }
7997 } ,
80-
98+
8199 async persist ( workspace ) {
82100 if ( workspace instanceof WebDAVDirectoryResource ) {
83101 const connectionInfo = workspace . getConnectionInfo ( ) ;
@@ -87,6 +105,7 @@ workspaceService.registerContribution({
87105
88106 return {
89107 url : connectionInfo . url ,
108+ name : workspace . getName ( ) ,
90109 ...( connectionInfo . username !== undefined ? { username : connectionInfo . username } : { } ) ,
91110 ...( connectionInfo . password !== undefined ? { password : encodePassword ( connectionInfo . password ) } : { } )
92111 } ;
0 commit comments