🐛 fix: synchronize MultiKeySize after editing multi-key channels

1. Recalculate `ChannelInfo.MultiKeySize` based on the current key list when a multi-key channel is updated.
2. Purge any indexes in `MultiKeyStatusList` that exceed the new key count to avoid stale or out-of-range data.

This ensures the front-end display (`enabled x/x`) always reflects the real number of keys after users add or remove keys in edit mode.
This commit is contained in:
t0ng7u
2025-07-12 23:57:59 +08:00
parent 93b5638a9c
commit 203edaed50

View File

@@ -396,6 +396,19 @@ func (channel *Channel) Insert() error {
}
func (channel *Channel) Update() error {
// 如果是多密钥渠道,则根据当前 key 列表重新计算 MultiKeySize避免编辑密钥后数量未同步
if channel.ChannelInfo.IsMultiKey {
keys := channel.getKeys()
channel.ChannelInfo.MultiKeySize = len(keys)
// 清理超过新 key 数量范围的状态数据,防止索引越界
if channel.ChannelInfo.MultiKeyStatusList != nil {
for idx := range channel.ChannelInfo.MultiKeyStatusList {
if idx >= channel.ChannelInfo.MultiKeySize {
delete(channel.ChannelInfo.MultiKeyStatusList, idx)
}
}
}
}
var err error
err = DB.Model(channel).Updates(channel).Error
if err != nil {