load all items from the bucket
This commit is contained in:
+3
-3
@@ -1,3 +1,3 @@
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "x86_64-unknown-linux-gnu-gcc"
|
||||
ar = "x86_64-unknown-linux-gnu-ar"
|
||||
# [target.x86_64-unknown-linux-gnu]
|
||||
# linker = "x86_64-unknown-linux-gnu-gcc"
|
||||
# ar = "x86_64-unknown-linux-gnu-ar"
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ async fn main() {
|
||||
|
||||
for cloud in clouds {
|
||||
println!("Bucket tartalom listázása: {}", cloud.name);
|
||||
match print_bucket_contents(&cloud, cloud.folder.as_deref()).await {
|
||||
match print_bucket_contents(&cloud).await {
|
||||
Ok(_) => (),
|
||||
Err(e) => eprintln!("Hiba a bucket listázásakor: {}", e),
|
||||
}
|
||||
|
||||
+63
-44
@@ -25,7 +25,7 @@ impl std::fmt::Display for S3Item {
|
||||
|
||||
/// Listázza az S3 bucket tartalmát
|
||||
/// Visszaadja a fájlokat és mappákat megkülönböztetve
|
||||
pub async fn list_bucket(s3: &CloudS3, prefix: Option<&str>) -> Result<Vec<S3Item>, Error> {
|
||||
pub async fn list_bucket(s3: &CloudS3) -> Result<Vec<S3Item>, Error> {
|
||||
// Debug: S3 konfiguráció paraméterek
|
||||
println!("=== S3 Konfiguráció ===");
|
||||
println!("Bucket: {}", s3.bucket);
|
||||
@@ -35,7 +35,7 @@ pub async fn list_bucket(s3: &CloudS3, prefix: Option<&str>) -> Result<Vec<S3Ite
|
||||
"Access Key: {}...",
|
||||
&s3.accesskey.chars().take(8).collect::<String>()
|
||||
);
|
||||
if let Some(p) = prefix {
|
||||
if let Some(p) = &s3.folder {
|
||||
println!("Prefix: {}", p);
|
||||
}
|
||||
|
||||
@@ -52,74 +52,93 @@ pub async fn list_bucket(s3: &CloudS3, prefix: Option<&str>) -> Result<Vec<S3Ite
|
||||
.endpoint_url(&s3.endpoint_url)
|
||||
.behavior_version(BehaviorVersion::latest())
|
||||
.build();
|
||||
|
||||
println!("✓ S3 Config létrehozva (endpoint: {})", s3.endpoint_url);
|
||||
|
||||
let client = Client::from_conf(config);
|
||||
println!("✓ S3 Client létrehozva");
|
||||
|
||||
// Bucket tartalom listázása
|
||||
let mut request = client.list_objects_v2().bucket(&s3.bucket).delimiter("/");
|
||||
|
||||
if let Some(p) = prefix {
|
||||
request = request.prefix(p);
|
||||
}
|
||||
|
||||
println!("=== Request küldése ===");
|
||||
// dbg!(&request);
|
||||
|
||||
let response = request.send().await?;
|
||||
println!("✓ Response megérkezett");
|
||||
println!(
|
||||
"Common prefixes count: {}",
|
||||
response.common_prefixes().len()
|
||||
);
|
||||
println!("Contents count: {}", response.contents().len());
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
||||
// Mappák (CommonPrefixes)
|
||||
for prefix in response.common_prefixes() {
|
||||
if let Some(prefix_str) = prefix.prefix() {
|
||||
items.push(S3Item {
|
||||
key: prefix_str.to_string(),
|
||||
is_folder: true,
|
||||
size: None,
|
||||
last_modified: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut continuation_token: Option<String> = None;
|
||||
|
||||
// Fájlok (Contents)
|
||||
for object in response.contents() {
|
||||
if let Some(key) = object.key() {
|
||||
// Kihagyjuk a mappa neveket (amik '/' karakterrel végződnek)
|
||||
if !key.ends_with('/') {
|
||||
loop {
|
||||
// Bucket tartalom listázása
|
||||
let mut request = client.list_objects_v2().bucket(&s3.bucket);
|
||||
|
||||
if let Some(p) = &s3.folder {
|
||||
request = request.prefix(p);
|
||||
}
|
||||
|
||||
println!("=== Request küldése ===");
|
||||
// dbg!(&request);
|
||||
|
||||
if let Some(token) = &continuation_token {
|
||||
request = request.continuation_token(token);
|
||||
}
|
||||
|
||||
let response = request.send().await?;
|
||||
|
||||
println!("✓ Response megérkezett");
|
||||
println!(
|
||||
"Common prefixes count: {}",
|
||||
response.common_prefixes().len()
|
||||
);
|
||||
|
||||
// Mappák (CommonPrefixes)
|
||||
for prefix in response.common_prefixes() {
|
||||
if let Some(prefix_str) = prefix.prefix() {
|
||||
items.push(S3Item {
|
||||
key: key.to_string(),
|
||||
is_folder: false,
|
||||
size: object.size(),
|
||||
last_modified: object.last_modified().map(|dt| dt.to_string()),
|
||||
key: prefix_str.to_string(),
|
||||
is_folder: true,
|
||||
size: None,
|
||||
last_modified: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fájlok (Contents)
|
||||
for object in response.contents() {
|
||||
if let Some(key) = object.key() {
|
||||
// Kihagyjuk a mappa neveket (amik '/' karakterrel végződnek)
|
||||
if !key.ends_with('/') {
|
||||
items.push(S3Item {
|
||||
key: key.to_string(),
|
||||
is_folder: false,
|
||||
size: object.size(),
|
||||
last_modified: object.last_modified().map(|dt| dt.to_string()),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(next_token) = response.next_continuation_token() {
|
||||
continuation_token = Some(next_token.to_string());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
println!("Contents count: {}", items.len());
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
/// Egyszerű listázó függvény, ami kiírja a tartalmat
|
||||
pub async fn print_bucket_contents(s3: &CloudS3, prefix: Option<&str>) -> Result<(), Error> {
|
||||
let items = list_bucket(s3, prefix).await?;
|
||||
pub async fn print_bucket_contents(s3: &CloudS3) -> Result<(), Error> {
|
||||
let items = list_bucket(s3).await?;
|
||||
|
||||
println!("Bucket tartalom: {}", s3.bucket);
|
||||
if let Some(p) = prefix {
|
||||
if let Some(p) = &s3.folder {
|
||||
println!("Prefix: {}", p);
|
||||
}
|
||||
println!("{}", "-".repeat(60));
|
||||
|
||||
for item in items {
|
||||
for item in &items {
|
||||
println!("{}", item);
|
||||
}
|
||||
|
||||
println!("Contents count: {}", items.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user