Skip to content

chore: opt video channel and platform - #1416

Merged
creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/opt-video-channel
Jul 22, 2025
Merged

chore: opt video channel and platform#1416
creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/opt-video-channel

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 22, 2025

Copy link
Copy Markdown
Member

优化视频渠道代码:

  1. 统一视频渠道前置逻辑, 不需要每个渠道判断
  2. 平台从渠道推断,不需要再给每个渠道定义一个平台

Summary by CodeRabbit

  • Refactor
    • Streamlined platform handling by removing specific references to "kling" and "jimeng" platforms throughout the application.
    • Unified relay mode constants for video tasks, simplifying internal logic.
    • Improved dynamic rendering of platform tags in the task logs table for better maintainability and consistency.
    • Enhanced error handling and platform resolution in task update and relay functions.

@coderabbitai

coderabbitai Bot commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change removes explicit support for the "kling" and "jimeng" task platforms and their associated relay modes, consolidating their handling into generic video-related constants, logic, and UI rendering. Platform-specific functions, constants, and code paths are deleted or refactored to use unified video platform handling across backend and frontend components.

Changes

Files/Paths Change Summary
constant/task.go Removed TaskPlatformKling and TaskPlatformJimeng constants.
relay/constant/relay_mode.go Removed Kling/Jimeng relay mode constants and mapping functions; added unified video relay mode constants.
controller/relay.go, controller/task.go Refactored to use generic video relay modes and platform handling; removed explicit Kling/Jimeng cases.
middleware/distributor.go Simplified relay mode assignment for video generations; removed platform-specific logic.
relay/relay_adaptor.go Added GetTaskPlatform; refactored GetTaskAdaptor for unified platform handling; removed Kling/Jimeng specifics.
relay/relay_task.go Updated fallback platform resolution and relay mode mapping for video fetch.
web/src/components/table/task-logs/TaskLogsColumnDefs.js Refactored platform rendering to use CHANNEL_OPTIONS; removed Kling/Jimeng cases from UI rendering.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Middleware
    participant Controller
    participant Relay
    participant TaskAdaptor

    Client->>Middleware: Request (POST/GET /v1/video/generations)
    Middleware->>Controller: Set relay mode (VideoSubmit/VideoFetchByID)
    Controller->>Relay: taskRelayHandler (relay mode)
    Relay->>Relay: GetTaskPlatform (from context)
    Relay->>TaskAdaptor: GetTaskAdaptor (platform)
    TaskAdaptor-->>Relay: Adaptor instance
    Relay->>Controller: Processed result
    Controller->>Client: Response
Loading

Estimated code review effort

3 (~40 minutes)

Possibly related PRs

Suggested reviewers

  • xyfacai

Poem

A hop, a skip, two platforms gone,
Kling and Jimeng, we move along.
Now video tasks are unified,
No more forks or paths to hide.
With streamlined code, the future’s bright—
The rabbit cheers this tidy rewrite! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 057e551 and 7bc9192.

📒 Files selected for processing (8)
  • constant/task.go (0 hunks)
  • controller/relay.go (1 hunks)
  • controller/task.go (1 hunks)
  • middleware/distributor.go (1 hunks)
  • relay/constant/relay_mode.go (1 hunks)
  • relay/relay_adaptor.go (3 hunks)
  • relay/relay_task.go (2 hunks)
  • web/src/components/table/task-logs/TaskLogsColumnDefs.js (2 hunks)
🧠 Learnings (2)
controller/relay.go (1)

Learnt from: 9Ninety
PR: #1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

relay/relay_adaptor.go (1)

Learnt from: 9Ninety
PR: #1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

🧬 Code Graph Analysis (5)
relay/relay_task.go (2)
relay/relay_adaptor.go (1)
  • GetTaskPlatform (104-110)
relay/constant/relay_mode.go (1)
  • RelayModeVideoFetchByID (43-43)
controller/relay.go (1)
relay/constant/relay_mode.go (3)
  • RelayModeSunoFetch (39-39)
  • RelayModeSunoFetchByID (40-40)
  • RelayModeVideoFetchByID (43-43)
controller/task.go (2)
controller/task_video.go (1)
  • UpdateVideoTaskAll (18-25)
common/logger.go (1)
  • SysLog (50-53)
relay/relay_adaptor.go (6)
constant/task.go (2)
  • TaskPlatform (3-3)
  • TaskPlatformSuno (6-6)
