# ============================================================================
# Cloudflare R2 Configuration - Complete Setup Guide
# ============================================================================
# STEP 1: Get your Account ID
# URL: https://dash.cloudflare.com/?to=/:account/home
# Instructions:
# 1. Log into Cloudflare Dashboard
# 2. Click the menu button next to your account name
# 3. Select "Copy account ID" from the dropdown
# 4. Paste below (format: 32-character hex string like "a1b2c3d4e5f6...")
R2_ACCOUNT_ID=dea502ae4b9ede75e87b654ba5f05375
# STEP 2: Create an R2 Bucket
# URL: https://dash.cloudflare.com/?to=/:account/r2/overview
# Instructions:
# 1. Go to R2 Object Storage page
# 2. Click "Create bucket" button
# 3. Enter bucket name (lowercase, hyphens only, globally unique in your account)
# 4. Select jurisdiction (optional):
# - Default: Global (use standard endpoint)
# - EU: European Union (use *.eu.r2.cloudflarestorage.com)
# - FedRAMP: US Government (use *.fedramp.r2.cloudflarestorage.com)
# 5. Click "Create bucket"
R2_BUCKET_NAME=forge
# STEP 3: Create API Token (R2 Access Key ID & Secret Access Key)
# URL: https://dash.cloudflare.com/?to=/:account/r2/overview
# Instructions:
# 1. On R2 Overview page, click "Manage R2 API Tokens"
# 2. Click "Create API token" button
# 3. Choose token type:
# a) "Create Account API token" (recommended, tied to Cloudflare account)
# - Requires Super Administrator role
# - Valid until manually revoked
# b) "Create User API token" (alternative, tied to your user)
# - Inherits your personal permissions
# - Becomes inactive if user removed from account
# 4. Under "Permissions", select permission level:
# - "Admin Read & Write" (full access, recommended for development)
# - "Admin Read only" (read-only access)
# - "Object Read & Write" (bucket-specific read/write)
# - "Object Read only" (bucket-specific read-only)
# 5. (Optional) If you chose "Object Read & Write" or "Object Read only",
# scope the token to specific buckets in the "Bucket" dropdown
# 6. Click "Create Account API token" or "Create User API token"
# 7. IMPORTANT: Copy both values immediately (Secret is only shown once!)
# - Access Key ID: Labeled as "Access Key ID" (32-char hex)
# - Secret Access Key: Labeled as "Secret Access Key" (43-char base64)
# 8. Paste both values below
# R2 Access Key ID (from token creation page, looks like "a1b2c3d4e5f6...")
R2_ACCESS_KEY_ID=381155ecbee74e94645a44710020f76f
# R2 Secret Access Key (ONLY SHOWN ONCE! Save it now, looks like "abc123XYZ...")
R2_SECRET_ACCESS_KEY=84c3722c1a4f4525ff87424088fa96d49de81c7a6663e58b46c9e68ccd5cceb8
# STEP 4 (Optional): Configure Custom Domain - And here is the token btw: Rmp3Z0M43wY820sinALMOpvcEUy0C3tg3tHik6VF
# URL: https://dash.cloudflare.com/?to=/:account/r2/overview/buckets
# Instructions:
# 1. Click on your bucket name in the R2 buckets list
# 2. Go to "Settings" tab
# 3. Scroll to "Public access" section
# 4. Click "Connect custom domain"
# 5. Enter your domain name (e.g., storage.yourdomain.com)
# 6. Follow DNS configuration instructions
# 7. Wait for DNS propagation (1-48 hours)
# 8. Uncomment and update the line below
# R2_CUSTOM_DOMAIN=blobs.yourdomain.com
# ============================================================================
# R2 Endpoint URLs (DO NOT MODIFY - Auto-configured by the code)
# ============================================================================
# Standard endpoint: https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# EU endpoint: https://<ACCOUNT_ID>.eu.r2.cloudflarestorage.com
# FedRAMP endpoint: https://<ACCOUNT_ID>.fedramp.r2.cloudflarestorage.com
#
# The code automatically constructs the endpoint URL from your ACCOUNT_ID
# and bucket jurisdiction settings.
# ============================================================================
# ============================================================================
# Database Configuration (optional - for Neon/PostgreSQL)
# ============================================================================
# DATABASE_URL=postgresql://user:pass@host/dbname
# ============================================================================
# Server Configuration
# ============================================================================
# PORT=3000
# HOST=0.0.0.0
# ============================================================================
# Cost Estimates (as of 2024)
# ============================================================================
# Storage: $0.015/GB/month (first 10 GB free)
# Operations: Class A (write): $4.50/million requests
# Class B (read): $0.36/million requests
# Egress: $0.00/GB (FREE - zero egress fees!)
#
# Example cost for 100 GB storage with 1M reads/month:
# Storage: 90 GB * $0.015 = $1.35/month
# Reads: 1M * $0.36/million = $0.36/month
# Total: $1.71/month
#
# Compare to AWS S3 (same usage):
# Storage: 100 GB * $0.023 = $2.30/month
# Reads: 1M * $0.40/million = $0.40/month
# Egress: 100 GB * $0.09 = $9.00/month
# Total: $11.70/month (6.8x more expensive!)
# ============================================================================
# ============================================================================
# Troubleshooting
# ============================================================================
# Error: "Invalid account ID"
# → Check that R2_ACCOUNT_ID is exactly 32 hex characters (no spaces)
# → Copy from: https://dash.cloudflare.com/?to=/:account/home
#
# Error: "Bucket not found"
# → Verify bucket name matches exactly (case-sensitive, hyphens only)
# → Create bucket at: https://dash.cloudflare.com/?to=/:account/r2/overview
#
# Error: "Access denied" or "Invalid signature"
# → Verify R2_ACCESS_KEY_ID and R2_SECRET_ACCESS_KEY are correct
# → Check token permissions (Admin Read & Write required)
# → Recreate token if secret was lost
#
# Error: "Region not found"
# → If using EU/FedRAMP jurisdiction, update R2Storage::endpoint()
# → Use *.eu.r2.cloudflarestorage.com for EU buckets
# → Use *.fedramp.r2.cloudflarestorage.com for FedRAMP buckets
#
# Need help? Check docs:
# → https://developers.cloudflare.com/r2/
# → https://developers.cloudflare.com/r2/api/s3/tokens/
# ============================================================================