add multiplier, send 2 usd in newer

This commit is contained in:
songtianlun 2025-09-01 16:38:17 +08:00
parent 5c569056e2
commit c2417c31da
3 changed files with 24 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}
/**