- Add docker/podman-compose.yml for Immich server (no ML) - Add test-data/sample-photos/ with 3 public domain images - Add scripts/start-immich.sh for container startup + admin/API key creation - Add scripts/seed-data.sh for uploading test photos and creating albums - Add scripts/stop-immich.sh for cleanup with volume destruction - Add scripts/run-example.sh wrapper (fixed env var export) - Update examples to use IMMICH_URL and IMMICH_API_KEY env vars - Add .github/workflows/integration-test.yml for CI - Update assets.list() to use /search/metadata endpoint - Update AGENTS.md with example running instructions - Add 5 new examples: search_metadata, album_management, timeline_browsing, delete_assets, server_info
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
//! Example: Download an asset from Immich
|
|
//!
|
|
//! This example uses environment variables for configuration:
|
|
//! - IMMICH_URL: The Immich server URL (defaults to http://localhost:2283)
|
|
//! - IMMICH_API_KEY: Your API key (required)
|
|
|
|
use immich_sdk::Client;
|
|
use std::fs;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Configure the client from environment variables
|
|
let url = std::env::var("IMMICH_URL").unwrap_or_else(|_| "http://localhost:2283".to_string());
|
|
let api_key =
|
|
std::env::var("IMMICH_API_KEY").expect("IMMICH_API_KEY environment variable not set");
|
|
|
|
// Create a client
|
|
let client = Client::from_url(&url)?.with_api_key(api_key);
|
|
|
|
// Get first asset from the server
|
|
let assets = client.assets().list().execute().await?;
|
|
if assets.is_empty() {
|
|
println!("No assets found. Run upload_photos example first.");
|
|
return Ok(());
|
|
}
|
|
let asset_id = assets[0].id;
|
|
|
|
// Download the asset
|
|
println!("Downloading asset...");
|
|
let bytes = client.assets().download(asset_id).execute().await?;
|
|
|
|
// Save to file
|
|
let output_path = "/path/to/output/photo.jpg";
|
|
fs::write(output_path, &bytes)?;
|
|
println!("Saved {} bytes to {}", bytes.len(), output_path);
|
|
|
|
// Or download the edited version if available
|
|
let edited_bytes = client
|
|
.assets()
|
|
.download(asset_id)
|
|
.edited()
|
|
.execute()
|
|
.await?;
|
|
|
|
let edited_path = "/path/to/output/photo_edited.jpg";
|
|
fs::write(edited_path, &edited_bytes)?;
|
|
println!(
|
|
"Saved edited version {} bytes to {}",
|
|
edited_bytes.len(),
|
|
edited_path
|
|
);
|
|
|
|
Ok(())
|
|
}
|