Compare commits
2 Commits
7d1574d042
...
e886940999
Author | SHA1 | Date | |
---|---|---|---|
e886940999 | |||
a2a1f3e905 |
@ -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
|
||||
|
@ -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> {
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user