🐛 fix: preserve key data when editing channels & update MultiKeySize correctly

Backend
• `model/channel.go`
  – On multi-key channel updates, recalculate `MultiKeySize` from the current key list.
  – If the request omits `key`, fetch existing keys from DB to avoid resetting the count to `0/0`.
  – Remove out-of-range entries from `MultiKeyStatusList` to keep data consistent.

Frontend
• `web/src/pages/Channel/EditChannel.js`
  – Vertex AI channels no longer require re-uploading a key file in edit mode.
  – When no new key is provided during editing, exclude the `key` field from the payload to prevent overwriting the stored value.

These changes ensure that editing a channel no longer zeroes out the enabled key counter and that Vertex AI channels can be modified without mandatory key re-submission.
This commit is contained in:
t0ng7u
2025-07-13 00:09:27 +08:00
parent 203edaed50
commit d22ee5d451
2 changed files with 35 additions and 10 deletions

View File

@@ -398,7 +398,19 @@ func (channel *Channel) Insert() error {
func (channel *Channel) Update() error {
// 如果是多密钥渠道,则根据当前 key 列表重新计算 MultiKeySize避免编辑密钥后数量未同步
if channel.ChannelInfo.IsMultiKey {
keys := channel.getKeys()
var keyStr string
if channel.Key != "" {
keyStr = channel.Key
} else {
// 如果当前未提供 key读取数据库中的现有 key
if existing, err := GetChannelById(channel.Id, true); err == nil {
keyStr = existing.Key
}
}
keys := []string{}
if keyStr != "" {
keys = strings.Split(strings.Trim(keyStr, "\n"), "\n")
}
channel.ChannelInfo.MultiKeySize = len(keys)
// 清理超过新 key 数量范围的状态数据,防止索引越界
if channel.ChannelInfo.MultiKeyStatusList != nil {