支持Sora做为上游渠道 - #1997
Conversation
WalkthroughAdds GET support for fetching video tasks by ID in /v1/videos, sets relay mode accordingly without channel selection, and updates the Sora task adaptor to return a full response object with TaskID fallback. Introduces a new router route GET /videos/:task_id sharing the existing RelayTask handler. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor C as Client
participant R as v1 Router
participant D as Distributor (Middleware)
participant H as RelayTask Handler
participant A as Sora Adaptor
participant S as Upstream Sora
rect rgb(245,248,255)
note over C,R: New flow: GET /v1/videos/:task_id
C->>R: GET /videos/{task_id}
R->>D: Route request
D->>D: Set relayMode=VideoFetchByID<br/>shouldSelectChannel=false
D->>H: Forward with task_id
end
H->>A: Fetch task by ID
A->>S: Request task status/result
S-->>A: Response
A-->>H: Full responseTask JSON (with TaskID/ID)
H-->>C: HTTP 200 + responseTask
alt POST /v1/videos (existing)
C->>R: POST /videos
R->>D: Route request
D->>D: Select channel (normal flow)
D->>H: Create task
H->>A: Submit generation task
A->>S: Create task
S-->>A: Ack with task_id
A-->>H: responseTask JSON
H-->>C: HTTP 200 + task info
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
relay/channel/task/sora/adaptor.go (1)
115-121: Improve error message clarity.The error message at line 116 says "task_id is empty", but at this point both
IDandTaskIDare confirmed to be empty. The message should reflect that both identifiers are missing.Apply this diff to clarify the error:
if dResp.ID == "" { if dResp.TaskID == "" { - taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError) + taskErr = service.TaskErrorWrapper(fmt.Errorf("both id and task_id are empty"), "invalid_response", http.StatusInternalServerError) return } dResp.ID = dResp.TaskID dResp.TaskID = "" }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
middleware/distributor.go(1 hunks)relay/channel/task/sora/adaptor.go(2 hunks)router/video-router.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
middleware/distributor.go (2)
dto/request_common.go (1)
Request(8-12)relay/constant/relay_mode.go (1)
RelayModeVideoFetchByID(43-43)
relay/channel/task/sora/adaptor.go (1)
service/error.go (1)
TaskErrorWrapper(139-155)
router/video-router.go (1)
controller/relay.go (1)
RelayTask(383-426)
🔇 Additional comments (4)
router/video-router.go (1)
22-22: LGTM! Route follows established pattern.The new GET route for
/videos/:task_idcorrectly reuses the existingRelayTaskhandler and mirrors the pattern used for/video/generations/:task_idat line 16. This aligns with OpenAI's video API conventions.middleware/distributor.go (1)
187-189: LGTM! Fetch-by-ID handling follows established pattern.The GET request handling correctly:
- Sets relay mode to
VideoFetchByID- Disables channel selection (
shouldSelectChannel = false)This mirrors the pattern used for Midjourney (lines 131-135) and Suno (lines 159-161) fetch operations, where tasks are already associated with a channel.
relay/channel/task/sora/adaptor.go (2)
37-37: LGTM! Backward compatibility field added correctly.The
TaskIDfield withomitemptytag properly supports the old interface while the mainIDfield serves as the primary identifier. Theomitemptyensurestask_idonly appears in responses when explicitly populated by upstream sources.
123-123: Confirm consumer compatibility with expanded response schema
GET /v1/videos/{task_id} now returns the fullresponseTaskobject instead of a minimal payload; verify all downstream consumers (SDKs, integrations, downstream services) can correctly process the expanded response format.
…h-task 支持Sora做为上游渠道
Summary by CodeRabbit
New Features
Refactor