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

Function SetTaskPluginStatus

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

Source from the content-addressed store, hash-verified

440}
441
442func SetTaskPluginStatus(c *gin.Context) {
443 var request taskPluginStatusRequest
444 if err := c.ShouldBindJSON(&request); err != nil || request.Enabled == nil {
445 common.ApiErrorMsg(c, "enabled is required")
446 return
447 }
448 key := c.Param("key")
449 disabledChannels := 0
450 if !*request.Enabled {
451 channels, inFlight, usageErr := model.GetTaskPluginUsage(key)
452 if usageErr != nil {
453 common.ApiError(c, usageErr)
454 return
455 }
456 cascade := c.Query("cascade") == "true"
457 force := c.Query("force") == "true"
458 if (len(channels) > 0 && !cascade) || (inFlight > 0 && !force) {
459 c.JSON(200, gin.H{"success": false, "message": "task plugin is still in use", "data": gin.H{"channels": channels, "in_flight_count": inFlight}})
460 return
461 }
462 if cascade {
463 for _, channel := range channels {
464 if model.UpdateChannelStatus(channel.Id, "", common.ChannelStatusManuallyDisabled, "task plugin disabled") {
465 disabledChannels++
466 }
467 }
468 }
469 }
470 _, lookupErr := model.GetTaskPluginVersion(key, "")
471 hasActiveOverride := lookupErr == nil
472 if lookupErr != nil && !errors.Is(lookupErr, gorm.ErrRecordNotFound) {
473 common.ApiError(c, lookupErr)
474 return
475 }
476 // The disabled set suppresses only the factory fallback layer. An enabled
477 // override for the same key keeps serving and is toggled independently.
478 if taskPluginHasFactory(key) && !hasActiveOverride {
479 keys := setting.GetTaskPluginDisabledFactoryKeys()
480 if *request.Enabled {
481 next := make([]string, 0, len(keys))
482 for _, item := range keys {
483 if item != key {
484 next = append(next, item)
485 }
486 }
487 keys = next
488 } else {
489 keys = append(append([]string{}, keys...), key)
490 }
491 if err := setting.SetTaskPluginDisabledFactoryKeysOption(keys); err != nil {
492 common.ApiError(c, err)
493 return
494 }
495 encoded, err := common.Marshal(setting.GetTaskPluginDisabledFactoryKeys())
496 if err != nil {
497 common.ApiError(c, err)
498 return
499 }

Calls 14

ApiErrorMsgFunction · 0.92
GetTaskPluginUsageFunction · 0.92
ApiErrorFunction · 0.92
UpdateChannelStatusFunction · 0.92
GetTaskPluginVersionFunction · 0.92
MarshalFunction · 0.92
UpdateOptionFunction · 0.92
ApiSuccessFunction · 0.92
SetTaskPluginEnabledFunction · 0.92
taskPluginHasFactoryFunction · 0.85