#!/usr/bin/env bash
# ProSolutionX CDN — every endpoint as a copy-pasteable command.
#
#   export CDN_API_KEY="cdn_yoursite_..."
#   ./cdn-examples.sh

set -euo pipefail
BASE="https://cdn.prosolutionx.com"
: "${CDN_API_KEY:?Set CDN_API_KEY first}"
AUTH=(-H "Authorization: Bearer $CDN_API_KEY")

echo "— check the key —"
curl -s "${AUTH[@]}" "$BASE/api/v1/me"; echo

echo "— upload (slug is optional; the filename is used when omitted) —"
curl -s -X POST "${AUTH[@]}" \
  -F "file=@photo.jpg" \
  -F "slug=blue-widget-hero" \
  -F "alt=Blue widget on a white background" \
  "$BASE/api/v1/assets"; echo

echo "— list, newest first —"
curl -s "${AUTH[@]}" "$BASE/api/v1/assets?limit=10"; echo

echo "— search —"
curl -s "${AUTH[@]}" "$BASE/api/v1/assets?q=widget"; echo

echo "— fetch one, by id or by name —"
curl -s "${AUTH[@]}" "$BASE/api/v1/assets/blue-widget-hero"; echo

echo "— rename (the readable URL changes with it) —"
curl -s -X PATCH "${AUTH[@]}" \
  -H "Content-Type: application/json" \
  -d '{"slug":"blue-widget-hero-2026","alt":"Updated caption"}' \
  "$BASE/api/v1/assets/blue-widget-hero"; echo

echo "— replace the file, keep the name —"
curl -s -X PUT "${AUTH[@]}" \
  -F "file=@photo-v2.jpg" \
  "$BASE/api/v1/assets/blue-widget-hero-2026"; echo

echo "— delete —"
curl -s -X DELETE "${AUTH[@]}" "$BASE/api/v1/assets/blue-widget-hero-2026"; echo

# Delivery needs no key:
#   $BASE/<site>/blue-widget-hero.jpg
#   $BASE/<site>/blue-widget-hero.jpg?w=800&f=webp&q=80
