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