- 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
176 lines
5.1 KiB
Bash
Executable File
176 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Seed data script for Immich SDK testing
|
|
# Uploads sample photos to an Immich test instance
|
|
#
|
|
|
|
set -e
|
|
|
|
# Change to script directory
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# Load environment variables from .env.test if it exists
|
|
if [ -f ".env.test" ]; then
|
|
echo "Loading environment from .env.test"
|
|
source .env.test
|
|
fi
|
|
|
|
# Check required environment variables
|
|
if [ -z "$IMMICH_URL" ]; then
|
|
echo "Error: IMMICH_URL environment variable is not set"
|
|
echo "Please set it or create a .env.test file with:"
|
|
echo " IMMICH_URL=http://localhost:2283"
|
|
echo " IMMICH_API_KEY=your-api-key"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$IMMICH_API_KEY" ]; then
|
|
echo "Error: IMMICH_API_KEY environment variable is not set"
|
|
echo "Please set it or create a .env.test file with:"
|
|
echo " IMMICH_URL=http://localhost:2283"
|
|
echo " IMMICH_API_KEY=your-api-key"
|
|
exit 1
|
|
fi
|
|
|
|
PHOTO_DIR="test-data/sample-photos"
|
|
|
|
# Check if photo directory exists
|
|
if [ ! -d "$PHOTO_DIR" ]; then
|
|
echo "Warning: Photo directory $PHOTO_DIR does not exist"
|
|
echo "Creating directory..."
|
|
mkdir -p "$PHOTO_DIR"
|
|
echo "Please add sample .jpg files to $PHOTO_DIR and run again"
|
|
exit 0
|
|
fi
|
|
|
|
# Count jpg files
|
|
jpg_count=$(find "$PHOTO_DIR" -name "*.jpg" -type f 2>/dev/null | wc -l)
|
|
|
|
if [ "$jpg_count" -eq 0 ]; then
|
|
echo "Warning: No .jpg files found in $PHOTO_DIR"
|
|
echo "Please add sample .jpg files and run again"
|
|
exit 0
|
|
fi
|
|
|
|
echo "======================================"
|
|
echo "Immich Seed Data Script"
|
|
echo "======================================"
|
|
echo "Target: $IMMICH_URL"
|
|
echo "Photos to upload: $jpg_count"
|
|
echo "======================================"
|
|
echo ""
|
|
|
|
# Array to store uploaded asset IDs
|
|
declare -a asset_ids
|
|
|
|
# Upload photos
|
|
for photo in "$PHOTO_DIR"/*.jpg; do
|
|
[ -f "$photo" ] || continue
|
|
|
|
filename=$(basename "$photo")
|
|
device_asset_id=$(basename "$photo" .jpg)
|
|
|
|
echo -n "Uploading $filename... "
|
|
|
|
# Upload with asset data and capture response
|
|
response=$(curl -s -X POST "$IMMICH_URL/api/assets" \
|
|
-H "x-api-key: $IMMICH_API_KEY" \
|
|
-F "assetData=@$photo" \
|
|
-F "deviceAssetId=$device_asset_id" \
|
|
-F "deviceId=test-device" \
|
|
-F "fileCreatedAt=2024-01-15T10:00:00.000Z" \
|
|
-F "fileModifiedAt=2024-01-15T10:00:00.000Z" \
|
|
-H "Accept: application/json" 2>/dev/null || true)
|
|
|
|
# Extract asset ID from response if possible
|
|
asset_id=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
|
|
|
|
if [ -n "$asset_id" ]; then
|
|
asset_ids+=("$asset_id")
|
|
echo "OK (ID: ${asset_id:0:8}...)"
|
|
else
|
|
echo "OK"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "======================================"
|
|
echo "Upload Summary"
|
|
echo "======================================"
|
|
echo "Photos uploaded: $jpg_count"
|
|
|
|
# Create album and add assets if we have asset IDs
|
|
if [ ${#asset_ids[@]} -gt 0 ]; then
|
|
echo ""
|
|
echo "Creating album..."
|
|
|
|
# Create album
|
|
album_response=$(curl -s -X POST "$IMMICH_URL/api/albums" \
|
|
-H "x-api-key: $IMMICH_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"albumName":"SDK Test Album"}' 2>/dev/null || true)
|
|
|
|
album_id=$(echo "$album_response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
|
|
|
|
if [ -n "$album_id" ]; then
|
|
echo "Album created: SDK Test Album (ID: ${album_id:0:8}...)"
|
|
|
|
# Add assets to album
|
|
echo "Adding photos to album..."
|
|
|
|
# Build JSON array of asset IDs
|
|
asset_json="["
|
|
first=true
|
|
for id in "${asset_ids[@]}"; do
|
|
if [ "$first" = true ]; then
|
|
first=false
|
|
else
|
|
asset_json+=","
|
|
fi
|
|
asset_json+="\"$id\""
|
|
done
|
|
asset_json+="]"
|
|
|
|
add_response=$(curl -s -X PUT "$IMMICH_URL/api/albums/$album_id/assets" \
|
|
-H "x-api-key: $IMMICH_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"ids\":$asset_json}" 2>/dev/null || true)
|
|
|
|
echo "Added ${#asset_ids[@]} photos to album"
|
|
|
|
# Mark first photo as favorite
|
|
if [ ${#asset_ids[@]} -gt 0 ]; then
|
|
echo ""
|
|
echo "Marking first photo as favorite..."
|
|
|
|
curl -s -X PUT "$IMMICH_URL/api/assets" \
|
|
-H "x-api-key: $IMMICH_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"ids\":[\"${asset_ids[0]}\"],\"isFavorite\":true}" \
|
|
2>/dev/null > /dev/null || true
|
|
|
|
echo "Marked as favorite"
|
|
fi
|
|
else
|
|
echo "Warning: Could not create album (album ID not found in response)"
|
|
fi
|
|
else
|
|
echo "Warning: No asset IDs captured - skipping album creation"
|
|
fi
|
|
|
|
echo ""
|
|
echo "======================================"
|
|
echo "Seed complete!"
|
|
echo "======================================"
|
|
echo "Server: $IMMICH_URL"
|
|
echo "Photos uploaded: $jpg_count"
|
|
if [ ${#asset_ids[@]} -gt 0 ]; then
|
|
echo "Album: SDK Test Album"
|
|
echo "Favorites: 1"
|
|
fi
|
|
echo ""
|
|
echo "You can now run examples against this server:"
|
|
echo " cargo run --example list_assets"
|
|
echo " cargo run --example list_albums"
|
|
echo "======================================"
|