feat: EditTagModal header && param - #2159
Conversation
WalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 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: 2
🧹 Nitpick comments (2)
model/channel.go (1)
691-722: Consider consistent empty string handling for optional parameters.The new
paramOverrideandheaderOverrideparameters (lines 717, 720) only check!= nil, whereas other optional string parameters likemodelMapping,models, andgroup(lines 700, 703, 707) check both!= niland!= "".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) andheader_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
📒 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 issuesThe logic is consistent with frontend validation and properly guards against malformed JSON.
| } | ||
| 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) |
There was a problem hiding this comment.
🧩 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 goLength 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.
| 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; | ||
| } |
There was a problem hiding this comment.
🛠️ 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.
* 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 ...
#2100
Summary by CodeRabbit