add multiplier, send 2 usd in newer
This commit is contained in:
parent
5c569056e2
commit
c2417c31da
@ -193,12 +193,21 @@ FAL_API_KEY="fal-1234567890abcdefghijklmnopqrstuvwxyz"
|
|||||||
| `NEXTAUTH_URL` | NextAuth URL (same as app URL) | `https://prmbr.com` |
|
| `NEXTAUTH_URL` | NextAuth URL (same as app URL) | `https://prmbr.com` |
|
||||||
| `NEXTAUTH_SECRET` | NextAuth secret for JWT signing | Random 32-character string |
|
| `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
|
### Configuration
|
||||||
```bash
|
```bash
|
||||||
# Application Settings
|
# Application Settings
|
||||||
NEXT_PUBLIC_APP_URL="https://prmbr.com"
|
NEXT_PUBLIC_APP_URL="https://prmbr.com"
|
||||||
NEXTAUTH_URL="https://prmbr.com"
|
NEXTAUTH_URL="https://prmbr.com"
|
||||||
NEXTAUTH_SECRET="your-super-secret-nextauth-secret-32chars"
|
NEXTAUTH_SECRET="your-super-secret-nextauth-secret-32chars"
|
||||||
|
|
||||||
|
# Fee Calculation (Optional - defaults to 10x)
|
||||||
|
FEE_CALCULATION_MULTIPLIER="10.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Generating NEXTAUTH_SECRET
|
### Generating NEXTAUTH_SECRET
|
||||||
@ -269,6 +278,9 @@ FAL_API_KEY="fal-1234567890abcdefghijklmnopqrstuvwxyzABCDEF"
|
|||||||
NEXT_PUBLIC_APP_URL="http://localhost:3000"
|
NEXT_PUBLIC_APP_URL="http://localhost:3000"
|
||||||
NEXTAUTH_URL="http://localhost:3000"
|
NEXTAUTH_URL="http://localhost:3000"
|
||||||
NEXTAUTH_SECRET="super-secret-nextauth-development-key-32-chars-long"
|
NEXTAUTH_SECRET="super-secret-nextauth-development-key-32-chars-long"
|
||||||
|
|
||||||
|
# Fee Calculation (Optional - defaults to 10x)
|
||||||
|
FEE_CALCULATION_MULTIPLIER="10.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🌐 Full Production Configuration
|
### 🌐 Full Production Configuration
|
||||||
@ -311,6 +323,9 @@ FAL_API_KEY="fal-production-1234567890abcdefghijklmnopqrstuvwxyz"
|
|||||||
NEXT_PUBLIC_APP_URL="https://prmbr.com"
|
NEXT_PUBLIC_APP_URL="https://prmbr.com"
|
||||||
NEXTAUTH_URL="https://prmbr.com"
|
NEXTAUTH_URL="https://prmbr.com"
|
||||||
NEXTAUTH_SECRET="super-secret-production-nextauth-key-32-chars-long-secure"
|
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
|
## 🔒 Security Best Practices
|
||||||
|
@ -67,14 +67,14 @@ export async function POST() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isNewUser) {
|
if (isNewUser) {
|
||||||
// 为新用户添加系统赠送的5USD信用额度(1个月后过期)
|
// 为新用户添加系统赠送的2USD信用额度(1个月后过期)
|
||||||
const expiresAt = new Date()
|
const expiresAt = new Date()
|
||||||
expiresAt.setMonth(expiresAt.getMonth() + 1)
|
expiresAt.setMonth(expiresAt.getMonth() + 1)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addCredit(
|
await addCredit(
|
||||||
user.id,
|
user.id,
|
||||||
5.0,
|
2.0,
|
||||||
'system_gift',
|
'system_gift',
|
||||||
'系统赠送 - 新用户礼包',
|
'系统赠送 - 新用户礼包',
|
||||||
expiresAt
|
expiresAt
|
||||||
|
@ -53,7 +53,7 @@ export function calculateCost(
|
|||||||
inputCostPer1k?: number | null
|
inputCostPer1k?: number | null
|
||||||
outputCostPer1k?: number | null
|
outputCostPer1k?: number | null
|
||||||
},
|
},
|
||||||
costMultiplier: number = 1.0
|
costMultiplier?: number
|
||||||
): number {
|
): number {
|
||||||
const inputCostPer1k = model.inputCostPer1k || 0
|
const inputCostPer1k = model.inputCostPer1k || 0
|
||||||
const outputCostPer1k = model.outputCostPer1k || 0
|
const outputCostPer1k = model.outputCostPer1k || 0
|
||||||
@ -63,8 +63,12 @@ export function calculateCost(
|
|||||||
const outputCost = (outputTokens / 1000) * outputCostPer1k
|
const outputCost = (outputTokens / 1000) * outputCostPer1k
|
||||||
const baseCost = inputCost + outputCost
|
const baseCost = inputCost + outputCost
|
||||||
|
|
||||||
// 应用套餐费用倍率
|
// 获取环境变量中的费用倍率,默认为 10 倍
|
||||||
return baseCost * costMultiplier
|
const defaultMultiplier = parseFloat(process.env.FEE_CALCULATION_MULTIPLIER || '10.0')
|
||||||
|
const finalMultiplier = costMultiplier ?? defaultMultiplier
|
||||||
|
|
||||||
|
// 应用费用倍率
|
||||||
|
return baseCost * finalMultiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user