update history table

This commit is contained in:
sawka 2022-08-11 12:07:41 -07:00
parent adca87e9db
commit d5cf15e946
5 changed files with 60 additions and 20 deletions

View File

@ -81,10 +81,13 @@ CREATE TABLE cmd (
);
CREATE TABLE history (
sessionid varchar(36) NOT NULL,
windowid varchar(36) NOT NULL,
userid varchar(36) NOT NULL,
historyid varchar(36) PRIMARY KEY,
ts bigint NOT NULL,
lineid varchar(36) NOT NULL,
PRIMARY KEY (sessionid, windowid, lineid)
userid varchar(36) NOT NULL,
sessionid varchar(36) NOT NULL,
screenid varchar(36) NOT NULL,
windowid varchar(36) NOT NULL,
lineid int NOT NULL,
cmdid varchar(36) NOT NULL,
cmdstr text NOT NULL
);

View File

@ -75,10 +75,13 @@ CREATE TABLE cmd (
PRIMARY KEY (sessionid, cmdid)
);
CREATE TABLE history (
sessionid varchar(36) NOT NULL,
windowid varchar(36) NOT NULL,
userid varchar(36) NOT NULL,
historyid varchar(36) PRIMARY KEY,
ts bigint NOT NULL,
lineid varchar(36) NOT NULL,
PRIMARY KEY (sessionid, windowid, lineid)
userid varchar(36) NOT NULL,
sessionid varchar(36) NOT NULL,
screenid varchar(36) NOT NULL,
windowid varchar(36) NOT NULL,
lineid int NOT NULL,
cmdid varchar(36) NOT NULL,
cmdstr text NOT NULL
);

View File

@ -278,6 +278,10 @@ func RunCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.U
return sstore.LineUpdate{Line: rtnLine, Cmd: cmd}, nil
}
func addToHistory(ctx context.Context, pk *scpacket.FeCommandPacketType, cmdStr string) error {
return nil
}
func EvalCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
if len(pk.Args) == 0 {
return nil, fmt.Errorf("usage: /eval [command], no command passed to eval")
@ -287,6 +291,9 @@ func EvalCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.
if commandStr == "" {
return nil, fmt.Errorf("/eval, invalid emtpty command")
}
if !resolveBool(pk.Kwargs["nohist"], false) {
addToHistory(ctx, pk, pk.Args[0])
}
metaCmd := ""
metaSubCmd := ""
if commandStr == "cd" || strings.HasPrefix(commandStr, "cd ") {
@ -330,6 +337,7 @@ func EvalCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.
newPk.Kwargs[fields[0]] = fields[1]
}
}
return HandleCommand(ctx, newPk)
}

View File

@ -85,6 +85,23 @@ func InsertRemote(ctx context.Context, remote *RemoteType) error {
return nil
}
func InsertHistoryItem(ctx context.Context, hitem *HistoryItemType) error {
if hitem == nil {
return fmt.Errorf("cannot insert nil history item")
}
db, err := GetDB(ctx)
if err != nil {
return err
}
query := `INSERT INTO history ( historyid, ts, userid, sessionid, screenid, windowid, lineid, cmdid, cmdstr) VALUES
(:historyid,:ts,:userid,:sessionid,:screenid,:windowid,:lineid,:cmdid,:cmdstr)`
_, err = db.NamedExec(query, hitem)
if err != nil {
return err
}
return nil
}
func GetBareSessions(ctx context.Context) ([]*SessionType, error) {
var rtn []*SessionType
err := WithTx(ctx, func(tx *TxWrap) error {

View File

@ -82,14 +82,13 @@ func (opts WindowOptsType) Value() (driver.Value, error) {
}
type WindowType struct {
SessionId string `json:"sessionid"`
WindowId string `json:"windowid"`
CurRemote string `json:"curremote"`
WinOpts WindowOptsType `json:"winopts"`
Lines []*LineType `json:"lines"`
Cmds []*CmdType `json:"cmds"`
History []*HistoryItemType `json:"history"`
Remotes []*RemoteInstance `json:"remotes"`
SessionId string `json:"sessionid"`
WindowId string `json:"windowid"`
CurRemote string `json:"curremote"`
WinOpts WindowOptsType `json:"winopts"`
Lines []*LineType `json:"lines"`
Cmds []*CmdType `json:"cmds"`
Remotes []*RemoteInstance `json:"remotes"`
// only for updates
Remove bool `json:"remove,omitempty"`
@ -158,8 +157,18 @@ type ScreenWindowType struct {
}
type HistoryItemType struct {
CmdStr string `json:"cmdstr"`
Remove bool `json:"remove"`
HistoryId string `json:"historyid"`
Ts int64 `json:"ts"`
UserId string `json:"userid"`
SessionId string `json:"sessionid"`
ScreenId string `json:"screenid"`
WindowId string `json:"windowid"`
LineId int64 `json:"lineid"`
CmdId string `json:"cmdid"`
CmdStr string `json:"cmdstr"`
// only for updates
Remove bool `json:"remove"`
}
type RemoteState struct {