mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
Move bookmarks, history, playbook, and telemetry code out of sstore (#493)
* break out telemetry and playbook * break out bookmarks * add license disclaimers
This commit is contained in:
+32
-558
File diff suppressed because it is too large
Load Diff
@@ -110,6 +110,7 @@ const (
|
||||
SSHConfigSrcTypeImport = "sshconfig-import"
|
||||
)
|
||||
|
||||
// TODO: move to webshare package once sstore code is more modular
|
||||
const (
|
||||
ShareModeLocal = "local"
|
||||
ShareModeWeb = "web"
|
||||
@@ -154,8 +155,6 @@ const (
|
||||
UpdateType_PtyPos = "pty:pos"
|
||||
)
|
||||
|
||||
const MaxTzNameLen = 50
|
||||
|
||||
var globalDBLock = &sync.Mutex{}
|
||||
var globalDB *sqlx.DB
|
||||
var globalDBErr error
|
||||
@@ -233,56 +232,6 @@ type ClientWinSizeType struct {
|
||||
FullScreen bool `json:"fullscreen,omitempty"`
|
||||
}
|
||||
|
||||
type ActivityUpdate struct {
|
||||
FgMinutes int
|
||||
ActiveMinutes int
|
||||
OpenMinutes int
|
||||
NumCommands int
|
||||
ClickShared int
|
||||
HistoryView int
|
||||
BookmarksView int
|
||||
NumConns int
|
||||
WebShareLimit int
|
||||
ReinitBashErrors int
|
||||
ReinitZshErrors int
|
||||
BuildTime string
|
||||
}
|
||||
|
||||
type ActivityType struct {
|
||||
Day string `json:"day"`
|
||||
Uploaded bool `json:"-"`
|
||||
TData TelemetryData `json:"tdata"`
|
||||
TzName string `json:"tzname"`
|
||||
TzOffset int `json:"tzoffset"`
|
||||
ClientVersion string `json:"clientversion"`
|
||||
ClientArch string `json:"clientarch"`
|
||||
BuildTime string `json:"buildtime"`
|
||||
DefaultShell string `json:"defaultshell"`
|
||||
OSRelease string `json:"osrelease"`
|
||||
}
|
||||
|
||||
type TelemetryData struct {
|
||||
NumCommands int `json:"numcommands"`
|
||||
ActiveMinutes int `json:"activeminutes"`
|
||||
FgMinutes int `json:"fgminutes"`
|
||||
OpenMinutes int `json:"openminutes"`
|
||||
ClickShared int `json:"clickshared,omitempty"`
|
||||
HistoryView int `json:"historyview,omitempty"`
|
||||
BookmarksView int `json:"bookmarksview,omitempty"`
|
||||
NumConns int `json:"numconns"`
|
||||
WebShareLimit int `json:"websharelimit,omitempty"`
|
||||
ReinitBashErrors int `json:"reinitbasherrors,omitempty"`
|
||||
ReinitZshErrors int `json:"reinitzsherrors,omitempty"`
|
||||
}
|
||||
|
||||
func (tdata TelemetryData) Value() (driver.Value, error) {
|
||||
return quickValueJson(tdata)
|
||||
}
|
||||
|
||||
func (tdata *TelemetryData) Scan(val interface{}) error {
|
||||
return quickScanJson(tdata, val)
|
||||
}
|
||||
|
||||
type SidebarValueType struct {
|
||||
Collapsed bool `json:"collapsed"`
|
||||
Width int `json:"width"`
|
||||
@@ -398,52 +347,6 @@ type SessionStatsType struct {
|
||||
DiskStats SessionDiskSizeType `json:"diskstats"`
|
||||
}
|
||||
|
||||
func (h *HistoryItemType) ToMap() map[string]interface{} {
|
||||
rtn := make(map[string]interface{})
|
||||
rtn["historyid"] = h.HistoryId
|
||||
rtn["ts"] = h.Ts
|
||||
rtn["userid"] = h.UserId
|
||||
rtn["sessionid"] = h.SessionId
|
||||
rtn["screenid"] = h.ScreenId
|
||||
rtn["lineid"] = h.LineId
|
||||
rtn["linenum"] = h.LineNum
|
||||
rtn["haderror"] = h.HadError
|
||||
rtn["cmdstr"] = h.CmdStr
|
||||
rtn["remoteownerid"] = h.Remote.OwnerId
|
||||
rtn["remoteid"] = h.Remote.RemoteId
|
||||
rtn["remotename"] = h.Remote.Name
|
||||
rtn["ismetacmd"] = h.IsMetaCmd
|
||||
rtn["exitcode"] = h.ExitCode
|
||||
rtn["durationms"] = h.DurationMs
|
||||
rtn["festate"] = quickJson(h.FeState)
|
||||
rtn["tags"] = quickJson(h.Tags)
|
||||
rtn["status"] = h.Status
|
||||
return rtn
|
||||
}
|
||||
|
||||
func (h *HistoryItemType) FromMap(m map[string]interface{}) bool {
|
||||
quickSetStr(&h.HistoryId, m, "historyid")
|
||||
quickSetInt64(&h.Ts, m, "ts")
|
||||
quickSetStr(&h.UserId, m, "userid")
|
||||
quickSetStr(&h.SessionId, m, "sessionid")
|
||||
quickSetStr(&h.ScreenId, m, "screenid")
|
||||
quickSetStr(&h.LineId, m, "lineid")
|
||||
quickSetBool(&h.HadError, m, "haderror")
|
||||
quickSetStr(&h.CmdStr, m, "cmdstr")
|
||||
quickSetStr(&h.Remote.OwnerId, m, "remoteownerid")
|
||||
quickSetStr(&h.Remote.RemoteId, m, "remoteid")
|
||||
quickSetStr(&h.Remote.Name, m, "remotename")
|
||||
quickSetBool(&h.IsMetaCmd, m, "ismetacmd")
|
||||
quickSetStr(&h.HistoryNum, m, "historynum")
|
||||
quickSetInt64(&h.LineNum, m, "linenum")
|
||||
dbutil.QuickSetNullableInt64(&h.ExitCode, m, "exitcode")
|
||||
dbutil.QuickSetNullableInt64(&h.DurationMs, m, "durationms")
|
||||
quickSetJson(&h.FeState, m, "festate")
|
||||
quickSetJson(&h.Tags, m, "tags")
|
||||
quickSetStr(&h.Status, m, "status")
|
||||
return true
|
||||
}
|
||||
|
||||
type ScreenOptsType struct {
|
||||
TabColor string `json:"tabcolor,omitempty"`
|
||||
TabIcon string `json:"tabicon,omitempty"`
|
||||
@@ -619,55 +522,6 @@ type ScreenAnchorType struct {
|
||||
AnchorOffset int `json:"anchoroffset,omitempty"`
|
||||
}
|
||||
|
||||
type HistoryItemType struct {
|
||||
HistoryId string `json:"historyid"`
|
||||
Ts int64 `json:"ts"`
|
||||
UserId string `json:"userid"`
|
||||
SessionId string `json:"sessionid"`
|
||||
ScreenId string `json:"screenid"`
|
||||
LineId string `json:"lineid"`
|
||||
HadError bool `json:"haderror"`
|
||||
CmdStr string `json:"cmdstr"`
|
||||
Remote RemotePtrType `json:"remote"`
|
||||
IsMetaCmd bool `json:"ismetacmd"`
|
||||
ExitCode *int64 `json:"exitcode,omitempty"`
|
||||
DurationMs *int64 `json:"durationms,omitempty"`
|
||||
FeState FeStateType `json:"festate,omitempty"`
|
||||
Tags map[string]bool `json:"tags,omitempty"`
|
||||
LineNum int64 `json:"linenum" dbmap:"-"`
|
||||
Status string `json:"status"`
|
||||
|
||||
// only for updates
|
||||
Remove bool `json:"remove" dbmap:"-"`
|
||||
|
||||
// transient (string because of different history orderings)
|
||||
HistoryNum string `json:"historynum" dbmap:"-"`
|
||||
}
|
||||
|
||||
type HistoryQueryOpts struct {
|
||||
Offset int
|
||||
MaxItems int
|
||||
FromTs int64
|
||||
SearchText string
|
||||
SessionId string
|
||||
RemoteId string
|
||||
ScreenId string
|
||||
NoMeta bool
|
||||
RawOffset int
|
||||
FilterFn func(*HistoryItemType) bool
|
||||
}
|
||||
|
||||
type HistoryQueryResult struct {
|
||||
MaxItems int
|
||||
Items []*HistoryItemType
|
||||
Offset int // the offset shown to user
|
||||
RawOffset int // internal offset
|
||||
HasMore bool
|
||||
NextRawOffset int // internal offset used by pager for next query
|
||||
|
||||
prevItems int // holds number of items skipped by RawOffset
|
||||
}
|
||||
|
||||
type TermOpts struct {
|
||||
Rows int64 `json:"rows"`
|
||||
Cols int64 `json:"cols"`
|
||||
@@ -850,114 +704,6 @@ type OpenAIResponse struct {
|
||||
Choices []OpenAIChoiceType `json:"choices,omitempty"`
|
||||
}
|
||||
|
||||
type PlaybookType struct {
|
||||
PlaybookId string `json:"playbookid"`
|
||||
PlaybookName string `json:"playbookname"`
|
||||
Description string `json:"description"`
|
||||
EntryIds []string `json:"entryids"`
|
||||
|
||||
// this is not persisted to DB, just for transport to FE
|
||||
Entries []*PlaybookEntry `json:"entries"`
|
||||
}
|
||||
|
||||
func (p *PlaybookType) ToMap() map[string]interface{} {
|
||||
rtn := make(map[string]interface{})
|
||||
rtn["playbookid"] = p.PlaybookId
|
||||
rtn["playbookname"] = p.PlaybookName
|
||||
rtn["description"] = p.Description
|
||||
rtn["entryids"] = quickJsonArr(p.EntryIds)
|
||||
return rtn
|
||||
}
|
||||
|
||||
func (p *PlaybookType) FromMap(m map[string]interface{}) bool {
|
||||
quickSetStr(&p.PlaybookId, m, "playbookid")
|
||||
quickSetStr(&p.PlaybookName, m, "playbookname")
|
||||
quickSetStr(&p.Description, m, "description")
|
||||
quickSetJsonArr(&p.Entries, m, "entries")
|
||||
return true
|
||||
}
|
||||
|
||||
// reorders p.Entries to match p.EntryIds
|
||||
func (p *PlaybookType) OrderEntries() {
|
||||
if len(p.Entries) == 0 {
|
||||
return
|
||||
}
|
||||
m := make(map[string]*PlaybookEntry)
|
||||
for _, entry := range p.Entries {
|
||||
m[entry.EntryId] = entry
|
||||
}
|
||||
newList := make([]*PlaybookEntry, 0, len(p.EntryIds))
|
||||
for _, entryId := range p.EntryIds {
|
||||
entry := m[entryId]
|
||||
if entry != nil {
|
||||
newList = append(newList, entry)
|
||||
}
|
||||
}
|
||||
p.Entries = newList
|
||||
}
|
||||
|
||||
// removes from p.EntryIds (not from p.Entries)
|
||||
func (p *PlaybookType) RemoveEntry(entryIdToRemove string) {
|
||||
if len(p.EntryIds) == 0 {
|
||||
return
|
||||
}
|
||||
newList := make([]string, 0, len(p.EntryIds)-1)
|
||||
for _, entryId := range p.EntryIds {
|
||||
if entryId == entryIdToRemove {
|
||||
continue
|
||||
}
|
||||
newList = append(newList, entryId)
|
||||
}
|
||||
p.EntryIds = newList
|
||||
}
|
||||
|
||||
type PlaybookEntry struct {
|
||||
PlaybookId string `json:"playbookid"`
|
||||
EntryId string `json:"entryid"`
|
||||
Alias string `json:"alias"`
|
||||
CmdStr string `json:"cmdstr"`
|
||||
UpdatedTs int64 `json:"updatedts"`
|
||||
CreatedTs int64 `json:"createdts"`
|
||||
Description string `json:"description"`
|
||||
Remove bool `json:"remove,omitempty"`
|
||||
}
|
||||
|
||||
type BookmarkType struct {
|
||||
BookmarkId string `json:"bookmarkid"`
|
||||
CreatedTs int64 `json:"createdts"`
|
||||
CmdStr string `json:"cmdstr"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
OrderIdx int64 `json:"orderidx"`
|
||||
Remove bool `json:"remove,omitempty"`
|
||||
}
|
||||
|
||||
func (bm *BookmarkType) GetSimpleKey() string {
|
||||
return bm.BookmarkId
|
||||
}
|
||||
|
||||
func (bm *BookmarkType) ToMap() map[string]interface{} {
|
||||
rtn := make(map[string]interface{})
|
||||
rtn["bookmarkid"] = bm.BookmarkId
|
||||
rtn["createdts"] = bm.CreatedTs
|
||||
rtn["cmdstr"] = bm.CmdStr
|
||||
rtn["alias"] = bm.Alias
|
||||
rtn["description"] = bm.Description
|
||||
rtn["tags"] = quickJsonArr(bm.Tags)
|
||||
return rtn
|
||||
}
|
||||
|
||||
func (bm *BookmarkType) FromMap(m map[string]interface{}) bool {
|
||||
quickSetStr(&bm.BookmarkId, m, "bookmarkid")
|
||||
quickSetInt64(&bm.CreatedTs, m, "createdts")
|
||||
quickSetStr(&bm.Alias, m, "alias")
|
||||
quickSetStr(&bm.CmdStr, m, "cmdstr")
|
||||
quickSetStr(&bm.Description, m, "description")
|
||||
quickSetJsonArr(&bm.Tags, m, "tags")
|
||||
return true
|
||||
}
|
||||
|
||||
type ResolveItem struct {
|
||||
Name string
|
||||
Num int
|
||||
|
||||
@@ -91,18 +91,6 @@ func (ClearInfoUpdate) GetType() string {
|
||||
return "clearinfo"
|
||||
}
|
||||
|
||||
type HistoryInfoType struct {
|
||||
HistoryType string `json:"historytype"`
|
||||
SessionId string `json:"sessionid,omitempty"`
|
||||
ScreenId string `json:"screenid,omitempty"`
|
||||
Items []*HistoryItemType `json:"items"`
|
||||
Show bool `json:"show"`
|
||||
}
|
||||
|
||||
func (HistoryInfoType) GetType() string {
|
||||
return "history"
|
||||
}
|
||||
|
||||
type InteractiveUpdate bool
|
||||
|
||||
func (InteractiveUpdate) GetType() string {
|
||||
@@ -122,43 +110,6 @@ func (ConnectUpdate) GetType() string {
|
||||
return "connect"
|
||||
}
|
||||
|
||||
type MainViewUpdate struct {
|
||||
MainView string `json:"mainview"`
|
||||
HistoryView *HistoryViewData `json:"historyview,omitempty"`
|
||||
BookmarksView *BookmarksUpdate `json:"bookmarksview,omitempty"`
|
||||
}
|
||||
|
||||
func (MainViewUpdate) GetType() string {
|
||||
return "mainview"
|
||||
}
|
||||
|
||||
type BookmarksUpdate struct {
|
||||
Bookmarks []*BookmarkType `json:"bookmarks"`
|
||||
SelectedBookmark string `json:"selectedbookmark,omitempty"`
|
||||
}
|
||||
|
||||
func (BookmarksUpdate) GetType() string {
|
||||
return "bookmarks"
|
||||
}
|
||||
|
||||
func AddBookmarksUpdate(update *scbus.ModelUpdatePacketType, bookmarks []*BookmarkType, selectedBookmark *string) {
|
||||
if selectedBookmark == nil {
|
||||
update.AddUpdate(BookmarksUpdate{Bookmarks: bookmarks})
|
||||
} else {
|
||||
update.AddUpdate(BookmarksUpdate{Bookmarks: bookmarks, SelectedBookmark: *selectedBookmark})
|
||||
}
|
||||
}
|
||||
|
||||
type HistoryViewData struct {
|
||||
Items []*HistoryItemType `json:"items"`
|
||||
Offset int `json:"offset"`
|
||||
RawOffset int `json:"rawoffset"`
|
||||
NextRawOffset int `json:"nextrawoffset"`
|
||||
HasMore bool `json:"hasmore"`
|
||||
Lines []*LineType `json:"lines"`
|
||||
Cmds []*CmdType `json:"cmds"`
|
||||
}
|
||||
|
||||
type RemoteEditType struct {
|
||||
RemoteEdit bool `json:"remoteedit"`
|
||||
RemoteId string `json:"remoteid,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user