Skip to content

feat: EditTagModal header && param - #2159

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/channel_edit_tag
Nov 6, 2025
Merged

feat: EditTagModal header && param#2159
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/channel_edit_tag

Conversation

@seefs001

@seefs001 seefs001 commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator

#2100

Summary by CodeRabbit

  • New Features
    • Channel tags now support optional parameter and header overrides for granular request/response control
    • New "Advanced Settings" panel in tag editor with dedicated fields for override configuration
    • Includes JSON validation and example templates to guide users

@coderabbitai

coderabbitai Bot commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes extend channel tag editing to support optional JSON-based parameter and header overrides. New fields are added to the ChannelTag struct with controller-layer validation, passed through the model layer, and exposed in the UI with an "Advanced Settings" section for user input.

Changes

Cohort / File(s) Summary
Controller validation
controller/channel.go
ChannelTag struct expanded with ParamOverride and HeaderOverride optional fields; EditTagChannels workflow adds JSON validation for both fields with specific error responses; updated call to model.EditChannelByTag to pass the new parameters
Model layer
model/channel.go
EditChannelByTag function signature extended with paramOverride and headerOverride parameters; these values are assigned to updateData when provided
Frontend form
web/src/components/table/channels/modals/EditTagModal.jsx
Added param_override and header_override state fields with JSON validation; new "Advanced Settings" card with TextArea inputs for both overrides; submission logic updated to include these fields in payload when provided

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as EditTagModal
    participant Controller as EditTagChannels
    participant Model as EditChannelByTag
    participant DB as Database

    User->>UI: Fill param_override & header_override
    UI->>UI: Validate JSON format
    alt Invalid JSON
        UI->>User: Show error message
    else Valid JSON
        User->>UI: Submit form
        UI->>Controller: POST with ParamOverride,<br/>HeaderOverride
        Controller->>Controller: Validate JSON fields
        alt Invalid JSON in backend
            Controller->>UI: Error response
            UI->>User: Display error
        else Valid
            Controller->>Model: Call EditChannelByTag<br/>with overrides
            Model->>Model: Assign to updateData
            Model->>DB: Update channel record
            DB-->>Model: Success
            Model-->>Controller: Confirmation
            Controller-->>UI: Success response
            UI->>User: Display success
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Controller validation logic: Verify JSON validation implementation and error handling for ParamOverride and HeaderOverride
  • Model parameter propagation: Confirm correct assignment of override values to updateData structure
  • Frontend form state management: Review form submission logic to ensure overrides are only sent when present and unchanged values are properly handled

Possibly related PRs

Poem

🐰 Override fields now sprouting bright,
JSON validated, holding tight,
Headers dance, params bend,
Advanced settings round the end!
Channel tags in digital delight!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The pull request title 'feat: EditTagModal header && param' uses shorthand notation ('&&' and abbreviated terms like 'param') that reduces clarity. While it attempts to capture the main changes (adding header and param override functionality to EditTagModal), the abbreviated phrasing makes it less immediately clear what the changeset accomplishes. The title references specific components but lacks descriptive clarity about the actual feature being added—that users can now configure per-tag request/response overrides. Consider clarifying the title to be more descriptive and use complete terms, such as 'feat: Add header and param override options to EditTagModal' or 'feat: Enable per-tag override configuration in EditTagModal'. This would make the purpose of the change immediately clear to developers reviewing the commit history without requiring them to infer the meaning of abbreviated notation.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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: 2

🧹 Nitpick comments (2)
model/channel.go (1)

691-722: Consider consistent empty string handling for optional parameters.

The new paramOverride and headerOverride parameters (lines 717, 720) only check != nil, whereas other optional string parameters like modelMapping, models, and group (lines 700, 703, 707) check both != nil and != "".

If empty strings should be allowed to explicitly clear these fields, the current behavior is correct. Otherwise, consider aligning with the existing pattern:

 if paramOverride != nil {
+  if *paramOverride != "" {
     updateData.ParamOverride = paramOverride
+  }
 }
 if headerOverride != nil {
+  if *headerOverride != "" {
     updateData.HeaderOverride = headerOverride
+  }
 }
