refactor
Some checks are pending
BlockStorage/repertory_linux_builds/pipeline/head Build queued...
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2023-11-14 18:26:00 -06:00
parent a605d7af11
commit b3aa28d085

View File

@ -39,76 +39,6 @@ namespace repertory {
sia_provider::sia_provider(app_config &config, i_http_comm &comm)
: base_provider(config, comm) {}
auto sia_provider::get_object_info(const std::string &api_path,
json &object_info) const -> api_error {
try {
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path;
get.response_handler = [&object_info](const data_buffer &data,
long response_code) {
if (response_code == http_error_codes::ok) {
object_info = nlohmann::json::parse(data.begin(), data.end());
}
};
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
return api_error::comm_error;
}
if (response_code == http_error_codes::not_found) {
return api_error::item_not_found;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
"failed to get object info");
return api_error::comm_error;
}
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
"failed to get object info");
}
return api_error::error;
}
auto sia_provider::get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool {
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path + "/";
get.response_handler = [&object_list](const data_buffer &data,
long response_code) {
if (response_code == http_error_codes::ok) {
object_list = nlohmann::json::parse(data.begin(), data.end());
}
};
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
api_error::comm_error,
"failed to get object list");
return false;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
"failed to get object list");
return false;
}
return true;
}
auto sia_provider::create_directory_impl(const std::string &api_path,
api_meta_map & /* meta */)
-> api_error {
@ -348,6 +278,76 @@ auto sia_provider::get_file_list(api_file_list &list) const -> api_error {
return get_files_in_dir("");
}
auto sia_provider::get_object_info(const std::string &api_path,
json &object_info) const -> api_error {
try {
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path;
get.response_handler = [&object_info](const data_buffer &data,
long response_code) {
if (response_code == http_error_codes::ok) {
object_info = nlohmann::json::parse(data.begin(), data.end());
}
};
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
return api_error::comm_error;
}
if (response_code == http_error_codes::not_found) {
return api_error::item_not_found;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
"failed to get object info");
return api_error::comm_error;
}
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
"failed to get object info");
}
return api_error::error;
}
auto sia_provider::get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool {
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path + "/";
get.response_handler = [&object_list](const data_buffer &data,
long response_code) {
if (response_code == http_error_codes::ok) {
object_list = nlohmann::json::parse(data.begin(), data.end());
}
};
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
api_error::comm_error,
"failed to get object list");
return false;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
"failed to get object list");
return false;
}
return true;
}
auto sia_provider::get_total_drive_space() const -> std::uint64_t {
try {
curl::requests::http_get get{};