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

Function SetTaskPluginStatus

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

Source from the content-addressed store, hash-verified

492}
493
494func SetTaskPluginStatus(c *gin.Context) {
495 var request taskPluginStatusRequest
496 if err := c.ShouldBindJSON(&request); err != nil || request.Enabled == nil {
497 common.ApiErrorMsg(c, "enabled is required")
498 return
499 }
500 key := c.Param("key")
501 disabledChannels := 0
502 if !*request.Enabled {
503 channels, inFlight, usageErr := model.GetTaskPluginUsage(key)
504 if usageErr != nil {
505 common.ApiError(c, usageErr)
506 return
507 }
508 cascade := c.Query("cascade") == "true"
509 force := c.Query("force") == "true"
510 if (len(channels) > 0 && !cascade) || (inFlight > 0 && !force) {
511 c.JSON(200, gin.H{"success": false, "message": "task plugin is still in use", "data": gin.H{"channels": channels, "in_flight_count": inFlight}})
512 return
513 }
514 if cascade {
515 for _, channel := range channels {
516 if model.UpdateChannelStatus(channel.Id, "", common.ChannelStatusManuallyDisabled, "task plugin disabled") {
517 disabledChannels++
518 }
519 }
520 }
521 }
522 _, lookupErr := model.GetTaskPluginVersion(key, "")
523 hasActiveOverride := lookupErr == nil
524 if lookupErr != nil && !errors.Is(lookupErr, gorm.ErrRecordNotFound) {
525 common.ApiError(c, lookupErr)
526 return
527 }
528 // Switching a key off must silence every layer that can serve it. The
529 // factory built-in goes into the disabled set even when an override row
530 // exists; otherwise the built-in would keep routing the same models (and
531 // blocking same-model uploads) right after the administrator disabled the
532 // plugin. Switching on reverses both layers.
533 if taskPluginHasFactory(key) {
534 keys := setting.GetTaskPluginDisabledFactoryKeys()
535 if *request.Enabled {
536 next := make([]string, 0, len(keys))
537 for _, item := range keys {
538 if item != key {
539 next = append(next, item)
540 }
541 }
542 keys = next
543 } else {
544 keys = append(append([]string{}, keys...), key)
545 }
546 if err := setting.SetTaskPluginDisabledFactoryKeysOption(keys); err != nil {
547 common.ApiError(c, err)
548 return
549 }
550 encoded, err := common.Marshal(setting.GetTaskPluginDisabledFactoryKeys())
551 if err != nil {

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