修改配置编辑不了的问题
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/identity"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/jobs"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/providers"
|
||||
)
|
||||
|
||||
@@ -21,14 +20,14 @@ type billingHandler struct {
|
||||
authorizer *PlatformAuthorizer
|
||||
service BillingHTTPService
|
||||
accounts BillingAccountStore
|
||||
builder jobs.ProviderJobBuilder
|
||||
builder ProviderCommandBuilder
|
||||
}
|
||||
|
||||
func NewBillingHandler(authorizer *PlatformAuthorizer, service BillingHTTPService, accounts BillingAccountStore) http.Handler {
|
||||
return &billingHandler{authorizer: authorizer, service: service, accounts: accounts}
|
||||
}
|
||||
|
||||
func NewBillingHandlerWithBuilder(authorizer *PlatformAuthorizer, service BillingHTTPService, accounts BillingAccountStore, builder jobs.ProviderJobBuilder) http.Handler {
|
||||
func NewBillingHandlerWithBuilder(authorizer *PlatformAuthorizer, service BillingHTTPService, accounts BillingAccountStore, builder ProviderCommandBuilder) http.Handler {
|
||||
return &billingHandler{authorizer: authorizer, service: service, accounts: accounts, builder: builder}
|
||||
}
|
||||
|
||||
@@ -112,7 +111,7 @@ func (h *billingHandler) quote(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
provider, reqKey := billingString(body["provider"]), billingString(body["reqKey"])
|
||||
parameters := billing.Parameters{}
|
||||
if h.builder.NewID != nil {
|
||||
if h.builder != nil {
|
||||
prepared, err := h.builder.Build(r.Context(), session.User.ID, "", capability, "", body)
|
||||
if err != nil {
|
||||
writeJobError(w, err, false)
|
||||
|
||||
@@ -30,6 +30,7 @@ type handler struct {
|
||||
readiness Readiness
|
||||
readinessTimeout time.Duration
|
||||
healthDetails HealthDetails
|
||||
healthProvider func(context.Context) HealthDetails
|
||||
}
|
||||
|
||||
// HealthDetails contains runtime compatibility fields assembled by the
|
||||
@@ -67,6 +68,14 @@ func WithHealthDetails(details HealthDetails) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithHealthDetailsProvider evaluates mutable provider state for every health
|
||||
// request while preserving /api/health as a non-blocking liveness endpoint.
|
||||
func WithHealthDetailsProvider(provider func(context.Context) HealthDetails) Option {
|
||||
return func(h *handler) {
|
||||
h.healthProvider = provider
|
||||
}
|
||||
}
|
||||
|
||||
// NewHandler returns the foundation health/readiness HTTP handler.
|
||||
func NewHandler(readiness Readiness, options ...Option) http.Handler {
|
||||
h := &handler{readiness: readiness, readinessTimeout: defaultReadinessTimeout, healthDetails: HealthDetails{Capabilities: []any{}}}
|
||||
@@ -96,6 +105,13 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if h.readiness != nil {
|
||||
status = h.readiness.Status()
|
||||
}
|
||||
details := h.healthDetails
|
||||
if h.healthProvider != nil {
|
||||
details = h.healthProvider(r.Context())
|
||||
if details.Capabilities == nil {
|
||||
details.Capabilities = []any{}
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, struct {
|
||||
OK bool `json:"ok"`
|
||||
AppID string `json:"appId"`
|
||||
@@ -106,7 +122,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
OK: true,
|
||||
AppID: appID,
|
||||
WebOnly: true,
|
||||
HealthDetails: h.healthDetails,
|
||||
HealthDetails: details,
|
||||
Database: status,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,6 +34,12 @@ type JobBuilder interface {
|
||||
Build(context.Context, JobBuildInput) (jobs.CreateCommand, error)
|
||||
}
|
||||
|
||||
// ProviderCommandBuilder is the shared seam used by creation, retry, and quote
|
||||
// paths. Implementations may resolve runtime provider settings per request.
|
||||
type ProviderCommandBuilder interface {
|
||||
Build(context.Context, string, string, string, string, map[string]any) (jobs.CreateCommand, error)
|
||||
}
|
||||
|
||||
type JobCreationCoordinator interface {
|
||||
CreatePlatform(context.Context, identity.Session, orchestration.CreationInput) (jobs.Job, bool, error)
|
||||
CreatePublic(context.Context, orchestration.CreationInput) (jobs.Job, bool, error)
|
||||
@@ -48,7 +54,7 @@ type JobTickLimiter interface {
|
||||
}
|
||||
|
||||
// ProviderBuilderAdapter exposes jobs.ProviderJobBuilder at the HTTP seam.
|
||||
type ProviderBuilderAdapter struct{ Builder jobs.ProviderJobBuilder }
|
||||
type ProviderBuilderAdapter struct{ Builder ProviderCommandBuilder }
|
||||
|
||||
func (a ProviderBuilderAdapter) Build(ctx context.Context, in JobBuildInput) (jobs.CreateCommand, error) {
|
||||
return a.Builder.Build(ctx, in.Scope.OwnerID, in.Scope.ExternalClientID, in.Capability, in.IdempotencyKey, in.Body)
|
||||
|
||||
Reference in New Issue
Block a user