use realitydefender::{Client, Config, UploadOptions};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("REALITY_DEFENDER_API_KEY")
.expect("REALITY_DEFENDER_API_KEY environment variable must be set");
let client = Client::new(Config {
api_key,
..Default::default()
})?;
let file_path = "files/test_image.jpg";
println!("Checking if file exists at path: {}", file_path);
if !std::path::Path::new(file_path).exists() {
println!("Warning: File does not exist at path: {}", file_path);
println!("Please provide a valid file path to an existing image or video file.");
return Ok(());
}
println!("Uploading file: {}", file_path);
let upload_result = client
.upload(UploadOptions {
file_path: file_path.to_string(),
})
.await?;
println!(
"Upload successful! Request ID: {}",
upload_result.request_id
);
println!("Waiting for analysis result...");
let result = client
.get_result(
&upload_result.request_id,
Some(realitydefender::GetResultOptions {
max_attempts: Some(30),
polling_interval: Some(2000),
}),
)
.await?;
println!("Analysis complete!");
println!("Status: {}", result.status);
if let Some(score) = result.score {
println!("Score: {:.4} ({:.1}%)", score, score * 100.0);
} else {
println!("No overall score available");
}
if !result.models.is_empty() {
println!("\nModel-specific results:");
for model in result.models {
println!(
"- {}: Status: {}, Score: {}",
model.name,
model.status,
model
.score
.map_or("N/A".to_string(), |s| format!("{:.4}", s))
);
}
}
Ok(())
}