mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
wsh deleteblock
This commit is contained in:
@@ -29,6 +29,12 @@ func CreateBlockCommand(w *wshutil.WshRpc, data wshrpc.CommandCreateBlockData, o
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// command "deleteblock", wshserver.DeleteBlockCommand
|
||||
func DeleteBlockCommand(w *wshutil.WshRpc, data wshrpc.CommandDeleteBlockData, opts *wshrpc.WshRpcCommandOpts) error {
|
||||
_, err := sendRpcRequestCallHelper[any](w, "deleteblock", data, opts)
|
||||
return err
|
||||
}
|
||||
|
||||
// command "file:append", wshserver.AppendFileCommand
|
||||
func AppendFileCommand(w *wshutil.WshRpc, data wshrpc.CommandAppendFileData, opts *wshrpc.WshRpcCommandOpts) error {
|
||||
_, err := sendRpcRequestCallHelper[any](w, "file:append", data, opts)
|
||||
|
||||
@@ -25,6 +25,7 @@ const (
|
||||
Command_AppendIJson = "file:appendijson"
|
||||
Command_ResolveIds = "resolveids"
|
||||
Command_CreateBlock = "createblock"
|
||||
Command_DeleteBlock = "deleteblock"
|
||||
)
|
||||
|
||||
type MetaDataType = map[string]any
|
||||
@@ -133,3 +134,7 @@ type CommandAppendIJsonData struct {
|
||||
FileName string `json:"filename"`
|
||||
Data ijson.Command `json:"data"`
|
||||
}
|
||||
|
||||
type CommandDeleteBlockData struct {
|
||||
BlockId string `json:"blockid" wshcontext:"BlockId"`
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ var WshServerCommandToDeclMap = map[string]*WshServerMethodDecl{
|
||||
wshrpc.Command_BlockInput: GetWshServerMethod(wshrpc.Command_BlockInput, wshutil.RpcType_Call, "BlockInputCommand", WshServerImpl.BlockInputCommand),
|
||||
wshrpc.Command_AppendFile: GetWshServerMethod(wshrpc.Command_AppendFile, wshutil.RpcType_Call, "AppendFileCommand", WshServerImpl.AppendFileCommand),
|
||||
wshrpc.Command_AppendIJson: GetWshServerMethod(wshrpc.Command_AppendIJson, wshutil.RpcType_Call, "AppendIJsonCommand", WshServerImpl.AppendIJsonCommand),
|
||||
wshrpc.Command_DeleteBlock: GetWshServerMethod(wshrpc.Command_DeleteBlock, wshutil.RpcType_Call, "DeleteBlockCommand", WshServerImpl.DeleteBlockCommand),
|
||||
"streamtest": RespStreamTest_MethodDecl,
|
||||
}
|
||||
|
||||
@@ -294,3 +295,37 @@ func (ws *WshServer) AppendIJsonCommand(ctx context.Context, data wshrpc.Command
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ws *WshServer) DeleteBlockCommand(ctx context.Context, data wshrpc.CommandDeleteBlockData) error {
|
||||
ctx = wstore.ContextWithUpdates(ctx)
|
||||
tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finding tab for block: %w", err)
|
||||
}
|
||||
if tabId == "" {
|
||||
return fmt.Errorf("no tab found for block")
|
||||
}
|
||||
windowId, err := wstore.DBFindWindowForTabId(ctx, tabId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finding window for tab: %w", err)
|
||||
}
|
||||
if windowId == "" {
|
||||
return fmt.Errorf("no window found for tab")
|
||||
}
|
||||
err = wstore.DeleteBlock(ctx, tabId, data.BlockId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error deleting block: %w", err)
|
||||
}
|
||||
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
||||
EventType: eventbus.WSEvent_LayoutAction,
|
||||
Data: &eventbus.WSLayoutActionData{
|
||||
ActionType: "delete",
|
||||
TabId: tabId,
|
||||
BlockId: data.BlockId,
|
||||
},
|
||||
})
|
||||
blockcontroller.StopBlockController(data.BlockId)
|
||||
updates := wstore.ContextGetUpdatesRtn(ctx)
|
||||
sendWStoreUpdatesToEventBus(updates)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user