MCPcopy Create free account
hub / github.com/browserwing/browserwing / SaveScript

Method SaveScript

backend/api/handlers.go:484–556  ·  view source on GitHub ↗

SaveScript 保存脚本

(c *gin.Context)

Source from the content-addressed store, hash-verified

482
483// SaveScript 保存脚本
484func (h *Handler) SaveScript(c *gin.Context) {
485 var req struct {
486 ID string `json:"id"` // 可选,更新时使用
487 Name string `json:"name" binding:"required"`
488 Description string `json:"description"`
489 URL string `json:"url" binding:"required"`
490 Actions []models.ScriptAction `json:"actions" binding:"required"`
491 DownloadedFiles []models.DownloadedFile `json:"downloaded_files"` // 下载的文件列表
492 Tags []string `json:"tags"`
493 IsMCPCommand *bool `json:"is_mcp_command"`
494 MCPCommandName string `json:"mcp_command_name"`
495 MCPCommandDescription string `json:"mcp_command_description"`
496 MCPInputSchema map[string]interface{} `json:"mcp_input_schema"`
497 Variables map[string]string `json:"variables"`
498 }
499
500 if err := c.ShouldBindJSON(&req); err != nil {
501 c.JSON(http.StatusBadRequest, gin.H{"error": "error.invalidParams"})
502 return
503 }
504
505 // 计算录制时长
506 var duration int64
507 if len(req.Actions) > 0 {
508 duration = req.Actions[len(req.Actions)-1].Timestamp - req.Actions[0].Timestamp
509 }
510
511 id := req.ID
512 if id == "" {
513 id = uuid.New().String()
514 }
515
516 script := &models.Script{
517 ID: id,
518 Name: req.Name,
519 Description: req.Description,
520 URL: req.URL,
521 Actions: req.Actions,
522 DownloadedFiles: req.DownloadedFiles, // 保存下载文件信息
523 Tags: req.Tags,
524 Duration: duration,
525 CreatedAt: time.Now(),
526 UpdatedAt: time.Now(),
527 Variables: req.Variables,
528 }
529
530 // 如果提供了 MCP 相关字段,则设置
531 if req.IsMCPCommand != nil {
532 script.IsMCPCommand = *req.IsMCPCommand
533 }
534 if req.MCPCommandName != "" {
535 script.MCPCommandName = req.MCPCommandName
536 }
537 if req.MCPCommandDescription != "" {
538 script.MCPCommandDescription = req.MCPCommandDescription
539 }
540 if req.MCPInputSchema != nil {
541 script.MCPInputSchema = req.MCPInputSchema

Callers

nothing calls this directly

Calls 2

syncMCPRegistrationMethod · 0.95
SaveScriptMethod · 0.65

Tested by

no test coverage detected