mirror of
git://f0xx.org/android_cast
synced 2026-07-29 06:58:51 +03:00
BE sync
This commit is contained in:
15
backend/url-shortener/scripts/purge_url_shortener.php
Executable file
15
backend/url-shortener/scripts/purge_url_shortener.php
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once dirname(__DIR__) . '/src/bootstrap.php';
|
||||
|
||||
$pdo = Database::pdo();
|
||||
$deletedLinks = $pdo->exec(
|
||||
'DELETE FROM links WHERE expires_at IS NOT NULL AND expires_at < NOW()'
|
||||
);
|
||||
$deletedAudit = $pdo->exec(
|
||||
'DELETE FROM audit_log WHERE created_at < (NOW() - INTERVAL 90 DAY)'
|
||||
);
|
||||
|
||||
echo "purge: links=$deletedLinks audit=$deletedAudit\n";
|
||||
5
backend/url-shortener/scripts/run-php-tests.sh
Executable file
5
backend/url-shortener/scripts/run-php-tests.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# PHP unit-style checks (no phpunit required).
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
php "$ROOT/tests/run_tests.php"
|
||||
26
backend/url-shortener/scripts/seed_bearer.php
Executable file
26
backend/url-shortener/scripts/seed_bearer.php
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once dirname(__DIR__) . '/src/bootstrap.php';
|
||||
|
||||
$label = 'cli-seed';
|
||||
$canPermanent = false;
|
||||
foreach (array_slice($argv, 1) as $arg) {
|
||||
if ($arg === '--permanent') {
|
||||
$canPermanent = true;
|
||||
} elseif (str_starts_with($arg, '--label=')) {
|
||||
$label = substr($arg, 8);
|
||||
}
|
||||
}
|
||||
|
||||
$created = BearerRepository::createTrusted($label, true, $canPermanent);
|
||||
echo "Bearer token (store securely — shown once):\n";
|
||||
echo $created['token'] . "\n";
|
||||
echo "bearer_id=" . $created['id'] . " label=" . $label . "\n";
|
||||
|
||||
if ($canPermanent) {
|
||||
$signer = SignerRepository::create($label . '-signer');
|
||||
echo "Signer key (for ttl=0):\n";
|
||||
echo $signer['key'] . "\n";
|
||||
}
|
||||
@@ -6,14 +6,8 @@ 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
|
||||
body="$(curl -fsS "$BASE/api/v1/health")"
|
||||
echo "$body" | grep -q '"status":"ok"' || { echo "health not ok: $body"; exit 1; }
|
||||
|
||||
if [[ -z "$BEARER" ]]; then
|
||||
echo "SKIP shorten (set BEARER to run full smoke)"
|
||||
@@ -21,9 +15,14 @@ if [[ -z "$BEARER" ]]; then
|
||||
fi
|
||||
|
||||
echo "==> shorten POST"
|
||||
curl -fsS -X POST "$BASE/api/v1/shorten" \
|
||||
resp="$(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
|
||||
-d '{"url":"https://example.com/smoke-'"$(date +%s)"'","bearer":"'"$BEARER"'","ttl":300}')"
|
||||
echo "$resp"
|
||||
short="$(echo "$resp" | sed -n 's/.*"u":"\([^"]*\)".*/\1/p')"
|
||||
[[ -n "$short" ]] || { echo "no short url in response"; exit 1; }
|
||||
|
||||
echo "==> redirect HEAD"
|
||||
curl -fsSI "$short" | grep -qi '^location:' || { echo "missing redirect"; exit 1; }
|
||||
|
||||
echo "OK"
|
||||
|
||||
Reference in New Issue
Block a user