Compare commits

...

4 Commits

Author SHA1 Message Date
b93e2978b0 cleanup
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2025-03-15 19:01:29 -05:00
ece002f25b fixes 2025-03-15 19:00:17 -05:00
b9f5f774e2 display error if mount location is not found 2025-03-15 18:43:43 -05:00
52d210974b display error if mount location is not found 2025-03-15 18:34:49 -05:00
3 changed files with 45 additions and 17 deletions

View File

@ -334,6 +334,7 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
} else { } else {
if (not utils::file::directory{location}.exists()) { if (not utils::file::directory{location}.exists()) {
res.status = http_error_codes::internal_error; res.status = http_error_codes::internal_error;
return;
} }
launch_process(prov, name, fmt::format(R"("{}")", location), true); launch_process(prov, name, fmt::format(R"("{}")", location), true);

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount_list.dart'; import 'package:repertory/models/mount_list.dart';
import 'package:repertory/types/mount_config.dart'; import 'package:repertory/types/mount_config.dart';
@ -73,9 +74,9 @@ class Mount with ChangeNotifier {
} }
} }
Future<void> mount(bool unmount, {String? location}) async { Future<bool> mount(bool unmount, {String? location}) async {
try { try {
await http.post( final response = await http.post(
Uri.parse( Uri.parse(
Uri.encodeFull( Uri.encodeFull(
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location', '${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
@ -83,10 +84,16 @@ class Mount with ChangeNotifier {
), ),
); );
return refresh(); if (!unmount && response.statusCode == 500) {
return false;
}
await refresh();
} catch (e) { } catch (e) {
debugPrint('$e'); debugPrint('$e');
} }
return true;
} }
Future<void> refresh() async { Future<void> refresh() async {

View File

@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart'; import 'package:repertory/models/mount.dart';
@ -140,9 +141,15 @@ class _MountWidgetState extends State<MountWidget> {
} }
} }
cleanup() {
setState(() {
_enabled = true;
});
}
if (location == null) { if (location == null) {
if (!context.mounted) { if (!context.mounted) {
return; return cleanup();
} }
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -153,21 +160,34 @@ class _MountWidgetState extends State<MountWidget> {
), ),
), ),
); );
return;
return cleanup();
} }
mount final success = await mount.mount(
.mount(isActive, location: location) isActive,
.then((_) { location: location,
setState(() { );
_enabled = true;
}); if (success ||
}) isActive ||
.catchError((_) { constants.navigatorKey.currentContext == null ||
setState(() { !constants.navigatorKey.currentContext!.mounted) {
_enabled = true; return cleanup();
}); }
});
ScaffoldMessenger.of(
constants.navigatorKey.currentContext!,
).showSnackBar(
SnackBar(
content: const Text(
"Mount location not found",
textAlign: TextAlign.center,
),
),
);
return cleanup();
} }
: null, : null,
), ),