fix: restore reliable authenticated live recognition

This commit is contained in:
kiyo9w 2026-09-28 12:38:15 +09:00
parent 0e23425ef0
commit 934615b593
40 changed files with 2556 additions and 820 deletions

View file

@ -1,18 +1,16 @@
#!/usr/bin/env bash
# The demo server: one command, bound to the network so a phone can reach it.
# Start the recognition server and write ignored local app endpoints.
#
# ./run-demo-server.sh # both demo shelves enrolled (stock-demo)
# ./run-demo-server.sh
# ./run-demo-server.sh stock-milk150
#
# The iPhone must be on the same Wi-Fi as this Mac, and the app must point at this
# Mac's address - Config.xcconfig's APP_RECOGNITION_BASE_URL, which the app reads at
# build time. The script prints the exact line to use.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$(dirname "$0")"
STOCK="${1:-stock-demo}"
PORT="${PORT:-8099}"
TOKEN_FILE=".demo-token"
if [ ! -d "$STOCK" ]; then
echo "no such store: $STOCK" >&2
@ -25,21 +23,49 @@ if [ -z "$IP" ]; then
exit 1
fi
if [ ! -s "$TOKEN_FILE" ]; then
umask 077
openssl rand -hex 32 > "$TOKEN_FILE"
fi
TOKEN="$(tr -d '[:space:]' < "$TOKEN_FILE")"
umask 077
cat > "$ROOT/iosApp/Configuration/Config.local.xcconfig" <<EOF
APP_RECOGNITION_BASE_URL = http:/\$()/$IP:$PORT
APP_RECOGNITION_API_TOKEN = $TOKEN
EOF
mkdir -p config
cat > config/local.env <<EOF
DORAYAKI_API_TOKEN=$TOKEN
EOF
PROPERTIES="$ROOT/androidApp/local.properties"
touch "$PROPERTIES"
TMP="$(mktemp)"
awk -v url="app.recognitionBaseUrl=http://$IP:$PORT" -v token="app.recognitionApiToken=$TOKEN" '
BEGIN { url_found = 0; token_found = 0 }
$0 ~ /^app\.recognitionBaseUrl=/ { print url; url_found = 1; next }
$0 ~ /^app\.recognitionApiToken=/ { print token; token_found = 1; next }
{ print }
END {
if (!url_found) print url
if (!token_found) print token
}
' "$PROPERTIES" > "$TMP"
mv "$TMP" "$PROPERTIES"
cat <<EOF
Dorayaki demo server
store $STOCK ($(ls "$STOCK" | grep -c -E '\.(jpeg|jpg|png)$') enrolled views)
store $STOCK
listening http://0.0.0.0:$PORT
phone URL http://$IP:$PORT
Put this in iosApp/Configuration/Config.xcconfig and rebuild the app:
APP_RECOGNITION_BASE_URL = http:/\$()/$IP:$PORT
Health check from another device: http://$IP:$PORT/v1/health
Local app configuration was updated. Rebuild both apps.
The API token is in $TOKEN_FILE and is not printed.
EOF
# A phone on the same Wi-Fi reaches 0.0.0.0; localhost-only would not.
exec env YOLO_OFFLINE=1 DORAYAKI_STOCK_DIR="$STOCK" \
exec env YOLO_OFFLINE=1 DORAYAKI_STOCK_DIR="$STOCK" DORAYAKI_API_TOKEN="$TOKEN" \
.venv/bin/python -u code/app.py \
--port "$PORT" --host 0.0.0.0 --identity gallery \
--live-conf 0.25 --classify-workers 8
--live-conf 0.15 --classify-workers 8