web/src/components/table/channels/modals/EditTagModal.jsx (1)

196-229: Consider extracting validation logic into a helper function.

The validation logic for param_override (lines 196-211) and header_override (lines 213-229) is highly repetitive. Consider extracting to reduce duplication:

const validateJSONOverride = (value, fieldName) => {
  if (value !== undefined && value !== null) {
    if (typeof value !== 'string') {
      showInfo(t(`${fieldName}必须是合法的 JSON 格式!`));
      return false;
    }
    const trimmed = value.trim();
    if (trimmed !== '' && !verifyJSON(trimmed)) {
      showInfo(t(`${fieldName}必须是合法的 JSON 格式!`));
      return false;
    }
    return trimmed;
  }
  return null;
};

// Then use:
const paramOverride = validateJSONOverride(formVals.param_override, '参数覆盖');
if (paramOverride === false) {
  setLoading(false);
  return;
}
if (paramOverride !== null) {
  data.param_override = paramOverride;
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00782aa and 310af68.

📒 Files selected for processing (3)
  • controller/channel.go (2 hunks)
  • model/channel.go (2 hunks)
  • web/src/components/table/channels/modals/EditTagModal.jsx (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-27T02:15:25.448Z
Learnt from: AAEE86
Repo: QuantumNous/new-api PR: 1658
File: web/src/components/table/channels/modals/EditChannelModal.jsx:555-569
Timestamp: 2025-08-27T02:15:25.448Z
Learning: In EditChannelModal.jsx, the database stores mapped keys (display names) in the models field after applying model mapping transformations. When loading a channel, data.models contains the mapped keys, not the original model names. The filtering logic if (data.models.includes(key)) in the initialization is correct.

Applied to files:

  • web/src/components/table/channels/modals/EditTagModal.jsx
🧬 Code graph analysis (2)
controller/channel.go (2)
common/utils.go (1)
  • GetPointer (292-294)
model/channel.go (1)
  • EditChannelByTag (691-745)
web/src/components/table/channels/modals/EditTagModal.jsx (2)
web/src/helpers/utils.jsx (1)
  • showInfo (161-163)
web/src/components/table/channels/modals/EditChannelModal.jsx (1)
  • handleInputChange (365-444)
🔇 Additional comments (2)
web/src/components/table/channels/modals/EditTagModal.jsx (1)

533-682: LGTM! Well-structured advanced settings UI.

The new "Advanced Settings" section provides clear templates, helpful examples, and variable documentation. The UI patterns are consistent with existing code and the extraText guidance is particularly helpful for users.

controller/channel.go (1)

726-747: Excellent validation logic with proper trimming and pointer handling.

The validation correctly:

  • Trims whitespace before validation
  • Validates JSON format using json.Valid
  • Allows empty strings to pass through (which can clear the field)
  • Creates fresh pointers with common.GetPointer[string](trimmed) to avoid aliasing issues

The logic is consistent with frontend validation and properly guards against malformed JSON.

Comment thread controller/channel.go
}
channelTag.HeaderOverride = common.GetPointer[string](trimmed)
}
err = model.EditChannelByTag(channelTag.Tag, channelTag.NewTag, channelTag.ModelMapping, channelTag.Models, channelTag.Groups, channelTag.Priority, channelTag.Weight, channelTag.ParamOverride, channelTag.HeaderOverride)

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify function call has correct parameter order.

The call to model.EditChannelByTag now passes 9 parameters. Let me verify this matches the function signature.


🏁 Script executed:

#!/bin/bash
# Verify the EditChannelByTag function signature matches the call
rg -A 2 'func EditChannelByTag' --type go

Length of output: 298


Fix parameter name mismatch: pass channelTag.Group (singular) instead of channelTag.Groups (plural).

The function signature expects group *string as the 5th parameter, but the call passes channelTag.Groups. This singular/plural mismatch indicates the wrong field is being passed to the function.

