Create management portal in Flutter #39
This commit is contained in:
parent
cd9ac4a02f
commit
76c105286f
@ -66,6 +66,9 @@ private:
|
|||||||
auto launch_process(provider_type prov, std::string_view name,
|
auto launch_process(provider_type prov, std::string_view name,
|
||||||
std::string_view args, bool background = false) const
|
std::string_view args, bool background = false) const
|
||||||
-> std::vector<std::string>;
|
-> std::vector<std::string>;
|
||||||
|
|
||||||
|
void set_key_value(provider_type prov, std::string_view name,
|
||||||
|
std::string_view key, std::string_view value) const;
|
||||||
};
|
};
|
||||||
} // namespace repertory::ui
|
} // namespace repertory::ui
|
||||||
|
|
||||||
|
@ -101,13 +101,13 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
handle_get_mount_status(req, res);
|
handle_get_mount_status(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
server->Post("/api/v1/mount",
|
|
||||||
[this](auto &&req, auto &&res) { handle_post_mount(req, res); });
|
|
||||||
|
|
||||||
server->Post("/api/v1/add_mount", [this](auto &&req, auto &&res) {
|
server->Post("/api/v1/add_mount", [this](auto &&req, auto &&res) {
|
||||||
handle_post_add_mount(req, res);
|
handle_post_add_mount(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server->Post("/api/v1/mount",
|
||||||
|
[this](auto &&req, auto &&res) { handle_post_mount(req, res); });
|
||||||
|
|
||||||
server->Put("/api/v1/set_value_by_name", [this](auto &&req, auto &&res) {
|
server->Put("/api/v1/set_value_by_name", [this](auto &&req, auto &&res) {
|
||||||
handle_put_set_value_by_name(req, res);
|
handle_put_set_value_by_name(req, res);
|
||||||
});
|
});
|
||||||
@ -150,6 +150,16 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
|
|
||||||
handlers::~handlers() { event_system::instance().stop(); }
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
|
||||||
|
void handlers::set_key_value(provider_type prov, std::string_view name,
|
||||||
|
std::string_view key,
|
||||||
|
std::string_view value) const {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
|
||||||
|
#else // !defined(_WIN32)
|
||||||
|
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
|
||||||
|
#endif // defined(_WIN32)
|
||||||
|
}
|
||||||
|
|
||||||
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -264,6 +274,18 @@ void handlers::handle_post_add_mount(auto &&req, auto &&res) const {
|
|||||||
fmt::println("config: {}-{}-{}", name, app_config::get_provider_name(prov),
|
fmt::println("config: {}-{}-{}", name, app_config::get_provider_name(prov),
|
||||||
cfg.dump(2));
|
cfg.dump(2));
|
||||||
|
|
||||||
|
launch_process(prov, name, "-gc");
|
||||||
|
for (const auto &[key, value] : cfg.items()) {
|
||||||
|
if (value.is_object()) {
|
||||||
|
for (const auto &[key2, value2] : value.items()) {
|
||||||
|
set_key_value(prov, name, fmt::format("{}.{}", key, key2),
|
||||||
|
value2.template get<std::string>());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set_key_value(prov, name, key, value.template get<std::string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,11 +310,7 @@ void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) const {
|
|||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
auto prov = provider_type_from_string(req.get_param_value("type"));
|
||||||
auto value = req.get_param_value("value");
|
auto value = req.get_param_value("value");
|
||||||
|
|
||||||
#if defined(_WIN32)
|
set_key_value(prov, name, key, value);
|
||||||
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
|
|
||||||
#else //! defined(_WIN32)
|
|
||||||
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
@ -175,21 +175,33 @@ bool validateSettings(
|
|||||||
}) {
|
}) {
|
||||||
settings.forEach((key, value) {
|
settings.forEach((key, value) {
|
||||||
final settingKey = rootKey == null ? key : '$rootKey.$key';
|
final settingKey = rootKey == null ? key : '$rootKey.$key';
|
||||||
if (value is Map) {
|
if (value is Map<String, dynamic>) {
|
||||||
validateSettings(
|
validateSettings(value, failed, rootKey: settingKey);
|
||||||
value as Map<String, dynamic>,
|
return;
|
||||||
failed,
|
}
|
||||||
rootKey: settingKey,
|
|
||||||
);
|
for (var validator in getSettingValidators(settingKey)) {
|
||||||
} else {
|
if (validator(value.toString())) {
|
||||||
for (var validator in getSettingValidators(settingKey)) {
|
continue;
|
||||||
if (validator(value.toString())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
failed.add(settingKey);
|
|
||||||
}
|
}
|
||||||
|
failed.add(settingKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return failed.isEmpty;
|
return failed.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertAllToString(Map<String, dynamic> settings) {
|
||||||
|
settings.forEach((key, value) {
|
||||||
|
if (value is Map<String, dynamic>) {
|
||||||
|
convertAllToString(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value is String) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings[key] = value.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -61,7 +61,7 @@ class MountList with ChangeNotifier {
|
|||||||
await http.post(
|
await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(mountConfig)}',
|
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(convertAllToString(mountConfig))}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user