| 505 | } |
| 506 | |
| 507 | func GetTaskPlugin(c *gin.Context) { |
| 508 | key := c.Param("key") |
| 509 | version := c.Query("version") |
| 510 | plugin, err := model.GetTaskPluginVersion(key, version) |
| 511 | if err == nil { |
| 512 | loaded, compileErr := jsplugin.NewRegistry().Register(string(plugin.Source), jsplugin.Options{Key: plugin.Key, Version: plugin.Version}) |
| 513 | if compileErr != nil { |
| 514 | taskPluginCompileError(c, compileErr) |
| 515 | return |
| 516 | } |
| 517 | common.ApiSuccess(c, taskPluginDetail{Plugin: plugin, Meta: loaded.Meta, Source: string(plugin.Source), Layer: "override", HasIcon: plugin.HasIcon(), SkippedRoutes: taskPluginSkippedRoutes(plugin.Key, plugin.Version), |
| 518 | taskPluginParts: servedTaskPluginParts(loaded.Meta, plugin.Active && plugin.Enabled)}) |
| 519 | return |
| 520 | } |
| 521 | if !errors.Is(err, gorm.ErrRecordNotFound) || version != "" { |
| 522 | common.ApiError(c, err) |
| 523 | return |
| 524 | } |
| 525 | source, err := plugins.Source(key) |
| 526 | if err != nil { |
| 527 | common.ApiErrorMsg(c, "task plugin not found") |
| 528 | return |
| 529 | } |
| 530 | loaded, err := jsplugin.NewRegistry().RegisterFactory(source, jsplugin.Options{Key: key}) |
| 531 | if err != nil { |
| 532 | taskPluginCompileError(c, err) |
| 533 | return |
| 534 | } |
| 535 | _, _, hasIcon := plugins.Icon(key) |
| 536 | common.ApiSuccess(c, taskPluginDetail{Meta: loaded.Meta, Source: source, Layer: "factory", HasIcon: hasIcon, SkippedRoutes: taskPluginSkippedRoutes(key, loaded.Meta.Version), |
| 537 | taskPluginParts: servedTaskPluginParts(loaded.Meta, !setting.IsTaskPluginFactoryDisabled(key))}) |
| 538 | } |
| 539 | |
| 540 | type taskPluginDryRunRequest struct { |
| 541 | Hook string `json:"hook" binding:"required"` |