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")) {
|
if (object_list.contains("entries")) {
|
||||||
for (const auto &entry : object_list.at("entries")) {
|
for (const auto &entry : object_list.at("entries")) {
|
||||||
try {
|
try {
|
||||||
auto name = entry.at("name").get<std::string>();
|
auto name{entry.at("name").get<std::string>()};
|
||||||
auto entry_api_path = utils::path::create_api_path(name);
|
auto entry_api_path{utils::path::create_api_path(name)};
|
||||||
if (utils::string::ends_with(name, "/") &&
|
if (utils::string::ends_with(name, "/") &&
|
||||||
(entry_api_path == api_path)) {
|
(entry_api_path == api_path)) {
|
||||||
continue;
|
continue;
|
||||||
@ -148,10 +148,10 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
|
|||||||
if (object_list.contains("entries")) {
|
if (object_list.contains("entries")) {
|
||||||
for (const auto &entry : object_list.at("entries")) {
|
for (const auto &entry : object_list.at("entries")) {
|
||||||
try {
|
try {
|
||||||
auto name = entry.at("name").get<std::string>();
|
auto name{entry.at("name").get<std::string>()};
|
||||||
auto entry_api_path = utils::path::create_api_path(name);
|
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)) {
|
if (directory && (entry_api_path == api_path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
|
|||||||
: entry["size"].get<std::uint64_t>(),
|
: entry["size"].get<std::uint64_t>(),
|
||||||
get_last_modified(entry));
|
get_last_modified(entry));
|
||||||
get_api_item_added()(directory, file);
|
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) {
|
if (res != api_error::success) {
|
||||||
utils::error::raise_api_path_error(function_name, entry_api_path,
|
utils::error::raise_api_path_error(function_name, entry_api_path,
|
||||||
res, "failed to get item meta");
|
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 {
|
try {
|
||||||
json file_data{};
|
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) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto slabs = file_data["object"]["Slabs"];
|
auto slabs{file_data["object"]["Slabs"]};
|
||||||
auto size = std::accumulate(
|
auto size{
|
||||||
slabs.begin(), slabs.end(), std::uint64_t(0U),
|
std::accumulate(
|
||||||
[](std::uint64_t total_size,
|
slabs.begin(), slabs.end(), std::uint64_t(0U),
|
||||||
const nlohmann::json &slab) -> std::uint64_t {
|
[](std::uint64_t total_size, auto &&slab) -> std::uint64_t {
|
||||||
return total_size + slab["Length"].get<std::uint64_t>();
|
return total_size + slab["Length"].get<std::uint64_t>();
|
||||||
});
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
api_meta_map meta{};
|
api_meta_map meta{};
|
||||||
if (get_item_meta(api_path, meta) == api_error::item_not_found) {
|
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")) {
|
if (object_list.contains("entries")) {
|
||||||
for (const auto &entry : object_list.at("entries")) {
|
for (const auto &entry : object_list.at("entries")) {
|
||||||
auto name = entry.at("name").get<std::string>();
|
auto name{entry.at("name").get<std::string>()};
|
||||||
auto entry_api_path = utils::path::create_api_path(name);
|
auto entry_api_path{utils::path::create_api_path(name)};
|
||||||
|
|
||||||
if (utils::string::ends_with(name, "/")) {
|
if (utils::string::ends_with(name, "/")) {
|
||||||
if (entry_api_path == utils::path::create_api_path(api_path)) {
|
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{};
|
api_meta_map meta{};
|
||||||
if (get_item_meta(entry_api_path, meta) ==
|
if (get_item_meta(entry_api_path, meta) ==
|
||||||
api_error::item_not_found) {
|
api_error::item_not_found) {
|
||||||
auto dir = create_api_file(entry_api_path, "", 0U,
|
auto dir{
|
||||||
get_last_modified(entry));
|
create_api_file(entry_api_path, "", 0U,
|
||||||
|
get_last_modified(entry)),
|
||||||
|
};
|
||||||
get_api_item_added()(true, dir);
|
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) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -480,7 +483,7 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
json file_data{};
|
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) {
|
if (res == api_error::item_not_found) {
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user