Create 创建脚本
(ctx context.Context, script *Script)
| 41 | |
| 42 | // Create 创建脚本 |
| 43 | func (sc *ScriptClient) Create(ctx context.Context, script *Script) (string, error) { |
| 44 | if sc.client.db == nil { |
| 45 | return "", fmt.Errorf("database not initialized") |
| 46 | } |
| 47 | |
| 48 | if script.Name == "" { |
| 49 | return "", fmt.Errorf("script name is required") |
| 50 | } |
| 51 | |
| 52 | // 生成脚本 ID |
| 53 | if script.ID == "" { |
| 54 | script.ID = uuid.New().String() |
| 55 | } |
| 56 | |
| 57 | // 转换为内部模型 |
| 58 | dbScript := &models.Script{ |
| 59 | ID: script.ID, |
| 60 | Name: script.Name, |
| 61 | Description: script.Description, |
| 62 | URL: script.URL, |
| 63 | Actions: script.Actions, |
| 64 | Tags: script.Tags, |
| 65 | Group: script.Group, |
| 66 | } |
| 67 | |
| 68 | // 保存到数据库 |
| 69 | if err := sc.client.db.SaveScript(dbScript); err != nil { |
| 70 | return "", fmt.Errorf("failed to save script: %w", err) |
| 71 | } |
| 72 | |
| 73 | return script.ID, nil |
| 74 | } |
| 75 | |
| 76 | // Get 获取脚本 |
| 77 | func (sc *ScriptClient) Get(ctx context.Context, scriptID string) (*Script, error) { |
no test coverage detected