service

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Start

func (am *AccountManager) Start(ctx context.Context)

Start 启动后台同步任务

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

func (s *Scheduler) GetProxyURL() string

GetProxyURL 返回全局代理 URL(动态从设置读取)

func (*Scheduler) MarkAccountError

func (s *Scheduler) MarkAccountError(accountID int64, status, lastError string)

MarkAccountError 标记账号错误状态

func (*Scheduler) MarkRateLimited

func (s *Scheduler) MarkRateLimited(accountID int64, resetsInSec int)

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 NewSettingsStore

func NewSettingsStore(db *gorm.DB) *SettingsStore

NewSettingsStore 创建设置存储

func (*SettingsStore) Get

func (s *SettingsStore) Get(key string) string

Get 获取设置值

func (*SettingsStore) GetAll

func (s *SettingsStore) GetAll() map[string]string

GetAll 获取所有设置(返回副本)

func (*SettingsStore) GetProxyURL

func (s *SettingsStore) GetProxyURL() string

GetProxyURL 获取全局代理 URL(原始值,格式解析由 sora.New 统一处理)

func (*SettingsStore) GetSyncConfig

func (s *SettingsStore) GetSyncConfig() *SyncConfig

GetSyncConfig 获取同步配置

func (*SettingsStore) InitDefaults

func (s *SettingsStore) InitDefaults(defaults map[string]string)

InitDefaults 初始化默认值(仅在设置不存在时写入)

func (*SettingsStore) Set

func (s *SettingsStore) Set(key, value string)

Set 设置值

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

func NewTaskStore(db *gorm.DB, scheduler *Scheduler) *TaskStore

NewTaskStore 创建任务存储

func (*TaskStore) Create

func (ts *TaskStore) Create(task *model.SoraTask) error

Create 创建任务记录

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) Get

func (ts *TaskStore) Get(taskID string) (*model.SoraTask, error)

Get 获取任务

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 启动后台轮询任务状态

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL