fix add mount
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
@@ -88,25 +88,58 @@ class MountList with ChangeNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> add(
|
||||
Future<bool> add(
|
||||
String type,
|
||||
String name,
|
||||
Map<String, dynamic> mountConfig,
|
||||
) async {
|
||||
var ret = false;
|
||||
|
||||
displayError() {
|
||||
if (constants.navigatorKey.currentContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
displayErrorMessage(
|
||||
constants.navigatorKey.currentContext!,
|
||||
'Add mount failed. Please try again.',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
final map = await convertAllToString(mountConfig);
|
||||
await http.post(
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(map)}',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
ret = true;
|
||||
break;
|
||||
case 404:
|
||||
reset();
|
||||
break;
|
||||
case 500:
|
||||
displayAuthError();
|
||||
break;
|
||||
default:
|
||||
displayError();
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
displayError();
|
||||
}
|
||||
|
||||
return _fetch();
|
||||
if (ret) {
|
||||
await _fetch();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Future<void> reset() async {
|
||||
@@ -126,10 +159,4 @@ class MountList with ChangeNotifier {
|
||||
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
void remove(String name) {
|
||||
_mountList.removeWhere((item) => item.name == name);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@@ -164,7 +164,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
await mountList.add(
|
||||
final success = await mountList.add(
|
||||
_mountType,
|
||||
_mountType == 'Remote'
|
||||
? '${_settings[_mountType]!['RemoteConfig']['HostNameOrIp']}_${_settings[_mountType]!['RemoteConfig']['ApiPort']}'
|
||||
@@ -172,9 +172,10 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
||||
_settings[_mountType]!,
|
||||
);
|
||||
|
||||
if (!context.mounted) {
|
||||
if (!success || !context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
label: const Text('Add'),
|
||||
|
Reference in New Issue
Block a user