Skip to content

Commit

Permalink
track
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Oct 27, 2023
1 parent 71628f6 commit 7c647f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions cmd/goatak_server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func getAdminApi(app *App, addr string, renderer *staticfiles.Renderer, webtakRo
adminApi.GET("/connections", getConnHandler(app))

adminApi.GET("/unit", getUnitsHandler(app))
adminApi.GET("/unit/:uid/track", getUnitTrackHandler(app))
adminApi.DELETE("/unit/:uid", deleteItemHandler(app))

adminApi.GET("/takproto/1", getWsHandler(app))
Expand Down Expand Up @@ -172,6 +173,19 @@ func getUnits(app *App) []*model.WebUnit {
return units
}

func getUnitTrackHandler(app *App) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
uid := getStringParam(req, "uid")
item := app.items.Get(uid)
if item == nil {
res.Status = http.StatusNotFound
return nil
}

return res.WriteJSON(item.GetTrack())
}
}

func deleteItemHandler(app *App) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
uid := getStringParam(req, "uid")
Expand Down
16 changes: 8 additions & 8 deletions cmd/goatak_server/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Mission struct {
Path string `json:"path"`
Classification string `json:"classification"`
Tool string `json:"tool"`
Keywords []any `json:"keywords"`
Keywords []string `json:"keywords"`
CreatorUID string `json:"creatorUid"`
CreateTime time.Time `json:"createTime"`
ExternalData []any `json:"externalData"`
Expand All @@ -25,13 +25,13 @@ type Mission struct {
Permissions []string `json:"permissions"`
Type string `json:"type"`
} `json:"ownerRole"`
InviteOnly bool `json:"inviteOnly"`
Expiration int `json:"expiration"`
GUID string `json:"guid"`
Uids []any `json:"uids"`
Contents []any `json:"contents"`
Token string `json:"token"`
PasswordProtected bool `json:"passwordProtected"`
InviteOnly bool `json:"inviteOnly"`
Expiration int `json:"expiration"`
GUID string `json:"guid"`
Uids []string `json:"uids"`
Contents []any `json:"contents"`
Token string `json:"token"`
PasswordProtected bool `json:"passwordProtected"`
}

func GetDefault(name string) *Mission {
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ func (i *Item) Update(msg *cot.CotMessage) {
}
}

func (i *Item) GetTrack() []*Pos {
i.mx.RLock()
defer i.mx.RUnlock()

return i.track[:]
}

func (i *Item) UpdateFromWeb(w *WebUnit, m *cot.CotMessage) {
if w == nil {
return
Expand Down

0 comments on commit 7c647f2

Please sign in to comment.