| 314 | } |
| 315 | |
| 316 | func DryRunTaskPlugin(c *gin.Context) { |
| 317 | var request taskPluginDryRunRequest |
| 318 | if err := c.ShouldBindJSON(&request); err != nil { |
| 319 | common.ApiErrorMsg(c, err.Error()) |
| 320 | return |
| 321 | } |
| 322 | detailSource := "" |
| 323 | plugin, err := model.GetTaskPluginVersion(c.Param("key"), "") |
| 324 | if err == nil { |
| 325 | detailSource = plugin.Source |
| 326 | } else if errors.Is(err, gorm.ErrRecordNotFound) { |
| 327 | detailSource, err = plugins.Source(c.Param("key")) |
| 328 | } |
| 329 | if err != nil { |
| 330 | common.ApiErrorMsg(c, "task plugin not found") |
| 331 | return |
| 332 | } |
| 333 | loaded, err := jsplugin.NewRegistry().Register(detailSource, jsplugin.Options{Key: c.Param("key")}) |
| 334 | if err != nil { |
| 335 | common.ApiErrorMsg(c, err.Error()) |
| 336 | return |
| 337 | } |
| 338 | args := make([]any, len(request.Args)) |
| 339 | for index, raw := range request.Args { |
| 340 | if err = common.Unmarshal(raw, &args[index]); err != nil { |
| 341 | common.ApiErrorMsg(c, fmt.Sprintf("invalid argument %d: %v", index+1, err)) |
| 342 | return |
| 343 | } |
| 344 | } |
| 345 | var output any |
| 346 | if request.Member == "" { |
| 347 | output, err = loaded.Engine.Call(context.Background(), request.Hook, args...) |
| 348 | } else { |
| 349 | output, err = loaded.Engine.CallMember(context.Background(), request.Hook, request.Member, args...) |
| 350 | } |
| 351 | if err != nil { |
| 352 | common.ApiErrorMsg(c, err.Error()) |
| 353 | return |
| 354 | } |
| 355 | common.ApiSuccess(c, output) |
| 356 | } |
| 357 | |
| 358 | func DeleteTaskPluginVersion(c *gin.Context) { |
| 359 | key := c.Param("key") |