mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
update history table
This commit is contained in:
parent
adca87e9db
commit
d5cf15e946
@ -81,10 +81,13 @@ CREATE TABLE cmd (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE history (
|
CREATE TABLE history (
|
||||||
sessionid varchar(36) NOT NULL,
|
historyid varchar(36) PRIMARY KEY,
|
||||||
windowid varchar(36) NOT NULL,
|
|
||||||
userid varchar(36) NOT NULL,
|
|
||||||
ts bigint NOT NULL,
|
ts bigint NOT NULL,
|
||||||
lineid varchar(36) NOT NULL,
|
userid varchar(36) NOT NULL,
|
||||||
PRIMARY KEY (sessionid, windowid, lineid)
|
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
|
||||||
);
|
);
|
||||||
|
@ -75,10 +75,13 @@ CREATE TABLE cmd (
|
|||||||
PRIMARY KEY (sessionid, cmdid)
|
PRIMARY KEY (sessionid, cmdid)
|
||||||
);
|
);
|
||||||
CREATE TABLE history (
|
CREATE TABLE history (
|
||||||
sessionid varchar(36) NOT NULL,
|
historyid varchar(36) PRIMARY KEY,
|
||||||
windowid varchar(36) NOT NULL,
|
|
||||||
userid varchar(36) NOT NULL,
|
|
||||||
ts bigint NOT NULL,
|
ts bigint NOT NULL,
|
||||||
lineid varchar(36) NOT NULL,
|
userid varchar(36) NOT NULL,
|
||||||
PRIMARY KEY (sessionid, windowid, lineid)
|
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
|
||||||
);
|
);
|
||||||
|
@ -278,6 +278,10 @@ func RunCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.U
|
|||||||
return sstore.LineUpdate{Line: rtnLine, Cmd: cmd}, nil
|
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) {
|
func EvalCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||||
if len(pk.Args) == 0 {
|
if len(pk.Args) == 0 {
|
||||||
return nil, fmt.Errorf("usage: /eval [command], no command passed to eval")
|
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 == "" {
|
if commandStr == "" {
|
||||||
return nil, fmt.Errorf("/eval, invalid emtpty command")
|
return nil, fmt.Errorf("/eval, invalid emtpty command")
|
||||||
}
|
}
|
||||||
|
if !resolveBool(pk.Kwargs["nohist"], false) {
|
||||||
|
addToHistory(ctx, pk, pk.Args[0])
|
||||||
|
}
|
||||||
metaCmd := ""
|
metaCmd := ""
|
||||||
metaSubCmd := ""
|
metaSubCmd := ""
|
||||||
if commandStr == "cd" || strings.HasPrefix(commandStr, "cd ") {
|
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]
|
newPk.Kwargs[fields[0]] = fields[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return HandleCommand(ctx, newPk)
|
return HandleCommand(ctx, newPk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,23 @@ func InsertRemote(ctx context.Context, remote *RemoteType) error {
|
|||||||
return nil
|
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) {
|
func GetBareSessions(ctx context.Context) ([]*SessionType, error) {
|
||||||
var rtn []*SessionType
|
var rtn []*SessionType
|
||||||
err := WithTx(ctx, func(tx *TxWrap) error {
|
err := WithTx(ctx, func(tx *TxWrap) error {
|
||||||
|
@ -82,14 +82,13 @@ func (opts WindowOptsType) Value() (driver.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WindowType struct {
|
type WindowType struct {
|
||||||
SessionId string `json:"sessionid"`
|
SessionId string `json:"sessionid"`
|
||||||
WindowId string `json:"windowid"`
|
WindowId string `json:"windowid"`
|
||||||
CurRemote string `json:"curremote"`
|
CurRemote string `json:"curremote"`
|
||||||
WinOpts WindowOptsType `json:"winopts"`
|
WinOpts WindowOptsType `json:"winopts"`
|
||||||
Lines []*LineType `json:"lines"`
|
Lines []*LineType `json:"lines"`
|
||||||
Cmds []*CmdType `json:"cmds"`
|
Cmds []*CmdType `json:"cmds"`
|
||||||
History []*HistoryItemType `json:"history"`
|
Remotes []*RemoteInstance `json:"remotes"`
|
||||||
Remotes []*RemoteInstance `json:"remotes"`
|
|
||||||
|
|
||||||
// only for updates
|
// only for updates
|
||||||
Remove bool `json:"remove,omitempty"`
|
Remove bool `json:"remove,omitempty"`
|
||||||
@ -158,8 +157,18 @@ type ScreenWindowType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HistoryItemType struct {
|
type HistoryItemType struct {
|
||||||
CmdStr string `json:"cmdstr"`
|
HistoryId string `json:"historyid"`
|
||||||
Remove bool `json:"remove"`
|
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 {
|
type RemoteState struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user