relay/channel/task/kling/adaptor.go (1)
  • TaskAdaptor (76-80)
relay/channel/adapter.go (1)
  • TaskAdaptor (31-50)
relay/channel/task/suno/adaptor.go (1)
  • TaskAdaptor (21-23)
relay/channel/task/jimeng/adaptor.go (1)
  • TaskAdaptor (70-75)
constant/channel.go (2)
  • ChannelTypeKling (50-50)
  • ChannelTypeJimeng (51-51)
middleware/distributor.go (1)
relay/constant/relay_mode.go (3)
  • RelayModeUnknown (9-9)
  • RelayModeVideoSubmit (44-44)
  • RelayModeVideoFetchByID (43-43)
💤 Files with no reviewable changes (1)
  • constant/task.go
🧰 Additional context used
🧠 Learnings (2)
controller/relay.go (1)

Learnt from: 9Ninety
PR: #1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

relay/relay_adaptor.go (1)

Learnt from: 9Ninety
PR: #1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

🧬 Code Graph Analysis (5)
relay/relay_task.go (2)
relay/relay_adaptor.go (1)
  • GetTaskPlatform (104-110)
relay/constant/relay_mode.go (1)
  • RelayModeVideoFetchByID (43-43)
controller/relay.go (1)
relay/constant/relay_mode.go (3)
  • RelayModeSunoFetch (39-39)
  • RelayModeSunoFetchByID (40-40)
  • RelayModeVideoFetchByID (43-43)
controller/task.go (2)
controller/task_video.go (1)
  • UpdateVideoTaskAll (18-25)
common/logger.go (1)
  • SysLog (50-53)
relay/relay_adaptor.go (6)
constant/task.go (2)
  • TaskPlatform (3-3)
  • TaskPlatformSuno (6-6)
relay/channel/task/kling/adaptor.go (1)
  • TaskAdaptor (76-80)
relay/channel/adapter.go (1)
  • TaskAdaptor (31-50)
relay/channel/task/suno/adaptor.go (1)
  • TaskAdaptor (21-23)
relay/channel/task/jimeng/adaptor.go (1)
  • TaskAdaptor (70-75)
constant/channel.go (2)
  • ChannelTypeKling (50-50)
  • ChannelTypeJimeng (51-51)
middleware/distributor.go (1)
relay/constant/relay_mode.go (3)
  • RelayModeUnknown (9-9)
  • RelayModeVideoSubmit (44-44)
  • RelayModeVideoFetchByID (43-43)
🔇 Additional comments (11)
web/src/components/table/task-logs/TaskLogsColumnDefs.js (1)

125-132: Excellent consolidation of platform rendering logic.

The dynamic approach using CHANNEL_OPTIONS is much more maintainable than hardcoded platform cases. The consistent use of the Video icon for all matched video platforms provides a unified user experience.

relay/relay_task.go (2)

27-29: Good defensive programming with platform fallback.

The fallback to GetTaskPlatform(c) when the platform string is empty ensures robust platform determination. This aligns well with the unified platform resolution approach described in the AI summary.


184-184: Relay mode consolidation is consistent with the refactor.

Replacing RelayModeKlingFetchByID with RelayModeVideoFetchByID successfully unifies the video platform handling as intended by this PR.

controller/relay.go (1)

431-431: Switch case update aligns with unified video handling.

The replacement of platform-specific relay mode with RelayModeVideoFetchByID is consistent with the broader consolidation effort and maintains the same functional behavior.

controller/task.go (1)

79-81: Good consolidation with improved error handling.

Moving UpdateVideoTaskAll to the default case effectively handles all video platforms (including the previously explicit kling/jimeng cases) while adding proper error logging that was missing before. This is both a simplification and an improvement.

middleware/distributor.go (1)

177-183: Excellent simplification of video generation request handling.

The new approach is much cleaner:

  • Direct HTTP method-based relay mode assignment eliminates complex platform-specific parsing
  • Setting shouldSelectChannel = false for GET requests (fetch operations) is appropriate
  • Removes dependency on model name prefixes for platform determination

This change successfully achieves the PR objective of unifying video channel preprocessing logic.

relay/constant/relay_mode.go (1)

43-44: LGTM! Good consolidation of platform-specific relay modes.