🤖 Prompt for AI Agents
In controller/channel.go around line 748, the call to model.EditChannelByTag
passes channelTag.Models (4th) and channelTag.Groups (5th) but the function
signature expects the 5th parameter to be group *string (singular). Replace the
channelTag.Groups argument with channelTag.Group (singular) so the correct
field/type is passed; ensure channelTag.Group is a *string (or take its address)
and handle nil appropriately if required by the model.EditChannelByTag contract.

Comment on lines +196 to +229
if (
formVals.param_override !== undefined &&
formVals.param_override !== null
) {
if (typeof formVals.param_override !== 'string') {
showInfo('参数覆盖必须是合法的 JSON 格式!');
setLoading(false);
return;
}
const trimmedParamOverride = formVals.param_override.trim();
if (trimmedParamOverride !== '' && !verifyJSON(trimmedParamOverride)) {
showInfo('参数覆盖必须是合法的 JSON 格式!');
setLoading(false);
return;
}
data.param_override = trimmedParamOverride;
}
if (
formVals.header_override !== undefined &&
formVals.header_override !== null
) {
if (typeof formVals.header_override !== 'string') {
showInfo('请求头覆盖必须是合法的 JSON 格式!');
setLoading(false);
return;
}
const trimmedHeaderOverride = formVals.header_override.trim();
if (trimmedHeaderOverride !== '' && !verifyJSON(trimmedHeaderOverride)) {
showInfo('请求头覆盖必须是合法的 JSON 格式!');
setLoading(false);
return;
}
data.header_override = trimmedHeaderOverride;
}

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.

🛠️ Refactor suggestion | 🟠 Major

Internationalize validation error messages.

The validation error messages at lines 201, 207-208, 218, and 224-225 are hardcoded in Chinese, but the rest of the file consistently uses the t() translation function.

       if (typeof formVals.param_override !== 'string') {
-        showInfo('参数覆盖必须是合法的 JSON 格式!');
+        showInfo(t('参数覆盖必须是合法的 JSON 格式!'));
         setLoading(false);
         return;
       }
       const trimmedParamOverride = formVals.param_override.trim();
       if (trimmedParamOverride !== '' && !verifyJSON(trimmedParamOverride)) {
-        showInfo('参数覆盖必须是合法的 JSON 格式!');
+        showInfo(t('参数覆盖必须是合法的 JSON 格式!'));
         setLoading(false);
         return;
       }

Apply similar changes for header_override messages at lines 218, 224-225.

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

🤖 Prompt for AI Agents
In web/src/components/table/channels/modals/EditTagModal.jsx around lines 196 to
229, the validation messages for param_override and header_override are
hardcoded in Chinese; replace those four fixed strings with calls to the
translation function t(...) to match the file's i18n pattern. Specifically,
change the messages at lines ~201 and ~207-208 for param_override and at ~218
and ~224-225 for header_override to use t(...) (use the existing translation
keys used elsewhere in this file for JSON/validation errors or add new keys in
the locale files and call them here), keeping the same control flow and
setLoading(false)/return behavior intact.

@Calcium-Ion
Calcium-Ion merged commit 019412c into QuantumNous:main Nov 6, 2025
1 check passed
Xiaoshuaiawd referenced this pull request in Xiaoshuaiawd/new-api Nov 12, 2025
* main: (77 commits)
  refactor(adaptor): Comment out enable_thinking logic for clarity and future adjustments
  fix GetChannelKey AdminAuth -> RootAuth
  fix GetChannelKey AdminAuth -> RootAuth
  feat: vidu reference2video only viduq2
  feat: vidu specify reference2video via metadata action
  同步多语言README文档
  chore: Update README.md for improved structure and clarity, including new sections for partners, acknowledgments, and deployment instructions
  feat: replicate channel flux model
  feat: ShouldPreserveThinkingSuffix (#2189)
  fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
  fix: update tag normalization regex
  feat: restrict automatic channel testing to master node only
  feat: EditTagModal header && param (#2159)
  add custom tool (#2157)
  fix playground (#2153)
  feat: add TASK_PRICE_PATCH environment variable for per-task billing configuration
  feat:  EditTokenModal 中针对用户创建的 token 默认无限额度
  feat: add environment variable switch for critical rate limit
  feat: enhance Ali video request processing with resolution mapping and size validation
  fix: logger
  ...
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
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