v2.0.6-release (#50)
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				BlockStorage/repertory/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	BlockStorage/repertory/pipeline/head This commit looks good
				
			Reviewed-on: #50
This commit is contained in:
		| @@ -153,9 +153,9 @@ String getBaseUri() { | ||||
| String? getSettingDescription(String settingPath) { | ||||
|   switch (settingPath) { | ||||
|     case 'ApiPassword': | ||||
|       return "HTTP basic authentication password"; | ||||
|       return "HTTP authentication password"; | ||||
|     case 'ApiUser': | ||||
|       return "HTTP basic authentication user"; | ||||
|       return "HTTP authentication user"; | ||||
|     case 'HostConfig.ApiPassword': | ||||
|       return "RENTERD_API_PASSWORD"; | ||||
|     default: | ||||
|   | ||||
| @@ -282,4 +282,31 @@ class Mount with ChangeNotifier { | ||||
|       debugPrint('$e'); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   Future<bool> test() async { | ||||
|     try { | ||||
|       final map = await convertAllToString( | ||||
|         jsonDecode(jsonEncode(mountConfig.settings)), | ||||
|         _auth.key, | ||||
|       ); | ||||
|       final auth = await _auth.createAuth(); | ||||
|       final response = await http.get( | ||||
|         Uri.parse( | ||||
|           Uri.encodeFull( | ||||
|             '${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(map)}', | ||||
|           ), | ||||
|         ), | ||||
|       ); | ||||
|  | ||||
|       if (response.statusCode == 401) { | ||||
|         _auth.logoff(); | ||||
|       } | ||||
|  | ||||
|       return (response.statusCode == 200); | ||||
|     } catch (e) { | ||||
|       debugPrint('$e'); | ||||
|     } | ||||
|  | ||||
|     return false; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -21,6 +21,7 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|   Mount? _mount; | ||||
|   final _mountNameController = TextEditingController(); | ||||
|   String _mountType = ""; | ||||
|  | ||||
|   final Map<String, Map<String, dynamic>> _settings = { | ||||
|     "": {}, | ||||
|     "Encrypt": createDefaultSettings("Encrypt"), | ||||
| @@ -69,18 +70,16 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|                         DropdownButton<String>( | ||||
|                           autofocus: true, | ||||
|                           value: _mountType, | ||||
|                           onChanged: | ||||
|                               (mountType) => | ||||
|                                   _handleChange(auth, mountType ?? ''), | ||||
|                           items: | ||||
|                               constants.providerTypeList | ||||
|                                   .map<DropdownMenuItem<String>>((item) { | ||||
|                                     return DropdownMenuItem<String>( | ||||
|                                       value: item, | ||||
|                                       child: Text(item), | ||||
|                                     ); | ||||
|                                   }) | ||||
|                                   .toList(), | ||||
|                           onChanged: (mountType) => | ||||
|                               _handleChange(auth, mountType ?? ''), | ||||
|                           items: constants.providerTypeList | ||||
|                               .map<DropdownMenuItem<String>>((item) { | ||||
|                                 return DropdownMenuItem<String>( | ||||
|                                   value: item, | ||||
|                                   child: Text(item), | ||||
|                                 ); | ||||
|                               }) | ||||
|                               .toList(), | ||||
|                         ), | ||||
|                       ], | ||||
|                     ), | ||||
| @@ -113,8 +112,8 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|                       ), | ||||
|                     ), | ||||
|                   ), | ||||
|                 if (_mount != null) const SizedBox(height: constants.padding), | ||||
|                 if (_mount != null) | ||||
|                 if (_mount != null) ...[ | ||||
|                   const SizedBox(height: constants.padding), | ||||
|                   Expanded( | ||||
|                     child: Card( | ||||
|                       margin: EdgeInsets.all(0.0), | ||||
| @@ -129,10 +128,15 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|                       ), | ||||
|                     ), | ||||
|                   ), | ||||
|                 if (_mount != null) const SizedBox(height: constants.padding), | ||||
|                 if (_mount != null) | ||||
|                   const SizedBox(height: constants.padding), | ||||
|                   Row( | ||||
|                     children: [ | ||||
|                       ElevatedButton.icon( | ||||
|                         label: const Text('Test'), | ||||
|                         icon: const Icon(Icons.check), | ||||
|                         onPressed: _handleProviderTest, | ||||
|                       ), | ||||
|                       const SizedBox(width: constants.padding), | ||||
|                       ElevatedButton.icon( | ||||
|                         label: const Text('Add'), | ||||
|                         icon: const Icon(Icons.add), | ||||
| @@ -189,16 +193,9 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|                           Navigator.pop(context); | ||||
|                         }, | ||||
|                       ), | ||||
|                       if (_mountType == 'Sia' || _mountType == 'S3') ...[ | ||||
|                         const SizedBox(width: constants.padding), | ||||
|                         ElevatedButton.icon( | ||||
|                           label: const Text('Test'), | ||||
|                           icon: const Icon(Icons.check), | ||||
|                           onPressed: () async {}, | ||||
|                         ), | ||||
|                       ], | ||||
|                     ], | ||||
|                   ), | ||||
|                 ], | ||||
|               ], | ||||
|             ); | ||||
|           }, | ||||
| @@ -218,22 +215,37 @@ class _AddMountScreenState extends State<AddMountScreen> { | ||||
|         _mountNameController.text = mountType == 'Sia' ? 'default' : ''; | ||||
|       } | ||||
|  | ||||
|       _mount = | ||||
|           (_mountNameController.text.isEmpty) | ||||
|               ? null | ||||
|               : Mount( | ||||
|                 auth, | ||||
|                 MountConfig( | ||||
|                   name: _mountNameController.text, | ||||
|                   settings: _settings[mountType], | ||||
|                   type: mountType, | ||||
|                 ), | ||||
|                 null, | ||||
|                 isAdd: true, | ||||
|               ); | ||||
|       _mount = (_mountNameController.text.isEmpty) | ||||
|           ? null | ||||
|           : Mount( | ||||
|               auth, | ||||
|               MountConfig( | ||||
|                 name: _mountNameController.text, | ||||
|                 settings: _settings[mountType], | ||||
|                 type: mountType, | ||||
|               ), | ||||
|               null, | ||||
|               isAdd: true, | ||||
|             ); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   Future<void> _handleProviderTest() async { | ||||
|     if (_mount == null) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     final success = await _mount!.test(); | ||||
|     if (!mounted) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     displayErrorMessage( | ||||
|       context, | ||||
|       success ? "Success" : "Provider settings are invalid!", | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void setState(VoidCallback fn) { | ||||
|     if (!mounted) { | ||||
|   | ||||
| @@ -18,9 +18,11 @@ class MountSettingsWidget extends StatefulWidget { | ||||
|   final bool showAdvanced; | ||||
|   final Mount mount; | ||||
|   final Map<String, dynamic> settings; | ||||
|   final Function? onChanged; | ||||
|   const MountSettingsWidget({ | ||||
|     super.key, | ||||
|     this.isAdd = false, | ||||
|     this.onChanged, | ||||
|     required this.mount, | ||||
|     required this.settings, | ||||
|     required this.showAdvanced, | ||||
| @@ -1020,6 +1022,10 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     if (widget.onChanged != null) { | ||||
|       widget.onChanged!(); | ||||
|     } | ||||
|  | ||||
|     super.setState(fn); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user