Files
CatoandClaude 88b06e8adc Public pictures straight from R2; the box stops resizing them (#1861)
Public pictures still passed through the app box: storage-api answered
every supabase.orangecat.ch/storage/v1/object/public/... request, and
next/image fetched, resized and cached them there. orangecat-media holds
private files too, so it never gets a public domain; public pictures go
to the separate public bucket fleet-media under orangecat/<bucket>/<path>,
served from MEDIA_PUBLIC_BASE.

- src/lib/media/public-url.ts: the one URL helper. Direct address only
  for objects known to be copied (listing every 10 min + own writes),
  otherwise the Supabase address. Unset base: unchanged.
- New uploads: server-side ones are written to fleet-media as stored;
  browser uploads ask POST /api/media/mirror. Stored URL is the direct one
  or, on any failure, the Supabase one.
- Background copy from instrumentation: idempotent, throttled
  (MEDIA_BACKFILL_KBPS, 512), one process at a time under a lease taken
  with a Postgres advisory lock (new migration). Only buckets declared
  public in code AND marked public in storage.buckets. Removes copies of
  deleted originals after a complete scan, capped at a tenth per run.
- next/image: with the base set at build, a custom loader draws R2
  pictures unoptimized and sends Supabase public pictures to
  /api/media/object, which redirects to R2 once copied, else to the
  optimizer as before.
- Docs: STORAGE_R2_BACKEND.md (how, switch-on, rollback, the pre-move
  disk copy an operator may remove), .env.example; three docs that named
  the removed auto-merge.yml now name the forge merge check.


Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 20:49:44 +01:00

285 lines
15 KiB
Bash

# OrangeCat Environment Variables Template
# Copy this to .env.local and fill in your actual values
# NEVER commit .env.local to git!
# ============================================================================
# SUPABASE (Required for auth, database, storage)
# ============================================================================
# Self-hosted on bitbaum, NOT supabase.com — the managed cloud project was
# retired 2026-06 (see docs/operations/DECOMMISSION-CLOUD.md). There is no
# dashboard to fetch these from: keys live in the box .env, ask before minting.
NEXT_PUBLIC_SUPABASE_URL="https://supabase.orangecat.ch"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-anon-key"
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY="your-publishable-key"
# Server-side only (never expose to browser)
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"
SUPABASE_SERVICE_KEY="your-service-role-key"
SUPABASE_SECRET_KEY="your-secret-key"
SUPABASE_ACCESS_TOKEN="sbp_..."
SUPABASE_JWT_SECRET="your-jwt-secret"
# ============================================================================
# POSTGRES (Required for database connections)
# ============================================================================
# Get from: Supabase Dashboard → Settings → Database
POSTGRES_URL="postgresql://..."
POSTGRES_URL_NON_POOLING="postgresql://..."
POSTGRES_PRISMA_URL="postgresql://..."
POSTGRES_DATABASE="postgres"
POSTGRES_HOST="db.your-project.supabase.co"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="your-db-password"
# ============================================================================
# PUBLIC PICTURES ON R2 (optional; docs/operations/STORAGE_R2_BACKEND.md)
# ============================================================================
# The public media bucket (fleet-media, shared with Solon; OrangeCat writes
# under orangecat/). All five set: pictures of the PUBLIC buckets (avatars,
# banners, project-media, proofs) are copied there and drawn straight from it,
# not through storage-api and the image optimizer on the box. Any one unset:
# everything as before. Never point these at orangecat-media: it also holds
# private files and must never get a public domain.
#
# MEDIA_PUBLIC_BASE is read at BUILD time (next.config.js switches next/image's
# loader on it), so it must be visible where the build runs as well. The
# credentials are read at run time. next.config.js passes the base on to the
# code as NEXT_PUBLIC_MEDIA_PUBLIC_BASE (read by src/lib/media); never set
# that one by hand.
MEDIA_PUBLIC_BASE=""
# NEXT_PUBLIC_MEDIA_PUBLIC_BASE=
PHOTOS_S3_ENDPOINT=""
PHOTOS_S3_BUCKET=""
PHOTOS_S3_ACCESS_KEY_ID=""
PHOTOS_S3_SECRET_ACCESS_KEY=""
# Run time: MEDIA_BACKFILL=0 stops the background copy of older pictures;
# MEDIA_BACKFILL_KBPS is its pace (512).
# MEDIA_BACKFILL="1"
# MEDIA_BACKFILL_KBPS="512"
# ============================================================================
# DEPLOYMENT (self-hosted on Hetzner "bitbaum", behind Caddy)
# ============================================================================
# No Vercel. Production env lives in /opt/orangecat/app/.env on the box.
# See docs/operations/deployment/DEPLOYMENT_PROCESS.md for the on-box flow.
# ============================================================================
# GITHUB (Required for repo integration, PRs, issues)
# ============================================================================
# Get from: gh auth token (after running: gh auth login)
GITHUB_TOKEN="ghp_your_personal_access_token"
# ============================================================================
# APPLICATION (Optional, used for OG metadata and CORS)
# ============================================================================
# NEXT_PUBLIC_APP_URL="https://orangecat.ch"
# NEXT_PUBLIC_SITE_URL="https://orangecat.ch"
# NEXT_PUBLIC_SITE_NAME="OrangeCat"
# ============================================================================
# BITCOIN / LIGHTNING (Required for payments)
# ============================================================================
BITCOIN_NETWORK="testnet"
# OrangeCat's OWN receiving addresses — power the founding-supporter donation on
# /support (rendered as QR + copy). Until set to real values, /support shows a
# graceful "opens shortly" state instead of a placeholder address.
NEXT_PUBLIC_BITCOIN_ADDRESS="bitcoin:bc1q...?message=OrangeCat%20Donation"
NEXT_PUBLIC_LIGHTNING_ADDRESS="your-username@getalby.com"
# NEXT_PUBLIC_LIGHTNING_NODE_URL=""
# LIGHTNING_API_KEY=""
# Payment provider: 'mock' (default) or 'btcpay' (requires BTCPay Server)
# PAYMENT_PROVIDER="mock"
# BTCPay Server integration (required if PAYMENT_PROVIDER="btcpay")
# BTCPAY_URL="https://your-btcpay-instance.example.com"
# BTCPAY_STORE_ID=""
# BTCPAY_API_KEY=""
# Platform receiving wallet for Cat Credits top-ups (NWC connection string).
# This is OrangeCat's OWN wallet, used only to RECEIVE credit purchases — it is
# unrelated to users' (non-custodial) wallets. When unset, Lightning top-up is
# disabled and the rest of Cat Credits is unaffected. NWC is an abstraction, so
# this can point at a hosted wallet now or a self-hosted LNbits/BTCPay node later.
# PLATFORM_NWC_URI="nostr+walletconnect://<pubkey>?relay=...&secret=..."
# Encryption keys (generate with: openssl rand -hex 32)
# API_KEY_ENCRYPTION_SECRET=""
# PAYMENT_ENCRYPTION_KEY=""
# ============================================================================
# OAUTH PROVIDERS (Optional, social login)
# ============================================================================
# OAuth client IDs and secrets are configured in the Supabase Dashboard:
# Supabase Dashboard > Authentication > Providers
# No env vars needed here — all OAuth config lives in the Supabase dashboard.
# Callback URL to configure for each provider: https://your-domain.com/auth/callback
# Supported providers: Google, GitHub, Apple, X/Twitter
# ============================================================================
# CLOUDFLARE TURNSTILE (Optional, bot protection)
# ============================================================================
# Get from: https://dash.cloudflare.com → Turnstile
# NEXT_PUBLIC_TURNSTILE_SITE_KEY=""
# TURNSTILE_SECRET_KEY=""
# ============================================================================
# AI / OPENROUTER (Optional for platform-level AI)
# ============================================================================
# Get from: https://openrouter.ai/keys
# If not set, AI chat will only work when users bring their own key (BYOK mode)
# If set, provides platform-level access to Llama 4 Maverick and other models
# OPENROUTER_API_KEY="sk-or-..."
# GEMINI_API_KEY=""
# GROQ_API_KEY=""
# ============================================================================
# ANALYTICS (Optional)
# ============================================================================
# Provider: 'ga' (Google Analytics), 'mixpanel', 'amplitude', or 'plausible'
# NEXT_PUBLIC_ANALYTICS_PROVIDER=""
# NEXT_PUBLIC_GA_MEASUREMENT_ID=""
# NEXT_PUBLIC_MIXPANEL_TOKEN=""
# NEXT_PUBLIC_AMPLITUDE_KEY=""
# ============================================================================
# TURBO (Optional build optimization)
# ============================================================================
TURBO_CACHE="remote:rw"
TURBO_REMOTE_ONLY="true"
TURBO_RUN_SUMMARY="true"
TURBO_DOWNLOAD_LOCAL_ENABLED="true"
NX_DAEMON="false"
# ============================================================================
# FEATURE FLAGS (Optional)
# ============================================================================
# Enable mic buttons across forms and onboarding (client-side)
NEXT_PUBLIC_FEATURE_VOICE_INPUT="true"
# Enable analytics tracking
# NEXT_PUBLIC_FEATURE_ANALYTICS="false"
# Show performance monitor overlay (development only)
# NEXT_PUBLIC_SHOW_PERFORMANCE_MONITOR="false"
# Enable Supabase debug logging
# NEXT_PUBLIC_SUPABASE_DEBUG="false"
# Write-mode gates (set to true to enable write operations in those modules)
# LOANS_WRITE_MODE="false"
# PRODUCTS_WRITE_MODE="false"
# METRICS_ENABLED="false"
# ============================================================================
# LOKI SIBLING INTEGRATION
# ============================================================================
# Same 32+ character random value on OrangeCat and Loki. Signs ten-minute,
# one-use entity → build handoffs; never expose it as NEXT_PUBLIC_*.
LOKI_BUILD_INTENT_SECRET=""
# Same webhook secret on both products for settled-payment activity signals.
ORANGECAT_WEBHOOK_SECRET=""
LOKI_EVENTS_URL="https://loki.orangecat.ch/api/orangecat/events"
NEXT_PUBLIC_LOKI_URL="https://loki.orangecat.ch"
# Canonical OrangeCat pages used by both support pages.
NEXT_PUBLIC_ORANGECAT_PROJECT_ID="cb093f00-8745-4579-98df-050ebfb37181"
NEXT_PUBLIC_LOKI_ORANGECAT_PROJECT_ID="8130c927-114a-45b7-8cc2-99efd5224025"
# ============================================================================
# EVERYTHING ELSE src/ READS (optional — a feature is off until its key is set)
# ============================================================================
# Generated contract, enforced by __tests__/unit/ci/env-example-covers-src.test.ts:
# a variable the code reads must be named here, with the file that reads it,
# so a copy of this repo never discovers a switch by grepping. Leave unset to
# keep the feature off; read the named file for what the value means.
# AI_PROBE_SECRET= # src/services/cat/liveness.ts
# BRAVE_SEARCH_API_KEY= # src/services/cat/capability-gate.ts
# CAT_COMPLEXITY_ESCALATION= # src/services/cat/provider-catalog.ts
# CAT_PROMPT_SECTION_SELECTION= # src/services/cat/system-prompt.ts
# CAT_SOLON_PRIVKEY= # src/services/cat/handlers/governance.ts
# CHAT_REVIEW_TOKEN= # src/services/cat/chat-review-export.ts
# CRON_SECRET= # src/lib/api/cronAuth.ts
# EMBEDDINGS_API_KEY= # src/services/ai/embeddings.ts
# EMBEDDINGS_BASE_URL= # src/services/ai/embeddings.ts
# EMBEDDINGS_MODEL= # src/services/ai/embeddings.ts
# GITHUB_APP_CLIENT_ID= # src/services/github/connection.ts
# GITHUB_APP_CLIENT_SECRET= # src/services/github/connection.ts
# GITHUB_APP_SLUG= # src/services/github/connection.ts
# GOOGLE_CONNECT_CLIENT_ID= # src/services/google/connection.ts
# GOOGLE_CONNECT_CLIENT_SECRET= # src/services/google/connection.ts
# GROQ_DEFAULT_MODEL= # src/services/ai/groq-models.ts
# LOKI_ACTOR_STATUS_URL= # src/services/loki/actor-status.ts
# LOKI_TELEGRAM_REPLY_URL= # src/services/loki/telegram-reply.ts
# LOKI_ASK_URL= # src/services/loki/ask.ts
# LOKI_MODEL_URL= # src/services/loki/shared-keys.ts
# LOKI_FEEDBACK_URL= # src/services/loki/findings.ts
# LOKI_SITE_WALK_URL= # src/services/loki/site-walk.ts
# LOKI_BROWSER_URL= # src/services/loki/browser.ts
# LOKI_SESSIONS_URL= # src/services/loki/sessions.ts
# LOKI_ENTITLEMENT_URL= # src/services/loki/entitlement-notify.ts
# LOKI_NOTIFY_URL= # src/services/loki/notify-owner.ts (the owner bots to Loki notify gateway)
# LOKI_FEEDBACK_TOKEN= # src/app/layout.tsx
# LOKI_MAP_URL= # src/services/ai/studio-map-fetcher.ts
# LOKI_MCP_RESOURCE= # src/lib/oauth/config.ts
# LOKI_SITE_URL= # src/services/loki/site-build.ts
# LOKI_TASK_URL= # src/services/loki/task-dispatch.ts
# NEXT_PUBLIC_BITCOIN_NETWORK= # src/lib/bitcoin/mempool.ts
# NEXT_PUBLIC_CAT_CREDITS_LIVE= # src/config/features.ts
# NEXT_PUBLIC_ECOSYSTEM_BITCOIN_ADDRESS= # src/config/ecosystem.ts
# NEXT_PUBLIC_ECOSYSTEM_LIGHTNING_ADDRESS= # src/config/ecosystem.ts
# NEXT_PUBLIC_PAID_PLANS_OPEN= # src/config/features.ts
# NEXT_PUBLIC_SUPPORTER_PRODUCT_URL= # src/config/cat-plans.ts
# OAUTH_ISSUER= # src/lib/oauth/config.ts
# OAUTH_JWT_KID= # src/lib/oauth/keys.ts
# OAUTH_JWT_PREVIOUS_JWKS= # src/lib/oauth/keys.ts
# OAUTH_JWT_PRIVATE_KEY= # src/lib/oauth/keys.ts
# OC_BACKUP_DIR= # src/lib/host-metrics.ts
# OPENAI_API_KEY= # src/services/ai/embeddings.ts
# OPS_NOTIFY_USER_ID= # src/services/cat/ops-alert.ts
# ORANGECAT_OAUTH_CLIENT_ID= # src/app/(public)/docs/sign-in-with-orangecat/snippets.ts
# ORANGECAT_OAUTH_CLIENT_SECRET= # src/app/(public)/docs/sign-in-with-orangecat/snippets.ts
# PLATFORM_GROQ_FALLBACK_MODEL= # src/services/ai/groq-models.ts
# PLATFORM_GROQ_MODEL= # src/services/ai/groq-models.ts
# PLATFORM_OLLAMA_API_KEY= # src/services/ai/platform-providers.ts
# PLATFORM_OLLAMA_MODEL= # src/services/ai/platform-providers.ts
# PLATFORM_OLLAMA_URL= # src/services/ai/platform-providers.ts
# REINDEX_SECRET= # src/app/api/admin/reindex-embeddings/route.ts
# SEARXNG_URL= # src/services/cat/capability-gate.ts
# SOLON_AGENT_API_KEY= # src/services/cat/handlers/governance.ts
# SOLON_BASE_URL= # src/services/solon/decision-verify.ts
# SOLON_WEBHOOK_SECRET= # src/app/api/solon/events/route.ts
# TAVILY_API_KEY= # src/services/cat/capability-gate.ts
# TOGETHER_DEFAULT_MODEL= # src/services/cat/provider-catalog.ts
# WEBHOOK_SECRET_KEY= # src/lib/crypto/webhookSecretCipher.ts
# ============================================================================
# SETUP INSTRUCTIONS
# ============================================================================
# 1. Copy this file: cp .env.example .env.local
# 2. Fill in Supabase credentials from your project dashboard
# 3. Fill in Postgres credentials from Supabase database settings
# 4. Run: gh auth login (to authenticate GitHub CLI)
# 5. Run: gh auth token (to get GitHub personal access token)
# 6. Add GitHub token to GITHUB_TOKEN above
# 7. Optional: Add OpenRouter API key for platform-level AI
# 8. Run: npm run dev (to start development server)
# ============================================================================
# CREDENTIALS
# ============================================================================
# Local dev: fill in Supabase + Postgres values from your self-hosted
# Supabase instance (Studio on the box) into .env.local.
# Production: values live in /opt/orangecat/app/.env on the Hetzner box.
#
# Also add manually:
# - GITHUB_TOKEN (from: gh auth token)
# - OPENROUTER_API_KEY (optional, from: https://openrouter.ai/keys)
# The server's one AI usage log (src/services/ai/usage-events.ts, @bitbaum/ai-kit).
# One line per model call: app, vendor, model, outcome. Never content.
# Unset on the box: /opt/fleet/ai-usage is used when it exists. "off" writes nowhere.
# AI_USAGE_DIR=
# The name this app goes by in that log. Defaults to ORANGECAT.
# AI_APP_ID=
# Reading calendars linked by their iCal address. Unset = on. "off" pauses
# them without a deploy: nothing is fetched or parsed, and the page says so.
# CALENDAR_LINKED_READS=