mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
process static command / block commands. setmeta, setview
This commit is contained in:
@@ -15,12 +15,16 @@ const CommandKey = "command"
|
||||
|
||||
const (
|
||||
BlockCommand_Message = "message"
|
||||
BlockCommand_SetView = "setview"
|
||||
BlockCommand_SetMeta = "setmeta"
|
||||
BlockCommand_Input = "controller:input"
|
||||
)
|
||||
|
||||
var CommandToTypeMap = map[string]reflect.Type{
|
||||
BlockCommand_Message: reflect.TypeOf(MessageCommand{}),
|
||||
BlockCommand_Input: reflect.TypeOf(InputCommand{}),
|
||||
BlockCommand_SetView: reflect.TypeOf(SetViewCommand{}),
|
||||
BlockCommand_SetMeta: reflect.TypeOf(SetMetaCommand{}),
|
||||
}
|
||||
|
||||
type BlockCommand interface {
|
||||
@@ -67,3 +71,21 @@ type InputCommand struct {
|
||||
func (ic *InputCommand) GetCommand() string {
|
||||
return BlockCommand_Input
|
||||
}
|
||||
|
||||
type SetViewCommand struct {
|
||||
Command string `json:"command"`
|
||||
View string `json:"view"`
|
||||
}
|
||||
|
||||
func (svc *SetViewCommand) GetCommand() string {
|
||||
return BlockCommand_SetView
|
||||
}
|
||||
|
||||
type SetMetaCommand struct {
|
||||
Command string `json:"command"`
|
||||
Meta map[string]any `json:"meta"`
|
||||
}
|
||||
|
||||
func (smc *SetMetaCommand) GetCommand() string {
|
||||
return BlockCommand_SetMeta
|
||||
}
|
||||
|
||||
@@ -259,20 +259,8 @@ func (bc *BlockController) Run(bdata *BlockData) {
|
||||
}
|
||||
}()
|
||||
|
||||
messageCount := 0
|
||||
for genCmd := range bc.InputCh {
|
||||
switch cmd := genCmd.(type) {
|
||||
case *MessageCommand:
|
||||
fmt.Printf("MESSAGE: %s | %q\n", bc.BlockId, cmd.Message)
|
||||
messageCount++
|
||||
eventbus.SendEvent(application.WailsEvent{
|
||||
Name: "block:ptydata",
|
||||
Data: map[string]any{
|
||||
"blockid": bc.BlockId,
|
||||
"blockfile": "main",
|
||||
"ptydata": base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("message %d\r\n", messageCount))),
|
||||
},
|
||||
})
|
||||
case *InputCommand:
|
||||
fmt.Printf("INPUT: %s | %q\n", bc.BlockId, cmd.InputData64)
|
||||
if bc.ShellInputCh != nil {
|
||||
@@ -317,3 +305,32 @@ func GetBlockController(blockId string) *BlockController {
|
||||
defer globalLock.Unlock()
|
||||
return blockControllerMap[blockId]
|
||||
}
|
||||
|
||||
func ProcessStaticCommand(blockId string, cmdGen BlockCommand) {
|
||||
switch cmd := cmdGen.(type) {
|
||||
case *MessageCommand:
|
||||
log.Printf("MESSAGE: %s | %q\n", blockId, cmd.Message)
|
||||
case *SetViewCommand:
|
||||
log.Printf("SETVIEW: %s | %q\n", blockId, cmd.View)
|
||||
block := GetBlockData(blockId)
|
||||
if block != nil {
|
||||
block.WithLock(func() {
|
||||
block.View = cmd.View
|
||||
})
|
||||
}
|
||||
case *SetMetaCommand:
|
||||
log.Printf("SETMETA: %s | %v\n", blockId, cmd.Meta)
|
||||
block := GetBlockData(blockId)
|
||||
if block != nil {
|
||||
block.WithLock(func() {
|
||||
for k, v := range cmd.Meta {
|
||||
if v == nil {
|
||||
delete(block.Meta, k)
|
||||
continue
|
||||
}
|
||||
block.Meta[k] = v
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user