MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / EditChannelByTag

Function EditChannelByTag

model/channel.go:640–688  ·  view source on GitHub ↗
(tag string, newTag *string, modelMapping *string, models *string, group *string, priority *int64, weight *uint)

Source from the content-addressed store, hash-verified

638}
639
640func EditChannelByTag(tag string, newTag *string, modelMapping *string, models *string, group *string, priority *int64, weight *uint) error {
641 updateData := Channel{}
642 shouldReCreateAbilities := false
643 updatedTag := tag
644 // 如果 newTag 不为空且不等于 tag,则更新 tag
645 if newTag != nil && *newTag != tag {
646 updateData.Tag = newTag
647 updatedTag = *newTag
648 }
649 if modelMapping != nil && *modelMapping != "" {
650 updateData.ModelMapping = modelMapping
651 }
652 if models != nil && *models != "" {
653 shouldReCreateAbilities = true
654 updateData.Models = *models
655 }
656 if group != nil && *group != "" {
657 shouldReCreateAbilities = true
658 updateData.Group = *group
659 }
660 if priority != nil {
661 updateData.Priority = priority
662 }
663 if weight != nil {
664 updateData.Weight = weight
665 }
666
667 err := DB.Model(&Channel{}).Where("tag = ?", tag).Updates(updateData).Error
668 if err != nil {
669 return err
670 }
671 if shouldReCreateAbilities {
672 channels, err := GetChannelsByTag(updatedTag, false)
673 if err == nil {
674 for _, channel := range channels {
675 err = channel.UpdateAbilities(nil)
676 if err != nil {
677 common.SysError("failed to update abilities: " + err.Error())
678 }
679 }
680 }
681 } else {
682 err := UpdateAbilityByTag(tag, newTag, priority, weight)
683 if err != nil {
684 return err
685 }
686 }
687 return nil
688}
689
690func UpdateChannelUsedQuota(id int, quota int) {
691 if common.BatchUpdateEnabled {

Callers 1

EditTagChannelsFunction · 0.92

Calls 5

SysErrorFunction · 0.92
GetChannelsByTagFunction · 0.85
UpdateAbilityByTagFunction · 0.85
UpdateAbilitiesMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected