diff --git a/docs/ENVIRONMENT_VARIABLES.md b/docs/ENVIRONMENT_VARIABLES.md index ded703e..d35b88d 100644 --- a/docs/ENVIRONMENT_VARIABLES.md +++ b/docs/ENVIRONMENT_VARIABLES.md @@ -193,12 +193,21 @@ FAL_API_KEY="fal-1234567890abcdefghijklmnopqrstuvwxyz" | `NEXTAUTH_URL` | NextAuth URL (same as app URL) | `https://prmbr.com` | | `NEXTAUTH_SECRET` | NextAuth secret for JWT signing | Random 32-character string | +### Optional Variables + +| Variable | Description | Default | Example | +|----------|-------------|---------|---------| +| `FEE_CALCULATION_MULTIPLIER` | Fee calculation multiplier for AI model costs | `10.0` | `5.0` | + ### Configuration ```bash # Application Settings NEXT_PUBLIC_APP_URL="https://prmbr.com" NEXTAUTH_URL="https://prmbr.com" NEXTAUTH_SECRET="your-super-secret-nextauth-secret-32chars" + +# Fee Calculation (Optional - defaults to 10x) +FEE_CALCULATION_MULTIPLIER="10.0" ``` ### Generating NEXTAUTH_SECRET @@ -269,6 +278,9 @@ FAL_API_KEY="fal-1234567890abcdefghijklmnopqrstuvwxyzABCDEF" NEXT_PUBLIC_APP_URL="http://localhost:3000" NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="super-secret-nextauth-development-key-32-chars-long" + +# Fee Calculation (Optional - defaults to 10x) +FEE_CALCULATION_MULTIPLIER="10.0" ``` ### 🌐 Full Production Configuration @@ -311,6 +323,9 @@ FAL_API_KEY="fal-production-1234567890abcdefghijklmnopqrstuvwxyz" NEXT_PUBLIC_APP_URL="https://prmbr.com" NEXTAUTH_URL="https://prmbr.com" NEXTAUTH_SECRET="super-secret-production-nextauth-key-32-chars-long-secure" + +# Fee Calculation (Optional - defaults to 10x) +FEE_CALCULATION_MULTIPLIER="10.0" ``` ## 🔒 Security Best Practices diff --git a/src/app/api/users/sync/route.ts b/src/app/api/users/sync/route.ts index 25995e3..ef5ae65 100644 --- a/src/app/api/users/sync/route.ts +++ b/src/app/api/users/sync/route.ts @@ -67,14 +67,14 @@ export async function POST() { } if (isNewUser) { - // 为新用户添加系统赠送的5USD信用额度(1个月后过期) + // 为新用户添加系统赠送的2USD信用额度(1个月后过期) const expiresAt = new Date() expiresAt.setMonth(expiresAt.getMonth() + 1) try { await addCredit( user.id, - 5.0, + 2.0, 'system_gift', '系统赠送 - 新用户礼包', expiresAt diff --git a/src/lib/simulator-utils.ts b/src/lib/simulator-utils.ts index 4c7df90..e7e633b 100644 --- a/src/lib/simulator-utils.ts +++ b/src/lib/simulator-utils.ts @@ -53,7 +53,7 @@ export function calculateCost( inputCostPer1k?: number | null outputCostPer1k?: number | null }, - costMultiplier: number = 1.0 + costMultiplier?: number ): number { const inputCostPer1k = model.inputCostPer1k || 0 const outputCostPer1k = model.outputCostPer1k || 0 @@ -63,8 +63,12 @@ export function calculateCost( const outputCost = (outputTokens / 1000) * outputCostPer1k const baseCost = inputCost + outputCost - // 应用套餐费用倍率 - return baseCost * costMultiplier + // 获取环境变量中的费用倍率,默认为 10 倍 + const defaultMultiplier = parseFloat(process.env.FEE_CALCULATION_MULTIPLIER || '10.0') + const finalMultiplier = costMultiplier ?? defaultMultiplier + + // 应用费用倍率 + return baseCost * finalMultiplier } /**