66import  type  {  AxiosError  }  from  '@nextcloud/axios' 
77import  type  {  Node  }  from  '@nextcloud/files' 
88
9+ import  {  FileAction  }  from  '@nextcloud/files' 
910import  {  showWarning  }  from  '@nextcloud/dialogs' 
1011import  {  translate  as  t  }  from  '@nextcloud/l10n' 
1112import  AlertSvg  from  '@mdi/svg/svg/alert-circle.svg?raw' 
@@ -15,7 +16,6 @@ import '../css/fileEntryStatus.scss'
1516import  {  getStatus ,  type  StorageConfig  }  from  '../services/externalStorage' 
1617import  {  isMissingAuthConfig ,  STORAGE_STATUS  }  from  '../utils/credentialsUtils' 
1718import  {  isNodeExternalStorage  }  from  '../utils/externalStorageUtils' 
18- import  {  FileAction  }  from  '@nextcloud/files' 
1919
2020export  const  action  =  new  FileAction ( { 
2121	id : 'check-external-storage' , 
@@ -33,45 +33,51 @@ export const action = new FileAction({
3333	 * @param  node 
3434	 */ 
3535	async  renderInline ( node : Node )  { 
36+ 		const  span  =  document . createElement ( 'span' ) 
37+ 		span . className  =  'files-list__row-status' 
38+ 		span . innerHTML  =  t ( 'files_external' ,  'Checking storage...' ) 
39+ 
3640		let  config  =  null  as  unknown  as  StorageConfig 
37- 		try  { 
38- 			const  response  =  await  getStatus ( node . attributes . id ,  node . attributes . scope  ===  'system' ) 
39- 			config  =  response . data 
40- 			Vue . set ( node . attributes ,  'config' ,  config ) 
41+ 		getStatus ( node . attributes . id ,  node . attributes . scope  ===  'system' ) 
42+ 			. then ( response  =>  { 
43+ 
44+ 				config  =  response . data 
45+ 				Vue . set ( node . attributes ,  'config' ,  config ) 
46+ 
47+ 				if  ( config . status  !==  STORAGE_STATUS . SUCCESS )  { 
48+ 					throw  new  Error ( config ?. statusMessage  ||  t ( 'files_external' ,  'There was an error with this external storage.' ) ) 
49+ 				} 
4150
42- 			if  ( config . status  !==  STORAGE_STATUS . SUCCESS )  { 
43- 				throw  new  Error ( config ?. statusMessage  ||  t ( 'files_external' ,  'There was an error with this external storage.' ) ) 
44- 			} 
51+ 				span . remove ( ) 
52+ 			} ) 
53+ 			. catch ( error  =>  { 
54+ 				// If axios failed or if something else prevented 
55+ 				// us from getting the config 
56+ 				if  ( ( error  as  AxiosError ) . response  &&  ! config )  { 
57+ 					showWarning ( t ( 'files_external' ,  'We were unable to check the external storage {basename}' ,  { 
58+ 						basename : node . basename , 
59+ 					} ) ) 
60+ 				} 
4561
46- 			return  null 
47- 		}  catch  ( error )  { 
48- 			// If axios failed or if something else prevented 
49- 			// us from getting the config 
50- 			if  ( ( error  as  AxiosError ) . response  &&  ! config )  { 
51- 				showWarning ( t ( 'files_external' ,  'We were unable to check the external storage {basename}' ,  { 
52- 					basename : node . basename , 
53- 				} ) ) 
54- 				return  null 
55- 			} 
62+ 				// Reset inline status 
63+ 				span . innerHTML  =  '' 
5664
57- 			// Checking if we really have an error 
58- 			const  isWarning  =  isMissingAuthConfig ( config ) 
59- 			const  overlay  =  document . createElement ( 'span' ) 
60- 			overlay . classList . add ( `files-list__row-status--${ isWarning  ? 'warning'  : 'error' }  ) 
65+ 				 // Checking if we really have an error 
66+ 				 const  isWarning  =   ! config  ?  false  :  isMissingAuthConfig ( config ) 
67+ 				 const  overlay  =  document . createElement ( 'span' ) 
68+ 				 overlay . classList . add ( `files-list__row-status--${ isWarning  ? 'warning'  : 'error' }  ) 
6169
62- 			const  span  =  document . createElement ( 'span' ) 
63- 			span . className  =  'files-list__row-status' 
70+ 				// Only show an icon for errors, warning like missing credentials 
71+ 				// have a dedicated inline action button 
72+ 				if  ( ! isWarning )  { 
73+ 					span . innerHTML  =  AlertSvg 
74+ 					span . title  =  ( error  as  Error ) . message 
75+ 				} 
6476
65- 			// Only show an icon for errors, warning like missing credentials 
66- 			// have a dedicated inline action button 
67- 			if  ( ! isWarning )  { 
68- 				span . innerHTML  =  AlertSvg 
69- 				span . title  =  ( error  as  Error ) . message 
70- 			} 
77+ 				span . prepend ( overlay ) 
78+ 			} ) 
7179
72- 			span . prepend ( overlay ) 
73- 			return  span 
74- 		} 
80+ 		return  span 
7581	} , 
7682
7783	order : 10 , 
0 commit comments