11/** 
2-  * @copyright  Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> 
3-  * 
4-  * @author  John Molakvoæ <skjnldsv@protonmail.com> 
5-  * 
6-  * @license  AGPL-3.0-or-later 
7-  * 
8-  * This program is free software: you can redistribute it and/or modify 
9-  * it under the terms of the GNU Affero General Public License as 
10-  * published by the Free Software Foundation, either version 3 of the 
11-  * License, or (at your option) any later version. 
12-  * 
13-  * This program is distributed in the hope that it will be useful, 
14-  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
15-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16-  * GNU Affero General Public License for more details. 
17-  * 
18-  * You should have received a copy of the GNU Affero General Public License 
19-  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
20-  * 
2+  * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors 
3+  * SPDX-License-Identifier: AGPL-3.0-or-later 
214 */ 
225// eslint-disable-next-line n/no-extraneous-import 
23- import  type  {  AxiosError  }  from  'axios' 
6+ import  type  {  AxiosError  }  from  '@nextcloud/ axios' 
247import  type  {  Node  }  from  '@nextcloud/files' 
258
9+ import  {  FileAction  }  from  '@nextcloud/files' 
2610import  {  showWarning  }  from  '@nextcloud/dialogs' 
2711import  {  translate  as  t  }  from  '@nextcloud/l10n' 
2812import  AlertSvg  from  '@mdi/svg/svg/alert-circle.svg?raw' 
@@ -32,7 +16,6 @@ import '../css/fileEntryStatus.scss'
3216import  {  getStatus ,  type  StorageConfig  }  from  '../services/externalStorage' 
3317import  {  isMissingAuthConfig ,  STORAGE_STATUS  }  from  '../utils/credentialsUtils' 
3418import  {  isNodeExternalStorage  }  from  '../utils/externalStorageUtils' 
35- import  {  FileAction  }  from  '@nextcloud/files' 
3619
3720export  const  action  =  new  FileAction ( { 
3821	id : 'check-external-storage' , 
@@ -47,47 +30,55 @@ export const action = new FileAction({
4730	/** 
4831	 * Use this function to check the storage availability 
4932	 * We then update the node attributes directly. 
33+ 	 * 
34+ 	 * @param  node The node to render inline 
5035	 */ 
5136	async  renderInline ( node : Node )  { 
52- 		let  config  =  null  as  any  as  StorageConfig 
53- 		try  { 
54- 			const  response  =  await  getStatus ( node . attributes . id ,  node . attributes . scope  ===  'system' ) 
55- 			config  =  response . data 
56- 			Vue . set ( node . attributes ,  'config' ,  config ) 
37+ 		const  span  =  document . createElement ( 'span' ) 
38+ 		span . className  =  'files-list__row-status' 
39+ 		span . innerHTML  =  t ( 'files_external' ,  'Checking storage …' ) 
40+ 
41+ 		let  config  =  null  as  unknown  as  StorageConfig 
42+ 		getStatus ( node . attributes . id ,  node . attributes . scope  ===  'system' ) 
43+ 			. then ( response  =>  { 
44+ 
45+ 				config  =  response . data 
46+ 				Vue . set ( node . attributes ,  'config' ,  config ) 
47+ 
48+ 				if  ( config . status  !==  STORAGE_STATUS . SUCCESS )  { 
49+ 					throw  new  Error ( config ?. statusMessage  ||  t ( 'files_external' ,  'There was an error with this external storage.' ) ) 
50+ 				} 
5751
58- 			if  ( config . status  !==  STORAGE_STATUS . SUCCESS )  { 
59- 				throw  new  Error ( config ?. statusMessage  ||  t ( 'files_external' ,  'There was an error with this external storage.' ) ) 
60- 			} 
52+ 				span . remove ( ) 
53+ 			} ) 
54+ 			. catch ( error  =>  { 
55+ 				// If axios failed or if something else prevented 
56+ 				// us from getting the config 
57+ 				if  ( ( error  as  AxiosError ) . response  &&  ! config )  { 
58+ 					showWarning ( t ( 'files_external' ,  'We were unable to check the external storage {basename}' ,  { 
59+ 						basename : node . basename , 
60+ 					} ) ) 
61+ 				} 
6162
62- 			return  null 
63- 		}  catch  ( error )  { 
64- 			// If axios failed or if something else prevented 
65- 			// us from getting the config 
66- 			if  ( ( error  as  AxiosError ) . response  &&  ! config )  { 
67- 				showWarning ( t ( 'files_external' ,  'We were unable to check the external storage {basename}' ,  { 
68- 					basename : node . basename , 
69- 				} ) ) 
70- 				return  null 
71- 			} 
63+ 				// Reset inline status 
64+ 				span . innerHTML  =  '' 
7265
73- 			// Checking if we really have an error 
74- 			const  isWarning  =  isMissingAuthConfig ( config ) 
75- 			const  overlay  =  document . createElement ( 'span' ) 
76- 			overlay . classList . add ( `files-list__row-status--${ isWarning  ? 'warning'  : 'error' }  ) 
66+ 				 // Checking if we really have an error 
67+ 				 const  isWarning  =   ! config  ?  false  :  isMissingAuthConfig ( config ) 
68+ 				 const  overlay  =  document . createElement ( 'span' ) 
69+ 				 overlay . classList . add ( `files-list__row-status--${ isWarning  ? 'warning'  : 'error' }  ) 
7770
78- 			const  span  =  document . createElement ( 'span' ) 
79- 			span . className  =  'files-list__row-status' 
71+ 				// Only show an icon for errors, warning like missing credentials 
72+ 				// have a dedicated inline action button 
73+ 				if  ( ! isWarning )  { 
74+ 					span . innerHTML  =  AlertSvg 
75+ 					span . title  =  ( error  as  Error ) . message 
76+ 				} 
8077
81- 			// Only show an icon for errors, warning like missing credentials 
82- 			// have a dedicated inline action button 
83- 			if  ( ! isWarning )  { 
84- 				span . innerHTML  =  AlertSvg 
85- 				span . title  =  ( error  as  Error ) . message 
86- 			} 
78+ 				span . prepend ( overlay ) 
79+ 			} ) 
8780
88- 			span . prepend ( overlay ) 
89- 			return  span 
90- 		} 
81+ 		return  span 
9182	} , 
9283
9384	order : 10 , 
0 commit comments