mirror of
git://f0xx.org/android_cast
synced 2026-07-29 05:17:39 +03:00
url shortener addons
This commit is contained in:
55
backend/url-shortener/scripts/demo_curl.sh
Executable file
55
backend/url-shortener/scripts/demo_curl.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-to-end curl cookbook — SPEC appendix A.
|
||||
# Usage:
|
||||
# export BASE=https://s.f0xx.org
|
||||
# export BEARER=your-trusted-token
|
||||
# export SIGNER=optional-for-ttl0
|
||||
# ./scripts/demo_curl.sh
|
||||
set -euo pipefail
|
||||
|
||||
BASE="${BASE:-https://s.f0xx.org}"
|
||||
BEARER="${BEARER:?set BEARER to a trusted API token}"
|
||||
SIGNER="${SIGNER:-}"
|
||||
TARGET="${TARGET:-https://defender.net/very/long/link?demo=1}"
|
||||
TTL="${TTL:-3600}"
|
||||
|
||||
echo "==> 1) Health"
|
||||
curl -fsS "$BASE/api/v1/health" | head -c 200
|
||||
echo
|
||||
|
||||
echo "==> 2) Shorten (POST preferred)"
|
||||
SHORT_JSON="$(curl -fsS -X POST "$BASE/api/v1/shorten" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$(jq -nc --arg url "$TARGET" --arg bearer "$BEARER" --argjson ttl "$TTL" \
|
||||
'{url:$url,bearer:$bearer,ttl:$ttl}')")"
|
||||
echo "$SHORT_JSON" | jq .
|
||||
|
||||
SHORT="$(echo "$SHORT_JSON" | jq -r '.u // empty')"
|
||||
if [[ -z "$SHORT" ]]; then
|
||||
echo "shorten failed (no .u in response)" >&2
|
||||
exit 1
|
||||
fi
|
||||
SLUG="${SHORT##*/}"
|
||||
|
||||
echo "==> 3) Shorten cache hit (same bearer + url)"
|
||||
curl -fsS -X POST "$BASE/api/v1/shorten" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$(jq -nc --arg url "$TARGET" --arg bearer "$BEARER" --argjson ttl "$TTL" \
|
||||
'{url:$url,bearer:$bearer,ttl:$ttl}')" | jq .
|
||||
|
||||
echo "==> 4) Redirect (HEAD — no body)"
|
||||
curl -sSI "$SHORT" | grep -E '^(HTTP|Location:)'
|
||||
|
||||
echo "==> 5) QR PNG"
|
||||
curl -fsS -o "/tmp/url-shortener-qr-${SLUG}.png" "$BASE/api/v1/qr/${SLUG}.png?size=256"
|
||||
file "/tmp/url-shortener-qr-${SLUG}.png"
|
||||
|
||||
if [[ -n "$SIGNER" ]]; then
|
||||
echo "==> 6) Permanent link (ttl=0, signer required)"
|
||||
curl -fsS -X POST "$BASE/api/v1/shorten" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$(jq -nc --arg url "$TARGET&perm=1" --arg bearer "$BEARER" --arg signer "$SIGNER" \
|
||||
'{url:$url,bearer:$bearer,signer:$signer,ttl:0}')" | jq .
|
||||
fi
|
||||
|
||||
echo "==> Done"
|
||||
29
backend/url-shortener/scripts/smoke_shorten.sh
Executable file
29
backend/url-shortener/scripts/smoke_shorten.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# Minimal deploy smoke — exits non-zero on failure.
|
||||
set -euo pipefail
|
||||
|
||||
BASE="${BASE:-https://s.f0xx.org}"
|
||||
BEARER="${BEARER:-}"
|
||||
|
||||
echo "==> health $BASE/api/v1/health"
|
||||
code="$(curl -sS -o /tmp/url-shortener-health.json -w '%{http_code}' "$BASE/api/v1/health" || true)"
|
||||
if [[ "$code" != "200" ]]; then
|
||||
echo "FAIL health HTTP $code" >&2
|
||||
cat /tmp/url-shortener-health.json 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
cat /tmp/url-shortener-health.json
|
||||
echo
|
||||
|
||||
if [[ -z "$BEARER" ]]; then
|
||||
echo "SKIP shorten (set BEARER to run full smoke)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "==> shorten POST"
|
||||
curl -fsS -X POST "$BASE/api/v1/shorten" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"url":"https://example.com/smoke","bearer":"'"$BEARER"'","ttl":300}' \
|
||||
| jq -e '.code == "0" and (.u | length) > 0' >/dev/null
|
||||
|
||||
echo "OK"
|
||||
Reference in New Issue
Block a user