修复token缺失bug

This commit is contained in:
2026-06-01 13:40:17 +08:00
parent 1e032637de
commit 13ddc66cfe
6 changed files with 123 additions and 2 deletions

View File

@@ -18,12 +18,30 @@ else
exit 1
fi
if [ ! -f .env.local ]; then
if command -v node >/dev/null 2>&1; then
node scripts/ensure-deploy-env.mjs "$ROOT_DIR"
elif [ ! -f .env.local ]; then
cp .env.example .env.local
echo "[deploy] Created .env.local from .env.example"
echo "[deploy] Real generation requires API keys in .env.local. Empty keys keep mock/local flows available."
fi
if ! grep -q '^ZHINIAN_INTERNAL_WORKER_TOKEN=' .env.local || grep -q '^ZHINIAN_INTERNAL_WORKER_TOKEN=$\|^ZHINIAN_INTERNAL_WORKER_TOKEN=change-me-worker-token$' .env.local; then
if command -v openssl >/dev/null 2>&1; then
WORKER_TOKEN="$(openssl rand -hex 32)"
if grep -q '^ZHINIAN_INTERNAL_WORKER_TOKEN=' .env.local; then
sed -i.bak "s/^ZHINIAN_INTERNAL_WORKER_TOKEN=.*/ZHINIAN_INTERNAL_WORKER_TOKEN=${WORKER_TOKEN}/" .env.local
rm -f .env.local.bak
else
printf '\nZHINIAN_INTERNAL_WORKER_TOKEN=%s\n' "$WORKER_TOKEN" >> .env.local
fi
echo "[deploy] Added ZHINIAN_INTERNAL_WORKER_TOKEN to .env.local"
else
echo "[deploy] ZHINIAN_INTERNAL_WORKER_TOKEN is required in .env.local, and openssl was not found to generate one."
exit 1
fi
fi
mkdir -p .runtime/data .runtime/uploads .runtime/generated-results
if [ -z "${APP_PORT:-}" ] && [ -f .env.local ]; then