(c *gin.Context)
| 672 | } |
| 673 | |
| 674 | func UpdateChannel(c *gin.Context) { |
| 675 | channel := PatchChannel{} |
| 676 | err := c.ShouldBindJSON(&channel) |
| 677 | if err != nil { |
| 678 | common.ApiError(c, err) |
| 679 | return |
| 680 | } |
| 681 | |
| 682 | // 使用统一的校验函数 |
| 683 | if err := validateChannel(&channel.Channel, false); err != nil { |
| 684 | c.JSON(http.StatusOK, gin.H{ |
| 685 | "success": false, |
| 686 | "message": err.Error(), |
| 687 | }) |
| 688 | return |
| 689 | } |
| 690 | // Preserve existing ChannelInfo to ensure multi-key channels keep correct state even if the client does not send ChannelInfo in the request. |
| 691 | originChannel, err := model.GetChannelById(channel.Id, false) |
| 692 | if err != nil { |
| 693 | c.JSON(http.StatusOK, gin.H{ |
| 694 | "success": false, |
| 695 | "message": err.Error(), |
| 696 | }) |
| 697 | return |
| 698 | } |
| 699 | |
| 700 | // Always copy the original ChannelInfo so that fields like IsMultiKey and MultiKeySize are retained. |
| 701 | channel.ChannelInfo = originChannel.ChannelInfo |
| 702 | |
| 703 | // If the request explicitly specifies a new MultiKeyMode, apply it on top of the original info. |
| 704 | if channel.MultiKeyMode != nil && *channel.MultiKeyMode != "" { |
| 705 | channel.ChannelInfo.MultiKeyMode = constant.MultiKeyMode(*channel.MultiKeyMode) |
| 706 | } |
| 707 | err = channel.Update() |
| 708 | if err != nil { |
| 709 | common.ApiError(c, err) |
| 710 | return |
| 711 | } |
| 712 | model.InitChannelCache() |
| 713 | channel.Key = "" |
| 714 | c.JSON(http.StatusOK, gin.H{ |
| 715 | "success": true, |
| 716 | "message": "", |
| 717 | "data": channel, |
| 718 | }) |
| 719 | return |
| 720 | } |
| 721 | |
| 722 | func FetchModels(c *gin.Context) { |
| 723 | var req struct { |
nothing calls this directly
no test coverage detected