mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 15:06:36 +00:00
feat: add Sora async task API (videos/images)
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>
This commit is contained in:
1 parent
4fb58c66c4
commit
8c412b32d1
11 files changed
+1348
-2
No files matched your search
@@ -0,0 +1,63 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user