Files
ttstd-infinite-canvas/backend/internal/generation/deps.go
2026-09-14 01:11:56 +08:00

52 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package generation
import (
"context"
"time"
"infinite-canvas/backend/internal/model"
"infinite-canvas/backend/internal/protocol"
)
// MediaResolver 水合参考媒体(资源 URL / data URL),由组合根注入,避免 generation → service 回环。
type MediaResolver interface {
HydrateGenerationMedia(userID string, input *Input, preferURL bool) error
}
// TaskProgress 写入任务进度/日志。
type TaskProgress interface {
SyncProviderTaskProgress(taskID string, responseBody []byte)
Log(userID, taskID, level, message, payload string) error
}
// BillingHooks 生成路径上的计费终态钩子。
type BillingHooks interface {
MarkBillingUncertain(taskID, reason string) error
Settle(taskID string) error
Refund(taskID, reason string) error
RestoreRefunded(taskID, reason string) error
}
// ChannelLimiter 渠道并发槽与熔断结果。
type ChannelLimiter interface {
AcquireChannelSlot(ctx context.Context, channelID string) (release func(), err error)
RecordChannelResult(channelID string, success bool)
}
// MediaPersister 持久化生成结果与资源 URL。
type MediaPersister interface {
PersistGeneratedMediaResult(ctx context.Context, userID, taskID string, result map[string]interface{}) (map[string]interface{}, error)
DirectResourceURL(resource *model.Resource, expiresAt time.Time) (string, error)
}
// Deps 是 Engine 的外部端口集合;禁止持有组合根或回环到 service。
type Deps struct {
Media MediaResolver
Progress TaskProgress
Billing BillingHooks
Channel ChannelLimiter
Persist MediaPersister
// Registry 可选;为空时 Engine 使用官方插件包回退表。
Registry *protocol.Registry
}