53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
syncsvc "verstak/internal/core/sync"
|
|
)
|
|
|
|
func (a *App) ListActions(nodeID string) ([]ActionDTO, error) {
|
|
list, err := a.actions.ListByNode(nodeID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make([]ActionDTO, len(list))
|
|
for i := range list {
|
|
data := list[i].Command
|
|
if list[i].URL != "" {
|
|
data = list[i].URL
|
|
}
|
|
result[i] = ActionDTO{
|
|
ID: list[i].ID,
|
|
NodeID: list[i].NodeID,
|
|
Title: list[i].Title,
|
|
Type: list[i].Kind,
|
|
Data: data,
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (a *App) CreateAction(nodeID, kind, title, data string) (*ActionDTO, error) {
|
|
rec, err := a.actions.Create(nodeID, kind, title, data, "", data, nil, kind == "run_command" || kind == "run_script", false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_ = a.sync.RecordOp(syncsvc.EntityAction, rec.ID, syncsvc.OpCreate, actionPayload(rec))
|
|
return &ActionDTO{
|
|
ID: rec.ID,
|
|
NodeID: rec.NodeID,
|
|
Title: rec.Title,
|
|
Type: rec.Kind,
|
|
Data: data,
|
|
}, nil
|
|
}
|
|
|
|
func (a *App) DeleteAction(id string) error {
|
|
_ = a.sync.RecordOp(syncsvc.EntityAction, id, syncsvc.OpDelete, nil)
|
|
return a.actions.Delete(id)
|
|
}
|
|
|
|
func (a *App) RunAction(id string) error {
|
|
_, err := a.actions.Run(id)
|
|
return err
|
|
}
|