#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." source .env : "${ZLAY_ADMIN_PASSWORD:?set ZLAY_ADMIN_PASSWORD}" : "${ZLAY_DOMAIN:=zlay.waow.tech}" ACTION="${1:-status}" case "$ACTION" in start) SOURCE="${2:-bsky.network}" curl -sf -X POST \ -H "Authorization: Bearer $ZLAY_ADMIN_PASSWORD" \ "https://$ZLAY_DOMAIN/admin/backfill-collections?source=$SOURCE" | jq . ;; status) curl -sf --max-time 30 \ -H "Authorization: Bearer $ZLAY_ADMIN_PASSWORD" \ "https://$ZLAY_DOMAIN/admin/backfill-collections" | jq '{ running, total, completed, in_progress, total_imported, recent: [.collections[] | select(.completed == false)] | .[0:5] }' ;; full) curl -sf --max-time 30 \ -H "Authorization: Bearer $ZLAY_ADMIN_PASSWORD" \ "https://$ZLAY_DOMAIN/admin/backfill-collections" | jq . ;; *) echo "usage: $0 [status|start [source]|full]" exit 1 ;; esac