#!/bin/sh # Requires curl. ACTION=me|search|download|image; downloads print the JSON response. set -eu : "${MOTIONGIT_API_KEY:?Set MOTIONGIT_API_KEY}" base=${MOTIONGIT_BASE_URL:-http://127.0.0.1:8095} base=${base%/} case ${ACTION:-me} in me) curl -sS --fail-with-body -H "Authorization: Bearer $MOTIONGIT_API_KEY" "$base/api/v1/me" ;; search) curl -sS --fail-with-body -G -H "Authorization: Bearer $MOTIONGIT_API_KEY" --data-urlencode "q=${QUERY:-增长}" --data-urlencode 'limit=5' "$base/api/v1/stickers/search" ;; download) curl -sS --fail-with-body -H "Authorization: Bearer $MOTIONGIT_API_KEY" "$base/api/v1/stickers/${PRESET:-growth}" ;; image) curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $MOTIONGIT_API_KEY" -H 'Content-Type: application/json' -d '{"prompt":"清晨城市天际线","size":"1536x1024"}' "$base/api/v1/images" ;; *) echo 'Unknown ACTION' >&2; exit 1 ;; esac