The unified RelayModeVideoFetchByID and RelayModeVideoSubmit constants effectively replace the platform-specific Kling and Jimeng relay modes, simplifying the codebase while maintaining functionality.

relay/relay_adaptor.go (4)

4-4: Import addition looks good.

The github.com/gin-gonic/gin import is needed for the new GetTaskPlatform function.


37-37: Import addition looks good.

The strconv import is needed for the integer-to-string conversions in the new platform handling logic.


112-128: The unified platform handling approach is well-designed.

The refactored GetTaskAdaptor function effectively handles the transition from platform-specific constants to a more flexible approach. The fallback to numeric channel type parsing maintains backward compatibility while supporting the unified video platform approach.

The logic correctly:

  1. Handles the explicit TaskPlatformSuno case
  2. Attempts to parse the platform as an integer for numeric channel types
  3. Maps ChannelTypeKling and ChannelTypeJimeng to their respective adaptors

104-110: Ignore platform extraction inconsistency concern

I verified that GetTaskPlatform returns a numeric string when channel_type is set, and the NewTaskAdaptor logic first parses that numeric string back to an integer to route to the proper channel adaptor. If parsing fails, it falls back to the string constants ("suno", "mj", etc.). No other parts of the code compare the raw platform string in a way that would break under this dual representation, so the existing logic is consistent and no changes are needed.

Likely an incorrect or invalid review comment.

Sparkles
} from 'lucide-react';
import { TASK_ACTION_GENERATE, TASK_ACTION_TEXT_GENERATE } from '../../../constants/common.constant';
import { CHANNEL_OPTIONS } from '../../../constants/channel.constants';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify CHANNEL_OPTIONS import and usage.

Ensure that the imported CHANNEL_OPTIONS from channel.constants contains the expected video platform entries with proper value, label, and color properties.


🏁 Script executed:

#!/bin/bash
# Description: Verify CHANNEL_OPTIONS structure and content for video platforms
# Expected: Find CHANNEL_OPTIONS export with video platform configurations

echo "Searching for CHANNEL_OPTIONS definition:"
fd -e js -e ts -e jsx -e tsx channel.constants --exec cat {} \; | grep -A 20 "CHANNEL_OPTIONS"

echo -e "\nSearching for video platform references in constants:"
rg -A 5 -B 5 "video|Video|kling|jimeng" --type js --type ts

Length of output: 9039


CHANNEL_OPTIONS missing video platform entries

It looks like CHANNEL_OPTIONS (in web/src/constants/channel.constants.js) currently only includes providers such as OpenAI, Midjourney Proxy, Suno API, Ollama, etc., but no entries for our video platforms (e.g. Kling, Jimeng). The renderPlatform function in TaskLogsColumnDefs.js uses these options to render the correct tag, so we need to add the missing video‐task channels.

Please update web/src/constants/channel.constants.js to include the video platform entries with unique values, descriptive labels, and appropriate colors. For example:

 export const CHANNEL_OPTIONS = [
   { value: 1,  color: 'green',      label: 'OpenAI' },
   { value: 2,  color: 'light-blue', label: 'Midjourney Proxy' },
   { value: 5,  color: 'blue',       label: 'Midjourney Proxy Plus' },
   { value: 36, color: 'purple',     label: 'Suno API' },
   { value: 4,  color: 'grey',       label: 'Ollama' },
   { value: 14, color: 'indigo',     label: '…' },
+  { value: XX, color: 'orange',     label: 'Kling' },
+  { value: YY, color: 'teal',       label: 'Jimeng' },
   // …any other channels
 ];

• Ensure each new entry has a unique numeric value.
• Pick distinct, accessible color strings.
• Match the label exactly to how you want it displayed in the UI.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In web/src/constants/channel.constants.js, add new entries for the missing video
platforms such as Kling and Jimeng to the CHANNEL_OPTIONS array. Each entry
should have a unique numeric value, a label matching the platform name exactly
as it should appear in the UI, and an accessible color string distinct from
existing entries. This will ensure the renderPlatform function in
TaskLogsColumnDefs.js can correctly display tags for these video platforms.

@creamlike1024
creamlike1024 merged commit 07b64ff into QuantumNous:alpha Jul 22, 2025
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 26, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Mar 28, 2026
Closed
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…nnel

chore: opt video channel and platform
@coderabbitai coderabbitai Bot mentioned this pull request May 11, 2026
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants