| 356 | } |
| 357 | |
| 358 | func DeleteTaskPluginVersion(c *gin.Context) { |
| 359 | key := c.Param("key") |
| 360 | version := c.Param("version") |
| 361 | plugin, lookupErr := model.GetTaskPluginVersion(key, version) |
| 362 | if lookupErr != nil { |
| 363 | if errors.Is(lookupErr, gorm.ErrRecordNotFound) { |
| 364 | common.ApiErrorMsg(c, "override plugin version not found; factory plugins cannot be deleted") |
| 365 | return |
| 366 | } |
| 367 | common.ApiError(c, lookupErr) |
| 368 | return |
| 369 | } |
| 370 | if plugin.Active && !taskPluginHasFactory(key) { |
| 371 | channels, inFlight, usageErr := model.GetTaskPluginUsage(key) |
| 372 | if usageErr != nil { |
| 373 | common.ApiError(c, usageErr) |
| 374 | return |
| 375 | } |
| 376 | if (len(channels) > 0 || inFlight > 0) && c.Query("force") != "true" { |
| 377 | c.JSON(200, gin.H{"success": false, "message": "task plugin is still in use", "data": gin.H{"channels": channels, "in_flight_count": inFlight}}) |
| 378 | return |
| 379 | } |
| 380 | } |
| 381 | _, err := model.DeleteTaskPluginVersion(key, version) |
| 382 | if err != nil { |
| 383 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 384 | common.ApiErrorMsg(c, "override plugin version not found; factory plugins cannot be deleted") |
| 385 | return |
| 386 | } |
| 387 | common.ApiError(c, err) |
| 388 | return |
| 389 | } |
| 390 | if err = syncTaskPluginsOnceContext(c.Request.Context()); err != nil { |
| 391 | common.ApiError(c, err) |
| 392 | return |
| 393 | } |
| 394 | common.ApiSuccess(c, nil) |
| 395 | } |
| 396 | |
| 397 | type taskPluginActivateRequest struct { |
| 398 | Version string `json:"version" binding:"required"` |