Update 更新脚本
(ctx context.Context, scriptID string, script *Script)
| 130 | |
| 131 | // Update 更新脚本 |
| 132 | func (sc *ScriptClient) Update(ctx context.Context, scriptID string, script *Script) error { |
| 133 | if sc.client.db == nil { |
| 134 | return fmt.Errorf("database not initialized") |
| 135 | } |
| 136 | |
| 137 | // 确保 ID 一致 |
| 138 | script.ID = scriptID |
| 139 | |
| 140 | // 转换为内部模型 |
| 141 | dbScript := &models.Script{ |
| 142 | ID: script.ID, |
| 143 | Name: script.Name, |
| 144 | Description: script.Description, |
| 145 | URL: script.URL, |
| 146 | Actions: script.Actions, |
| 147 | Tags: script.Tags, |
| 148 | Group: script.Group, |
| 149 | } |
| 150 | |
| 151 | // 更新到数据库 |
| 152 | if err := sc.client.db.UpdateScript(dbScript); err != nil { |
| 153 | return fmt.Errorf("failed to update script: %w", err) |
| 154 | } |
| 155 | |
| 156 | return nil |
| 157 | } |
| 158 | |
| 159 | // Delete 删除脚本 |
| 160 | func (sc *ScriptClient) Delete(ctx context.Context, scriptID string) error { |
no test coverage detected