Documentation
¶
Index ¶
- Variables
- type AccountManager
- func (am *AccountManager) RefreshSingleToken(ctx context.Context, acc *model.SoraAccount) error
- func (am *AccountManager) Start(ctx context.Context)
- func (am *AccountManager) SyncSingleAccountCredit(ctx context.Context, acc *model.SoraAccount) error
- func (am *AccountManager) SyncSingleAccountSubscription(ctx context.Context, acc *model.SoraAccount) error
- type Scheduler
- type SettingsStore
- func (s *SettingsStore) Get(key string) string
- func (s *SettingsStore) GetAll() map[string]string
- func (s *SettingsStore) GetProxyURL() string
- func (s *SettingsStore) GetSyncConfig() *SyncConfig
- func (s *SettingsStore) InitDefaults(defaults map[string]string)
- func (s *SettingsStore) Set(key, value string)
- type SyncConfig
- type TaskStore
- func (ts *TaskStore) Create(task *model.SoraTask) error
- func (ts *TaskStore) DownloadImage(ctx context.Context, task *model.SoraTask) (io.ReadCloser, int64, string, error)
- func (ts *TaskStore) DownloadVideo(ctx context.Context, task *model.SoraTask) (io.ReadCloser, int64, string, error)
- func (ts *TaskStore) Get(taskID string) (*model.SoraTask, error)
- func (ts *TaskStore) ListTasks(status, taskType string, page, pageSize int, apiKeyID int64) ([]model.SoraTask, int64, error)
- func (ts *TaskStore) RecoverInProgressTasks()
- func (ts *TaskStore) StartPolling(task *model.SoraTask, account *model.SoraAccount)
Constants ¶
This section is empty.
Variables ¶
var ErrNoAvailableAccount = errors.New("没有可用的 Sora 账号")
Functions ¶
This section is empty.
Types ¶
type AccountManager ¶
type AccountManager struct {
// contains filtered or unexported fields
}
AccountManager 账号池管理(Token 刷新、配额同步、订阅同步)
func NewAccountManager ¶
func NewAccountManager(db *gorm.DB, settings *SettingsStore) *AccountManager
NewAccountManager 创建账号管理器
func (*AccountManager) RefreshSingleToken ¶
func (am *AccountManager) RefreshSingleToken(ctx context.Context, acc *model.SoraAccount) error
RefreshSingleToken 手动刷新单个账号 Token(管理端点使用)
func (*AccountManager) SyncSingleAccountCredit ¶
func (am *AccountManager) SyncSingleAccountCredit(ctx context.Context, acc *model.SoraAccount) error
SyncSingleAccountCredit 手动同步单个账号配额(管理端点使用)
func (*AccountManager) SyncSingleAccountSubscription ¶
func (am *AccountManager) SyncSingleAccountSubscription(ctx context.Context, acc *model.SoraAccount) error
SyncSingleAccountSubscription 手动同步单个账号订阅(管理端点使用)
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler 账号调度器
func NewScheduler ¶
func NewScheduler(db *gorm.DB, settings *SettingsStore) *Scheduler
NewScheduler 创建调度器
func (*Scheduler) GetProxyURL ¶
GetProxyURL 返回全局代理 URL(动态从设置读取)
func (*Scheduler) MarkAccountError ¶
MarkAccountError 标记账号错误状态
func (*Scheduler) MarkRateLimited ¶
MarkRateLimited 标记账号限流
func (*Scheduler) PickAccount ¶
func (s *Scheduler) PickAccount(groupID *int64) (*model.SoraAccount, error)
PickAccount 选取一个可用账号(最久未用优先),groupID 不为 nil 时仅从该分组选取
筛选条件:
- enabled=true 且 status=active
- remaining_count != 0(-1=未知视为可用,0=额度用完排除)
- rate_limit_reached=false 或 rate_limit_resets_at < now()(限流已解除)
- 若指定 groupID,则仅选取该分组的账号
排序:last_used_at ASC NULLS FIRST
type SettingsStore ¶
type SettingsStore struct {
// contains filtered or unexported fields
}
SettingsStore 系统设置存储(内存缓存 + 数据库持久化)
func (*SettingsStore) GetAll ¶
func (s *SettingsStore) GetAll() map[string]string
GetAll 获取所有设置(返回副本)
func (*SettingsStore) GetProxyURL ¶
func (s *SettingsStore) GetProxyURL() string
GetProxyURL 获取全局代理 URL(自动解析 ip:port:user:pass 等格式)
func (*SettingsStore) GetSyncConfig ¶
func (s *SettingsStore) GetSyncConfig() *SyncConfig
GetSyncConfig 获取同步配置
func (*SettingsStore) InitDefaults ¶
func (s *SettingsStore) InitDefaults(defaults map[string]string)
InitDefaults 初始化默认值(仅在设置不存在时写入)
type SyncConfig ¶
type SyncConfig struct {
TokenRefreshInterval time.Duration
CreditSyncInterval time.Duration
SubscriptionSyncInterval time.Duration
}
SyncConfig 同步配置
type TaskStore ¶
type TaskStore struct {
// contains filtered or unexported fields
}
TaskStore 任务存储与后台轮询
func NewTaskStore ¶
NewTaskStore 创建任务存储
func (*TaskStore) DownloadImage ¶
func (ts *TaskStore) DownloadImage(ctx context.Context, task *model.SoraTask) (io.ReadCloser, int64, string, error)
DownloadImage 下载图片并流式转发
func (*TaskStore) DownloadVideo ¶
func (ts *TaskStore) DownloadVideo(ctx context.Context, task *model.SoraTask) (io.ReadCloser, int64, string, error)
DownloadVideo 下载视频并流式转发
func (*TaskStore) ListTasks ¶
func (ts *TaskStore) ListTasks(status, taskType string, page, pageSize int, apiKeyID int64) ([]model.SoraTask, int64, error)
ListTasks 分页查询任务(apiKeyID > 0 时按 API Key 过滤)
func (*TaskStore) RecoverInProgressTasks ¶
func (ts *TaskStore) RecoverInProgressTasks()
RecoverInProgressTasks 服务重启后恢复进行中的任务轮询
func (*TaskStore) StartPolling ¶
func (ts *TaskStore) StartPolling(task *model.SoraTask, account *model.SoraAccount)
StartPolling 启动后台轮询任务状态