MCPcopy Create free account
hub / github.com/QuantumNous/new-api / SetTaskPluginStatus

Function SetTaskPluginStatus

controller/task_plugin.go:712–820  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

710}
711
712func SetTaskPluginStatus(c *gin.Context) {
713 var request taskPluginStatusRequest
714 if err := c.ShouldBindJSON(&request); err != nil || request.Enabled == nil {
715 common.ApiErrorMsg(c, "enabled is required")
716 return
717 }
718 key := c.Param("key")
719 disabledChannels := 0
720 unboundChannels := 0
721 if !*request.Enabled {
722 channels, inFlight, usageErr := model.GetTaskPluginUsage(key)
723 if usageErr != nil {
724 common.ApiError(c, usageErr)
725 return
726 }
727 cascade := c.Query("cascade") == "true"
728 force := c.Query("force") == "true"
729 if (len(channels) > 0 && !cascade) || (inFlight > 0 && !force) {
730 c.JSON(200, gin.H{"success": false, "message": "task plugin is still in use", "data": gin.H{"channels": channels, "in_flight_count": inFlight}})
731 return
732 }
733 if cascade {
734 for _, channel := range channels {
735 if channel.Type == constant.ChannelTypeNewAPI {
736 // A gateway channel also carries ordinary traffic, so the
737 // cascade only drops this plugin from its bindings.
738 unbound, unbindErr := model.UnbindTaskPlugin(channel.Id, key)
739 if unbindErr != nil {
740 common.ApiError(c, unbindErr)
741 return
742 }
743 if unbound {
744 unboundChannels++
745 }
746 continue
747 }
748 if model.UpdateChannelStatus(channel.Id, "", common.ChannelStatusManuallyDisabled, "task plugin disabled") {
749 disabledChannels++
750 }
751 }
752 if unboundChannels > 0 {
753 model.InitChannelCache()
754 }
755 }
756 }
757 active, lookupErr := model.GetTaskPluginVersion(key, "")
758 hasActiveOverride := lookupErr == nil
759 if lookupErr != nil && !errors.Is(lookupErr, gorm.ErrRecordNotFound) {
760 common.ApiError(c, lookupErr)
761 return
762 }
763 // Switching on serves the active version, or the factory built-in when the
764 // key has none.
765 if *request.Enabled && rejectTaskPluginRoutingConflict(c, key, active) {
766 return
767 }
768 response := gin.H{"plugin_enabled": *request.Enabled, "disabled_channels": disabledChannels, "unbound_channels": unboundChannels}
769 // Switching a key off must silence every layer that can serve it. The

Calls 15

ApiErrorMsgFunction · 0.92
GetTaskPluginUsageFunction · 0.92
ApiErrorFunction · 0.92
UnbindTaskPluginFunction · 0.92
UpdateChannelStatusFunction · 0.92
InitChannelCacheFunction · 0.92
GetTaskPluginVersionFunction · 0.92
MarshalFunction · 0.92
UpdateOptionFunction · 0.92
ApiSuccessFunction · 0.92