production runtime and mock removal
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
@@ -301,7 +302,18 @@ func (h *billingHandler) authorize(w http.ResponseWriter, r *http.Request, requi
|
||||
}
|
||||
func decodeJSON(r *http.Request, value any) { _ = json.NewDecoder(r.Body).Decode(value) }
|
||||
func billingString(value any) string { text, _ := value.(string); return strings.TrimSpace(text) }
|
||||
func numberValue(value any) float64 { number, _ := value.(float64); return number }
|
||||
func numberValue(value any) float64 {
|
||||
switch number := value.(type) {
|
||||
case float64:
|
||||
return number
|
||||
case string:
|
||||
parsed, err := strconv.ParseFloat(strings.TrimSpace(number), 64)
|
||||
if err == nil && !math.IsNaN(parsed) && !math.IsInf(parsed, 0) {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func first(value, fallback string) string {
|
||||
if value != "" {
|
||||
return value
|
||||
@@ -326,6 +338,10 @@ func writeAuthError(w http.ResponseWriter, err error) {
|
||||
}
|
||||
func writeDomainError(w http.ResponseWriter, err error) {
|
||||
status := billing.HTTPStatus(err)
|
||||
if status == http.StatusServiceUnavailable {
|
||||
writeAPIError(w, status, "计费服务暂不可用,请联系管理员。")
|
||||
return
|
||||
}
|
||||
if status >= 500 {
|
||||
writeAPIError(w, 500, "服务器内部错误。")
|
||||
return
|
||||
|
||||
@@ -87,6 +87,10 @@ func TestBillingAdminRoutesRequireSuperAdminAndValidateWrites(t *testing.T) {
|
||||
if got.Code != 200 || service.adjustment.AmountFen != 124 || service.adjustment.DeltaFen != -124 || service.adjustment.OperatorID != "root" {
|
||||
t.Fatalf("adjustment status=%d got=%+v body=%s", got.Code, service.adjustment, got.Body.String())
|
||||
}
|
||||
got = serveJSON(t, super, http.MethodPost, "/api/admin/billing/adjustments", map[string]any{"organizationId": "org", "amountYuan": "1.235", "direction": "credit", "note": " string amount "})
|
||||
if got.Code != 200 || service.adjustment.AmountFen != 124 || service.adjustment.DeltaFen != 124 {
|
||||
t.Fatalf("string adjustment status=%d got=%+v body=%s", got.Code, service.adjustment, got.Body.String())
|
||||
}
|
||||
var adjustmentResponse map[string]json.RawMessage
|
||||
if err := json.Unmarshal(got.Body.Bytes(), &adjustmentResponse); err != nil {
|
||||
t.Fatalf("decode adjustment response: %v", err)
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestHealthReportsProcessAndDatabaseConfigurationWithoutReadinessProbe(t *te
|
||||
func TestHealthIncludesInjectedRuntimeCompatibilityDetails(t *testing.T) {
|
||||
details := httpapi.HealthDetails{
|
||||
VisualAPIMode: "volcengine",
|
||||
EvolinkMode: "mock",
|
||||
EvolinkMode: "missing",
|
||||
SeedanceMode: "seedance",
|
||||
BailianMode: "missing",
|
||||
AuthMode: "configured",
|
||||
@@ -73,7 +73,7 @@ func TestHealthIncludesInjectedRuntimeCompatibilityDetails(t *testing.T) {
|
||||
if err := json.NewDecoder(recorder.Body).Decode(&response); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if response.VisualAPIMode != "volcengine" || response.EvolinkMode != "mock" || response.SeedanceMode != "seedance" || response.BailianMode != "missing" || response.AuthMode != "configured" {
|
||||
if response.VisualAPIMode != "volcengine" || response.EvolinkMode != "missing" || response.SeedanceMode != "seedance" || response.BailianMode != "missing" || response.AuthMode != "configured" {
|
||||
t.Fatalf("runtime response = %+v", response)
|
||||
}
|
||||
if len(response.Capabilities) != 2 || response.Capabilities[0]["id"] != "image.generate" || response.Capabilities[1]["id"] != "video.generate" {
|
||||
|
||||
@@ -55,7 +55,7 @@ func openAPISchemas() map[string]any {
|
||||
"ownerId": map[string]any{"type": "string", "example": "api:partner-a"},
|
||||
"externalClientId": map[string]any{"type": "string"},
|
||||
"capability": openAPIRef("GenerationCapability"),
|
||||
"provider": map[string]any{"type": "string", "enum": []string{"volcengine-visual", "evolink", "seedance", "bailian", "mock"}},
|
||||
"provider": map[string]any{"type": "string", "enum": []string{"volcengine-visual", "evolink", "seedance", "bailian"}},
|
||||
"reqKey": map[string]any{"type": "string"},
|
||||
"status": openAPIRef("GenerationStatus"),
|
||||
"prompt": map[string]any{"type": "string"},
|
||||
|
||||
Reference in New Issue
Block a user