Compare commits

...

2 Commits

Author SHA1 Message Date
e886940999 fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2025-03-01 16:54:23 -06:00
a2a1f3e905 added unmount handling 2025-03-01 16:51:08 -06:00
4 changed files with 53 additions and 4 deletions

View File

@ -64,9 +64,10 @@ private:
void handle_get_mount_status(auto &&req, auto &&res) const;
[[nodiscard]] static auto read_process(provider_type prov,
std::string_view name,
std::string_view command)
void handle_post_mount(auto &&req, auto &&res) const;
static auto read_process(provider_type prov, std::string_view name,
std::string_view command)
-> std::vector<std::string>;
};
} // namespace repertory::ui

View File

@ -83,6 +83,9 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
handle_get_mount_status(req, res);
});
server->Post("/api/v1/mount",
[this](auto &&req, auto &&res) { handle_post_mount(req, res); });
event_system::instance().start();
static std::atomic<httplib::Server *> this_server{server_};
@ -200,6 +203,18 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
res.status = http_error_codes::ok;
}
void handlers::handle_post_mount(auto &&req, auto &&res) const {
auto type = req.get_param_value("type");
auto name = req.get_param_value("name");
auto unmount = utils::string::to_bool(req.get_param_value("unmount"));
auto prov = provider_type_from_string(type);
if (unmount) {
read_process(prov, name, "-unmount");
}
res.status = http_error_codes::ok;
}
auto handlers::read_process(provider_type prov, std::string_view name,
std::string_view command)
-> std::vector<std::string> {

View File

@ -48,6 +48,18 @@ class Mount with ChangeNotifier {
notifyListeners();
}
Future<void> mount(bool unmount) async {
await http.post(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/mount?unmount=$unmount&name=$name&type=$type',
),
),
);
return refresh();
}
Future<void> refresh() async {
await _fetch();
return _fetchStatus();

View File

@ -14,6 +14,7 @@ class MountWidget extends StatefulWidget {
class _MountWidgetState extends State<MountWidget> {
Timer? _timer;
bool _enabled = true;
@override
Widget build(BuildContext context) {
@ -57,7 +58,27 @@ class _MountWidgetState extends State<MountWidget> {
mount.state,
color: isActive ? Colors.blue : Colors.grey,
),
onPressed: () {},
onPressed:
_enabled
? () async {
setState(() {
_enabled = false;
});
if (isActive) {
mount.mount(isActive).then((_) {
setState(() {
_enabled = true;
});
});
return;
}
setState(() {
_enabled = false;
});
}
: null,
),
);
},