mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-12 15:21:09 +00:00
fix(billing): validate quantity parameters and harden quota calculations
Bound user-supplied count/duration parameters at request validation, route ratio multipliers through guarded setters, and use saturating int conversions in all quota math paths.
This commit is contained in:
@@ -3,6 +3,8 @@ package gemini
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
)
|
||||
|
||||
// ParseVeoDurationSeconds extracts durationSeconds from metadata.
|
||||
@@ -46,19 +48,21 @@ func ParseVeoResolution(metadata map[string]any) string {
|
||||
|
||||
// ResolveVeoDuration returns the effective duration in seconds.
|
||||
// Priority: metadata["durationSeconds"] > stdDuration > stdSeconds > default (8).
|
||||
// The result is capped because it is used as a billing multiplier and the
|
||||
// metadata path bypasses standard request validation.
|
||||
func ResolveVeoDuration(metadata map[string]any, stdDuration int, stdSeconds string) int {
|
||||
if metadata != nil {
|
||||
if _, exists := metadata["durationSeconds"]; exists {
|
||||
if d := ParseVeoDurationSeconds(metadata); d > 0 {
|
||||
return d
|
||||
return min(d, relaycommon.MaxTaskDurationSeconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
if stdDuration > 0 {
|
||||
return stdDuration
|
||||
return min(stdDuration, relaycommon.MaxTaskDurationSeconds)
|
||||
}
|
||||
if s, err := strconv.Atoi(stdSeconds); err == nil && s > 0 {
|
||||
return s
|
||||
return min(s, relaycommon.MaxTaskDurationSeconds)
|
||||
}
|
||||
return 8
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user