Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
b8c56ff9
Commit
b8c56ff9
authored
Apr 02, 2026
by
erio
Browse files
fix: validate prices must be >= 0, remove debug logs
parent
38da737e
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/channel_handler.go
View file @
b8c56ff9
...
@@ -226,14 +226,34 @@ func pricingRequestToService(reqs []channelModelPricingRequest) []service.Channe
...
@@ -226,14 +226,34 @@ func pricingRequestToService(reqs []channelModelPricingRequest) []service.Channe
return
result
return
result
}
}
// validatePricingBillingMode 校验
按次/图片计费模式必须配置 PerRequestPrice 或 Intervals
// validatePricingBillingMode 校验
计费配置
func
validatePricingBillingMode
(
pricing
[]
service
.
ChannelModelPricing
)
error
{
func
validatePricingBillingMode
(
pricing
[]
service
.
ChannelModelPricing
)
error
{
for
_
,
p
:=
range
pricing
{
for
_
,
p
:=
range
pricing
{
// 按次/图片模式必须配置默认价格或区间
if
p
.
BillingMode
==
service
.
BillingModePerRequest
||
p
.
BillingMode
==
service
.
BillingModeImage
{
if
p
.
BillingMode
==
service
.
BillingModePerRequest
||
p
.
BillingMode
==
service
.
BillingModeImage
{
if
p
.
PerRequestPrice
==
nil
&&
len
(
p
.
Intervals
)
==
0
{
if
p
.
PerRequestPrice
==
nil
&&
len
(
p
.
Intervals
)
==
0
{
return
errors
.
New
(
"per-request price or intervals required for per_request/image billing mode"
)
return
errors
.
New
(
"per-request price or intervals required for per_request/image billing mode"
)
}
}
}
}
// 校验价格不能为负
if
err
:=
validatePriceNotNegative
(
"input_price"
,
p
.
InputPrice
);
err
!=
nil
{
return
err
}
if
err
:=
validatePriceNotNegative
(
"output_price"
,
p
.
OutputPrice
);
err
!=
nil
{
return
err
}
if
err
:=
validatePriceNotNegative
(
"cache_write_price"
,
p
.
CacheWritePrice
);
err
!=
nil
{
return
err
}
if
err
:=
validatePriceNotNegative
(
"cache_read_price"
,
p
.
CacheReadPrice
);
err
!=
nil
{
return
err
}
if
err
:=
validatePriceNotNegative
(
"image_output_price"
,
p
.
ImageOutputPrice
);
err
!=
nil
{
return
err
}
if
err
:=
validatePriceNotNegative
(
"per_request_price"
,
p
.
PerRequestPrice
);
err
!=
nil
{
return
err
}
// 校验 interval:至少有一个价格字段非空
// 校验 interval:至少有一个价格字段非空
for
_
,
iv
:=
range
p
.
Intervals
{
for
_
,
iv
:=
range
p
.
Intervals
{
if
iv
.
InputPrice
==
nil
&&
iv
.
OutputPrice
==
nil
&&
if
iv
.
InputPrice
==
nil
&&
iv
.
OutputPrice
==
nil
&&
...
@@ -247,6 +267,13 @@ func validatePricingBillingMode(pricing []service.ChannelModelPricing) error {
...
@@ -247,6 +267,13 @@ func validatePricingBillingMode(pricing []service.ChannelModelPricing) error {
return
nil
return
nil
}
}
func
validatePriceNotNegative
(
field
string
,
val
*
float64
)
error
{
if
val
!=
nil
&&
*
val
<
0
{
return
fmt
.
Errorf
(
"%s must be >= 0"
,
field
)
}
return
nil
}
func
formatMaxTokens
(
max
*
int
)
string
{
func
formatMaxTokens
(
max
*
int
)
string
{
if
max
==
nil
{
if
max
==
nil
{
return
"∞"
return
"∞"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment