@@ -65,34 +65,49 @@ class DiskStore extends VuexModule {
6565 }
6666
6767 @Action
68- async deletePath ( path : string ) : Promise < void > {
68+ async deletePaths ( paths : string [ ] ) : Promise < { succeeded : string [ ] ; failed : { path : string ; error : string } [ ] } > {
6969 this . setDeleting ( true )
7070 this . setError ( null )
71- await back_axios ( {
72- method : 'delete' ,
73- url : `${ this . API_URL } /paths/${ encodeURIComponent ( path ) } ` ,
74- timeout : 120000 ,
75- } )
76- . then ( async ( ) => {
77- // Refresh after delete using the current usage query to reflect changes
78- if ( this . usage ) {
79- await this . fetchUsage ( {
80- path : this . usage . root . path ,
81- depth : this . usage . depth ,
82- include_files : this . usage . include_files ,
83- min_size_bytes : this . usage . min_size_bytes ,
84- } )
85- }
86- } )
87- . catch ( ( error ) => {
71+
72+ const deleteOne = async ( path : string ) : Promise < void > => {
73+ try {
74+ await back_axios ( {
75+ method : 'delete' ,
76+ url : `${ this . API_URL } /paths/${ encodeURIComponent ( path ) } ` ,
77+ timeout : 120000 ,
78+ } )
79+ } catch ( error : unknown ) {
8880 if ( isBackendOffline ( error ) ) {
89- return
81+ throw new Error ( 'Backend is offline' )
9082 }
91- this . setError ( `Failed to delete path: ${ error . response ?. data ?. detail || error . message } ` )
92- } )
93- . finally ( ( ) => {
94- this . setDeleting ( false )
95- } )
83+ const axiosError = error as { response ?: { data ?: { detail ?: string } } ; message ?: string }
84+ const message = axiosError . response ?. data ?. detail || axiosError . message || 'Unknown error'
85+ throw new Error ( message )
86+ }
87+ }
88+
89+ const results = await Promise . allSettled ( paths . map ( ( path ) => deleteOne ( path ) ) )
90+
91+ const succeeded : string [ ] = [ ]
92+ const failed : { path : string ; error : string } [ ] = [ ]
93+
94+ results . forEach ( ( result , index ) => {
95+ if ( result . status === 'fulfilled' ) {
96+ succeeded . push ( paths [ index ] )
97+ } else {
98+ failed . push ( { path : paths [ index ] , error : result . reason ?. message || 'Unknown error' } )
99+ }
100+ } )
101+
102+ if ( failed . length > 0 ) {
103+ const errorMsg = failed . length === 1
104+ ? `Failed to delete ${ failed [ 0 ] . path } : ${ failed [ 0 ] . error } `
105+ : `Failed to delete ${ failed . length } path(s): ${ failed . map ( ( f ) => f . path ) . join ( ', ' ) } `
106+ this . setError ( errorMsg )
107+ }
108+
109+ this . setDeleting ( false )
110+ return { succeeded, failed }
96111 }
97112}
98113
0 commit comments