use ngdp_cache::cached_cdn_client::CachedCdnClient;
use tracing::{Level, info};
use tracing_subscriber::FmtSubscriber;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
tracing::subscriber::set_global_default(subscriber)?;
info!("=== CDN Helper Methods Example ===\n");
let client = CachedCdnClient::new().await?;
let cdn_host = "blzddist1-a.akamaihd.net";
let path = "tpr/wow"; let config_path = "tpr/configs/data";
let build_config_hash = "e359107662e72559b4e1ab721b157cb0";
let cdn_config_hash = "48c7c7dfe4ea7df9dac22f6937ecbf47";
let product_config_hash = "53020d32e1a25648c8e1eafd5771935f";
let key_ring_hash = "3ca57fe7319a297346440e4d2a03a0cd";
let data_hash = "1234567890abcdef1234567890abcdef";
let patch_hash = "fedcba9876543210fedcba9876543210";
info!("Demonstrating different download methods:\n");
info!("1. BuildConfig (stored at {}/config):", path);
match client
.download_build_config(cdn_host, path, build_config_hash)
.await
{
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {}", e);
}
}
info!("\n2. CDNConfig (stored at {}/config):", path);
match client
.download_cdn_config(cdn_host, path, cdn_config_hash)
.await
{
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {}", e);
}
}
info!("\n3. ProductConfig (stored at {}):", config_path);
match client
.download_product_config(cdn_host, config_path, product_config_hash)
.await
{
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {}", e);
}
}
info!("\n4. KeyRing (stored at {}/config):", path);
match client
.download_key_ring(cdn_host, path, key_ring_hash)
.await
{
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {}", e);
}
}
info!("\n5. Data file (stored at {}/data):", path);
match client.download_data(cdn_host, path, data_hash).await {
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {} (example hash may not exist)", e);
}
}
info!("\n6. Patch file (stored at {}/patch):", path);
match client.download_patch(cdn_host, path, patch_hash).await {
Ok(response) => {
let is_cached = response.is_from_cache();
let data = response.bytes().await?;
info!(
" ✓ Downloaded {} bytes (cached: {})",
data.len(),
is_cached
);
}
Err(e) => {
info!(" ✗ Failed: {} (example hash may not exist)", e);
}
}
info!("\n✅ Helper methods make it easy to download the right content type!");
info!(" No need to manually construct paths anymore!");
Ok(())
}