[ui] Implement provider test button #49

This commit is contained in:
Scott E. Graves 2025-04-24 06:54:53 -05:00
parent eaa95cf9d1
commit 1a02d89ab9
2 changed files with 23 additions and 7 deletions

View File

@ -315,6 +315,8 @@ auto handlers::data_directory_exists(provider_type prov,
void handlers::generate_config(provider_type prov, std::string_view name,
const json &cfg,
std::optional<std::string> data_dir) const {
REPERTORY_USES_FUNCTION_NAME();
std::map<std::string, std::string> values{};
for (const auto &[key, value] : cfg.items()) {
if (value.is_object()) {
@ -342,7 +344,13 @@ void handlers::generate_config(provider_type prov, std::string_view name,
}
if (data_dir.has_value()) {
utils::file::directory{data_dir.value()}.create_directory();
if (not utils::file::directory{data_dir.value()}.create_directory()) {
throw utils::error::create_exception(function_name,
{
"failed to create data diretory",
data_dir.value(),
});
}
launch_process(prov, name, {"-dd", data_dir.value(), "-gc"});
} else {
launch_process(prov, name, {"-gc"});
@ -530,11 +538,16 @@ void handlers::handle_get_test(const httplib::Request &req,
auto data_dir = utils::path::combine(
utils::directory::temp(), {utils::file::create_temp_name("repertory")});
try {
generate_config(prov, name, cfg, data_dir);
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
res.status = lines.at(0U) == "0" ? http_error_codes::ok
: http_error_codes::internal_error;
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e, "test provider config failed");
res.status = http_error_codes::internal_error;
}
utils::file::directory{data_dir}.remove_recursively();
}
@ -551,7 +564,6 @@ void handlers::handle_post_add_mount(const httplib::Request &req,
auto cfg = nlohmann::json::parse(req.get_param_value("config"));
generate_config(prov, name, cfg);
launch_process(prov, name, {"-test"});
res.status = http_error_codes::ok;
}

View File

@ -285,11 +285,15 @@ class Mount with ChangeNotifier {
Future<bool> test() async {
try {
final map = await convertAllToString(
jsonDecode(jsonEncode(mountConfig.settings)),
_auth.key,
);
final auth = await _auth.createAuth();
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(mountConfig.settings)}',
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(map)}',
),
),
);