[ui] Implement provider test button #49
This commit is contained in:
parent
eaa95cf9d1
commit
1a02d89ab9
@ -315,6 +315,8 @@ auto handlers::data_directory_exists(provider_type prov,
|
|||||||
void handlers::generate_config(provider_type prov, std::string_view name,
|
void handlers::generate_config(provider_type prov, std::string_view name,
|
||||||
const json &cfg,
|
const json &cfg,
|
||||||
std::optional<std::string> data_dir) const {
|
std::optional<std::string> data_dir) const {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
std::map<std::string, std::string> values{};
|
std::map<std::string, std::string> values{};
|
||||||
for (const auto &[key, value] : cfg.items()) {
|
for (const auto &[key, value] : cfg.items()) {
|
||||||
if (value.is_object()) {
|
if (value.is_object()) {
|
||||||
@ -342,7 +344,13 @@ void handlers::generate_config(provider_type prov, std::string_view name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data_dir.has_value()) {
|
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"});
|
launch_process(prov, name, {"-dd", data_dir.value(), "-gc"});
|
||||||
} else {
|
} else {
|
||||||
launch_process(prov, name, {"-gc"});
|
launch_process(prov, name, {"-gc"});
|
||||||
@ -530,11 +538,16 @@ void handlers::handle_get_test(const httplib::Request &req,
|
|||||||
auto data_dir = utils::path::combine(
|
auto data_dir = utils::path::combine(
|
||||||
utils::directory::temp(), {utils::file::create_temp_name("repertory")});
|
utils::directory::temp(), {utils::file::create_temp_name("repertory")});
|
||||||
|
|
||||||
generate_config(prov, name, cfg, data_dir);
|
try {
|
||||||
|
generate_config(prov, name, cfg, data_dir);
|
||||||
|
|
||||||
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
|
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
|
||||||
res.status = lines.at(0U) == "0" ? http_error_codes::ok
|
res.status = lines.at(0U) == "0" ? http_error_codes::ok
|
||||||
: http_error_codes::internal_error;
|
: 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();
|
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"));
|
auto cfg = nlohmann::json::parse(req.get_param_value("config"));
|
||||||
generate_config(prov, name, cfg);
|
generate_config(prov, name, cfg);
|
||||||
|
|
||||||
launch_process(prov, name, {"-test"});
|
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,11 +285,15 @@ class Mount with ChangeNotifier {
|
|||||||
|
|
||||||
Future<bool> test() async {
|
Future<bool> test() async {
|
||||||
try {
|
try {
|
||||||
|
final map = await convertAllToString(
|
||||||
|
jsonDecode(jsonEncode(mountConfig.settings)),
|
||||||
|
_auth.key,
|
||||||
|
);
|
||||||
final auth = await _auth.createAuth();
|
final auth = await _auth.createAuth();
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
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)}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user