Compare commits

..

No commits in common. "6b629b81b428ef977ca7da5c291f03974ed921fa" and "6d09b2549e123a7249b69acb902afe1780a06d26" have entirely different histories.

4 changed files with 20 additions and 69 deletions

View File

@ -57,18 +57,13 @@ private:
void handle_get_mount_status(auto &&req, auto &&res) const; void handle_get_mount_status(auto &&req, auto &&res) const;
void handle_post_add_mount(auto &&req, auto &&res) const;
void handle_post_mount(auto &&req, auto &&res) const; void handle_post_mount(auto &&req, auto &&res) const;
void handle_put_set_value_by_name(auto &&req, auto &&res) const; void handle_put_set_value_by_name(auto &&req, auto &&res);
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

View File

@ -101,10 +101,6 @@ 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/add_mount", [this](auto &&req, auto &&res) {
handle_post_add_mount(req, res);
});
server->Post("/api/v1/mount", server->Post("/api/v1/mount",
[this](auto &&req, auto &&res) { handle_post_mount(req, res); }); [this](auto &&req, auto &&res) { handle_post_mount(req, res); });
@ -150,16 +146,6 @@ 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();
@ -267,26 +253,6 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
res.status = http_error_codes::ok; res.status = http_error_codes::ok;
} }
void handlers::handle_post_add_mount(auto &&req, auto &&res) const {
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
auto cfg = nlohmann::json::parse(req.get_param_value("config"));
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;
}
void handlers::handle_post_mount(auto &&req, auto &&res) const { void handlers::handle_post_mount(auto &&req, auto &&res) const {
auto location = utils::path::absolute(req.get_param_value("location")); auto location = utils::path::absolute(req.get_param_value("location"));
auto name = req.get_param_value("name"); auto name = req.get_param_value("name");
@ -302,13 +268,17 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
res.status = http_error_codes::ok; res.status = http_error_codes::ok;
} }
void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) const { void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) {
auto key = req.get_param_value("key"); auto key = req.get_param_value("key");
auto name = req.get_param_value("name"); auto name = req.get_param_value("name");
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");
set_key_value(prov, name, key, value); #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)
res.status = http_error_codes::ok; res.status = http_error_codes::ok;
} }

View File

@ -175,35 +175,21 @@ 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<String, dynamic>) { if (value is Map) {
validateSettings(value, failed, rootKey: settingKey); validateSettings(
return; value as Map<String, dynamic>,
} failed,
rootKey: settingKey,
for (var validator in getSettingValidators(settingKey)) { );
if (validator(value.toString())) { } else {
continue; for (var validator in getSettingValidators(settingKey)) {
if (validator(value.toString())) {
continue;
}
failed.add(settingKey);
} }
failed.add(settingKey);
} }
}); });
return failed.isEmpty; return failed.isEmpty;
} }
Map<String, dynamic> 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();
});
return settings;
}

View File

@ -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(convertAllToString(mountConfig))}', '${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(mountConfig)}',
), ),
), ),
); );