refactor
This commit is contained in:
		| @@ -417,25 +417,27 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path, | |||||||
|     for (auto &&node : node_list) { |     for (auto &&node : node_list) { | ||||||
|       auto child_object_name = utils::path::create_api_path( |       auto child_object_name = utils::path::create_api_path( | ||||||
|           node.node().select_node("Key").node().text().as_string()); |           node.node().select_node("Key").node().text().as_string()); | ||||||
|       if (child_object_name != utils::path::create_api_path(prefix)) { |       if (child_object_name == utils::path::create_api_path(prefix)) { | ||||||
|         auto size = node.node().select_node("Size").node().text().as_ullong(); |         continue; | ||||||
|         auto last_modified = convert_api_date( |  | ||||||
|             node.node().select_node("LastModified").node().text().as_string()); |  | ||||||
|         add_directory_item( |  | ||||||
|             false, child_object_name, last_modified, |  | ||||||
|             [this, &is_encrypted, |  | ||||||
|              &size](const directory_item &dir_item) -> std::uint64_t { |  | ||||||
|               std::string size_str; |  | ||||||
|               if (get_item_meta(dir_item.api_path, META_SIZE, size_str) == |  | ||||||
|                   api_error::success) { |  | ||||||
|                 return utils::string::to_uint64(size_str); |  | ||||||
|               } |  | ||||||
|  |  | ||||||
|               return is_encrypted ? utils::encryption::encrypting_reader:: |  | ||||||
|                                         calculate_decrypted_size(size) |  | ||||||
|                                   : size; |  | ||||||
|             }); |  | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |       auto size = node.node().select_node("Size").node().text().as_ullong(); | ||||||
|  |       auto last_modified = convert_api_date( | ||||||
|  |           node.node().select_node("LastModified").node().text().as_string()); | ||||||
|  |       add_directory_item(false, child_object_name, last_modified, | ||||||
|  |                          [this, &is_encrypted, &size]( | ||||||
|  |                              const directory_item &dir_item) -> std::uint64_t { | ||||||
|  |                            std::string size_str; | ||||||
|  |                            if (get_item_meta(dir_item.api_path, META_SIZE, | ||||||
|  |                                              size_str) == api_error::success) { | ||||||
|  |                              return utils::string::to_uint64(size_str); | ||||||
|  |                            } | ||||||
|  |  | ||||||
|  |                            return is_encrypted | ||||||
|  |                                       ? utils::encryption::encrypting_reader:: | ||||||
|  |                                             calculate_decrypted_size(size) | ||||||
|  |                                       : size; | ||||||
|  |                          }); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -521,40 +523,39 @@ auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const | |||||||
|   for (auto &&node : node_list) { |   for (auto &&node : node_list) { | ||||||
|     auto api_path = |     auto api_path = | ||||||
|         std::string{node.node().select_node("Key").node().text().as_string()}; |         std::string{node.node().select_node("Key").node().text().as_string()}; | ||||||
|     if (not utils::string::ends_with(api_path, "/")) { |     if (utils::string::ends_with(api_path, "/")) { | ||||||
|       auto is_encrypted = |       continue; | ||||||
|           not get_config().get_s3_config().encryption_token.empty(); |     } | ||||||
|       if (is_encrypted) { |  | ||||||
|         auto err = decrypt_object_name(api_path); |  | ||||||
|         if (err != api_error::success) { |  | ||||||
|           return err; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       auto size = node.node().select_node("Size").node().text().as_ullong(); |     auto is_encrypted = | ||||||
|  |         not get_config().get_s3_config().encryption_token.empty(); | ||||||
|       api_file file{}; |     if (is_encrypted) { | ||||||
|       file.api_path = utils::path::create_api_path(api_path); |       auto err = decrypt_object_name(api_path); | ||||||
|       file.api_parent = utils::path::get_parent_api_path(file.api_path); |  | ||||||
|       file.accessed_date = file.changed_date = file.creation_date = |  | ||||||
|           file.modified_date = convert_api_date(node.node() |  | ||||||
|                                                     .select_node("LastModified") |  | ||||||
|                                                     .node() |  | ||||||
|                                                     .text() |  | ||||||
|                                                     .as_string()); |  | ||||||
|       file.file_size = |  | ||||||
|           is_encrypted |  | ||||||
|               ? utils::encryption::encrypting_reader::calculate_decrypted_size( |  | ||||||
|                     size) |  | ||||||
|               : size; |  | ||||||
|       file.key = is_encrypted ? utils::path::create_api_path(api_path) : ""; |  | ||||||
|       auto err = add_if_not_found(file, api_path); |  | ||||||
|       if (err != api_error::success) { |       if (err != api_error::success) { | ||||||
|         return err; |         return err; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       list.push_back(std::move(file)); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     auto size = node.node().select_node("Size").node().text().as_ullong(); | ||||||
|  |  | ||||||
|  |     api_file file{}; | ||||||
|  |     file.api_path = utils::path::create_api_path(api_path); | ||||||
|  |     file.api_parent = utils::path::get_parent_api_path(file.api_path); | ||||||
|  |     file.accessed_date = file.changed_date = file.creation_date = | ||||||
|  |         file.modified_date = convert_api_date( | ||||||
|  |             node.node().select_node("LastModified").node().text().as_string()); | ||||||
|  |     file.file_size = | ||||||
|  |         is_encrypted | ||||||
|  |             ? utils::encryption::encrypting_reader::calculate_decrypted_size( | ||||||
|  |                   size) | ||||||
|  |             : size; | ||||||
|  |     file.key = is_encrypted ? utils::path::create_api_path(api_path) : ""; | ||||||
|  |     auto err = add_if_not_found(file, api_path); | ||||||
|  |     if (err != api_error::success) { | ||||||
|  |       return err; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     list.push_back(std::move(file)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return grab_more ? api_error::more_data : api_error::success; |   return grab_more ? api_error::more_data : api_error::success; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user