This commit is contained in:
Scott E. Graves 2025-03-06 14:04:05 -06:00
parent 6f45848db4
commit 992a02a6ee
3 changed files with 106 additions and 67 deletions

View File

@ -20,6 +20,7 @@ class Mount with ChangeNotifier {
String get type => mountConfig.type;
Future<void> _fetch() async {
try {
final response = await http.get(
Uri.parse(
Uri.encodeFull('${getBaseUri()}/api/v1/mount?name=$name&type=$type'),
@ -33,9 +34,13 @@ class Mount with ChangeNotifier {
mountConfig.updateSettings(jsonDecode(response.body));
notifyListeners();
} catch (e) {
debugPrint('$e');
}
}
Future<void> _fetchStatus() async {
try {
final response = await http.get(
Uri.parse(
Uri.encodeFull(
@ -50,9 +55,13 @@ class Mount with ChangeNotifier {
mountConfig.updateStatus(jsonDecode(response.body));
notifyListeners();
} catch (e) {
debugPrint('$e');
}
}
Future<void> mount(bool unmount, {String? location}) async {
try {
await http.post(
Uri.parse(
Uri.encodeFull(
@ -62,6 +71,9 @@ class Mount with ChangeNotifier {
);
return refresh();
} catch (e) {
debugPrint('$e');
}
}
Future<void> refresh() async {
@ -70,6 +82,7 @@ class Mount with ChangeNotifier {
}
Future<void> setValue(String key, String value) async {
try {
await http.put(
Uri.parse(
Uri.encodeFull(
@ -79,9 +92,13 @@ class Mount with ChangeNotifier {
);
return refresh();
} catch (e) {
debugPrint('$e');
}
}
Future<String?> getMountLocation() async {
try {
final response = await http.get(
Uri.parse(
Uri.encodeFull(
@ -95,5 +112,10 @@ class Mount with ChangeNotifier {
}
return jsonDecode(response.body)['Location'] as String;
} catch (e) {
debugPrint('$e');
}
return null;
}
}

View File

@ -17,11 +17,14 @@ class MountList with ChangeNotifier {
UnmodifiableListView<MountConfig>(_mountList);
Future<void> _fetch() async {
try {
final response = await http.get(
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
);
if (response.statusCode == 200) {
if (response.statusCode != 200) {
return;
}
List<MountConfig> nextList = [];
jsonDecode(response.body).forEach((key, value) {
@ -33,7 +36,8 @@ class MountList with ChangeNotifier {
_mountList = nextList;
notifyListeners();
return;
} catch (e) {
debugPrint('$e');
}
}
@ -50,25 +54,22 @@ class MountList with ChangeNotifier {
Future<void> add(
String type,
String name, {
String? apiPassword,
String? apiPort,
String? bucket,
String? encryptionToken,
String? hostNameOrIp,
String? path,
}) async {
String name,
Map<String, dynamic> mountConfig,
) async {
try {
await http.post(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&bucket=$bucket'
'&path=$path&apiPassword=$apiPassword&apiPort=$apiPort&hostNameOrIp=$hostNameOrIp'
'&encryptionToken=$encryptionToken',
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(mountConfig)}',
),
),
);
return _fetch();
} catch (e) {
debugPrint('$e');
}
}
void remove(String name) {

View File

@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:repertory/constants.dart';
import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart';
import 'package:repertory/models/mount_list.dart';
import 'package:repertory/types/mount_config.dart';
import 'package:repertory/widgets/mount_settings.dart';
@ -116,6 +118,20 @@ class _AddMountScreenState extends State<AddMountScreen> {
),
),
),
if (_mount != null)
ElevatedButton.icon(
onPressed: () {
Provider.of<MountList>(context, listen: false).add(
_mountType,
_mountNameController.text,
_settings[_mountType]!,
);
Navigator.pop(context);
},
label: const Text('Add'),
icon: Icon(Icons.add),
),
],
),
),