refactor
This commit is contained in:
@ -111,8 +111,8 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
|
||||
if (object_list.contains("entries")) {
|
||||
for (const auto &entry : object_list.at("entries")) {
|
||||
try {
|
||||
auto name = entry.at("name").get<std::string>();
|
||||
auto entry_api_path = utils::path::create_api_path(name);
|
||||
auto name{entry.at("name").get<std::string>()};
|
||||
auto entry_api_path{utils::path::create_api_path(name)};
|
||||
if (utils::string::ends_with(name, "/") &&
|
||||
(entry_api_path == api_path)) {
|
||||
continue;
|
||||
@ -148,10 +148,10 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
|
||||
if (object_list.contains("entries")) {
|
||||
for (const auto &entry : object_list.at("entries")) {
|
||||
try {
|
||||
auto name = entry.at("name").get<std::string>();
|
||||
auto entry_api_path = utils::path::create_api_path(name);
|
||||
auto name{entry.at("name").get<std::string>()};
|
||||
auto entry_api_path{utils::path::create_api_path(name)};
|
||||
|
||||
auto directory = utils::string::ends_with(name, "/");
|
||||
auto directory{utils::string::ends_with(name, "/")};
|
||||
if (directory && (entry_api_path == api_path)) {
|
||||
continue;
|
||||
}
|
||||
@ -164,7 +164,7 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
|
||||
: entry["size"].get<std::uint64_t>(),
|
||||
get_last_modified(entry));
|
||||
get_api_item_added()(directory, file);
|
||||
auto res = get_item_meta(entry_api_path, meta);
|
||||
auto res{get_item_meta(entry_api_path, meta)};
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, entry_api_path,
|
||||
res, "failed to get item meta");
|
||||
@ -201,18 +201,19 @@ auto sia_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
|
||||
try {
|
||||
json file_data{};
|
||||
auto res = get_object_info(api_path, file_data);
|
||||
auto res{get_object_info(api_path, file_data)};
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
auto slabs = file_data["object"]["Slabs"];
|
||||
auto size = std::accumulate(
|
||||
slabs.begin(), slabs.end(), std::uint64_t(0U),
|
||||
[](std::uint64_t total_size,
|
||||
const nlohmann::json &slab) -> std::uint64_t {
|
||||
return total_size + slab["Length"].get<std::uint64_t>();
|
||||
});
|
||||
auto slabs{file_data["object"]["Slabs"]};
|
||||
auto size{
|
||||
std::accumulate(
|
||||
slabs.begin(), slabs.end(), std::uint64_t(0U),
|
||||
[](std::uint64_t total_size, auto &&slab) -> std::uint64_t {
|
||||
return total_size + slab["Length"].get<std::uint64_t>();
|
||||
}),
|
||||
};
|
||||
|
||||
api_meta_map meta{};
|
||||
if (get_item_meta(api_path, meta) == api_error::item_not_found) {
|
||||
@ -247,8 +248,8 @@ auto sia_provider::get_file_list(api_file_list &list,
|
||||
|
||||
if (object_list.contains("entries")) {
|
||||
for (const auto &entry : object_list.at("entries")) {
|
||||
auto name = entry.at("name").get<std::string>();
|
||||
auto entry_api_path = utils::path::create_api_path(name);
|
||||
auto name{entry.at("name").get<std::string>()};
|
||||
auto entry_api_path{utils::path::create_api_path(name)};
|
||||
|
||||
if (utils::string::ends_with(name, "/")) {
|
||||
if (entry_api_path == utils::path::create_api_path(api_path)) {
|
||||
@ -258,12 +259,14 @@ auto sia_provider::get_file_list(api_file_list &list,
|
||||
api_meta_map meta{};
|
||||
if (get_item_meta(entry_api_path, meta) ==
|
||||
api_error::item_not_found) {
|
||||
auto dir = create_api_file(entry_api_path, "", 0U,
|
||||
get_last_modified(entry));
|
||||
auto dir{
|
||||
create_api_file(entry_api_path, "", 0U,
|
||||
get_last_modified(entry)),
|
||||
};
|
||||
get_api_item_added()(true, dir);
|
||||
}
|
||||
|
||||
auto res = get_files_in_dir(entry_api_path);
|
||||
auto res{get_files_in_dir(entry_api_path)};
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
@ -480,7 +483,7 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
}
|
||||
|
||||
json file_data{};
|
||||
auto res = get_object_info(api_path, file_data);
|
||||
auto res{get_object_info(api_path, file_data)};
|
||||
if (res == api_error::item_not_found) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
Reference in New Issue
Block a user