mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
Add async task management for Sora video/image generation with two forwarding modes: OAuth (SDK) and API Key (HTTP upstream). Includes background worker for status polling and 3-layer storage degradation (S3 > local disk > upstream URL passthrough). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// ── 任务状态常量 ──
|
|
|
|
const (
|
|
SoraTaskQueued = "queued"
|
|
SoraTaskInProgress = "in_progress"
|
|
SoraTaskCompleted = "completed"
|
|
SoraTaskFailed = "failed"
|
|
)
|
|
|
|
// ── 对象类型常量 ──
|
|
|
|
const (
|
|
SoraObjectVideo = "video"
|
|
SoraObjectCharacter = "character"
|
|
SoraObjectImage = "image"
|
|
)
|
|
|
|
// SoraTask 表示一个 Sora 异步任务记录。
|
|
type SoraTask struct {
|
|
ID string
|
|
AccountID int64
|
|
APIKeyID *int64
|
|
UpstreamTaskID string
|
|
ObjectType string
|
|
Model string
|
|
Prompt string
|
|
Status string
|
|
Progress int
|
|
VideoURL string // 原始上游 URL
|
|
StoredKey string // 存储后的 key(本地路径或 S3 key)
|
|
StorageType string // local / s3 / gdrive / 空
|
|
ShareID string
|
|
CharacterInfo *SoraCharacter
|
|
ErrorMessage string
|
|
ErrorType string
|
|
RequestBody []byte
|
|
Seconds string
|
|
Size string
|
|
CreatedAt time.Time
|
|
CompletedAt *time.Time
|
|
}
|
|
|
|
// SoraCharacter 角色信息。
|
|
type SoraCharacter struct {
|
|
Username string `json:"username"`
|
|
DisplayName string `json:"display_name"`
|
|
}
|
|
|
|
// SoraTaskRepository 持久层接口。
|
|
type SoraTaskRepository interface {
|
|
Create(ctx context.Context, task *SoraTask) error
|
|
GetByID(ctx context.Context, id string) (*SoraTask, error)
|
|
GetByIDAndAPIKey(ctx context.Context, id string, apiKeyID int64) (*SoraTask, error)
|
|
Update(ctx context.Context, task *SoraTask) error
|
|
ListPending(ctx context.Context) ([]*SoraTask, error)
|
|
}
|