| 545 | } |
| 546 | |
| 547 | func DryRunTaskPlugin(c *gin.Context) { |
| 548 | var request taskPluginDryRunRequest |
| 549 | if err := c.ShouldBindJSON(&request); err != nil { |
| 550 | common.ApiErrorMsg(c, err.Error()) |
| 551 | return |
| 552 | } |
| 553 | detailSource := "" |
| 554 | plugin, err := model.GetTaskPluginVersion(c.Param("key"), "") |
| 555 | if err == nil { |
| 556 | detailSource = string(plugin.Source) |
| 557 | } else if errors.Is(err, gorm.ErrRecordNotFound) { |
| 558 | detailSource, err = plugins.Source(c.Param("key")) |
| 559 | } |
| 560 | if err != nil { |
| 561 | common.ApiErrorMsg(c, "task plugin not found") |
| 562 | return |
| 563 | } |
| 564 | loaded, err := jsplugin.NewRegistry().Register(detailSource, jsplugin.Options{Key: c.Param("key")}) |
| 565 | if err != nil { |
| 566 | taskPluginCompileError(c, err) |
| 567 | return |
| 568 | } |
| 569 | args := make([]any, len(request.Args)) |
| 570 | for index, raw := range request.Args { |
| 571 | if err = common.Unmarshal(raw, &args[index]); err != nil { |
| 572 | common.ApiErrorMsg(c, fmt.Sprintf("invalid argument %d: %v", index+1, err)) |
| 573 | return |
| 574 | } |
| 575 | } |
| 576 | var output any |
| 577 | if request.Member == "" { |
| 578 | output, err = loaded.Engine.Call(context.Background(), request.Hook, args...) |
| 579 | } else { |
| 580 | output, err = loaded.Engine.CallMember(context.Background(), request.Hook, request.Member, args...) |
| 581 | } |
| 582 | if err != nil { |
| 583 | common.ApiErrorMsg(c, err.Error()) |
| 584 | return |
| 585 | } |
| 586 | common.ApiSuccess(c, output) |
| 587 | } |
| 588 | |
| 589 | func DeleteTaskPluginVersion(c *gin.Context) { |
| 590 | key := c.Param("key") |