Skip to content

Commit

Permalink
video, mission
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Oct 25, 2023
1 parent 8fa4a5e commit dd48e24
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
33 changes: 33 additions & 0 deletions cmd/goatak_server/marti_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func addMartiRoutes(app *App, api *air.Air, name string) {
api.GET("/Marti/api/device/profile/connection", getProfileConnectionHandler(app, name))

api.GET("/Marti/api/missions", getMissionsHandler(app, name))
api.GET("/Marti/api/missions/", getMissionsHandler(app, name))
api.GET("/Marti/api/missions/:missionname", getMissionHandler(app, name))

api.GET("/Marti/sync/content", getMetadataGetHandler(app, name))
api.GET("/Marti/sync/search", getSearchHandler(app, name))
Expand All @@ -65,6 +67,8 @@ func addMartiRoutes(app *App, api *air.Air, name string) {

api.GET("/Marti/vcm", getVideoListHandler(app, name))
api.POST("/Marti/vcm", getVideoPostHandler(app, name))

api.GET("/Marti/api/video", getVideo2ListHandler(app, name))
}

func getVersionHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
Expand Down Expand Up @@ -321,6 +325,17 @@ func getMissionsHandler(app *App, name string) func(req *air.Request, res *air.R
}
}

func getMissionHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
logger := app.Logger.With(zap.String("api", name), zap.String("user", user))
logger.Infof("%s %s", req.Method, req.Path)

m := GetDefault(getStringParam(req, "missionname"))
return res.WriteJSON(makeAnswer("Mission", []any{m}))
}
}

func getProfileConnectionHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
Expand Down Expand Up @@ -368,6 +383,24 @@ func getVideoListHandler(app *App, name string) func(req *air.Request, res *air.
}
}

func getVideo2ListHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
logger := app.Logger.With(zap.String("api", name), zap.String("user", user))
logger.Infof("%s %s", req.Method, req.Path)

conn := make([]*model.VideoConnections2, 0)
app.feeds.ForEach(func(f *model.Feed2) bool {
conn = append(conn, &model.VideoConnections2{Feeds: []*model.Feed2{f}})
return true
})

r := make(map[string]any)
r["videoConnections"] = conn
return res.WriteJSON(r)
}
}

func getVideoPostHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
Expand Down
47 changes: 47 additions & 0 deletions cmd/goatak_server/mission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import "time"

type Mission struct {
Name string `json:"name"`
Description string `json:"description"`
ChatRoom string `json:"chatRoom"`
BaseLayer string `json:"baseLayer"`
Bbox string `json:"bbox"`
Path string `json:"path"`
Classification string `json:"classification"`
Tool string `json:"tool"`
Keywords []any `json:"keywords"`
CreatorUID string `json:"creatorUid"`
CreateTime time.Time `json:"createTime"`
ExternalData []any `json:"externalData"`
Feeds []any `json:"feeds"`
MapLayers []any `json:"mapLayers"`
DefaultRole struct {
Permissions []string `json:"permissions"`
Type string `json:"type"`
} `json:"defaultRole"`
OwnerRole 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"`
}

func GetDefault(name string) *Mission {
m := new(Mission)

m.Name = name
m.DefaultRole.Type = "MISSION_SUBSCRIBER"
m.DefaultRole.Permissions = []string{"MISSION_WRITE", "MISSION_READ"}
m.OwnerRole.Type = "MISSION_OWNER"
m.OwnerRole.Permissions = []string{"MISSION_MANAGE_FEEDS", "MISSION_SET_PASSWORD", "MISSION_WRITE", "MISSION_MANAGE_LAYERS", "MISSION_UPDATE_GROUPS", "MISSION_READ", "MISSION_DELETE", "MISSION_SET_ROLE"}

return m
}
5 changes: 4 additions & 1 deletion cmd/webclient/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"
)

const renewContacts = time.Second * 30

func (app *App) getContacts() error {
url := ""
if app.tls {
Expand Down Expand Up @@ -43,14 +45,15 @@ func (app *App) getContacts() error {

app.Logger.Debugf("got %d contacts", len(dat))
for _, c := range dat {
app.Logger.Debugf("contact %s %s", c.Uid, c.Callsign)
app.messages.Contacts.Store(c.Uid, c)
}

return nil
}

func (app *App) periodicGetter(ctx context.Context) {
ticker := time.NewTicker(time.Second * 30)
ticker := time.NewTicker(renewContacts)
defer ticker.Stop()

_ = app.getContacts()
Expand Down
1 change: 1 addition & 0 deletions internal/repository/feeds_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (r *FeedsFileRepository) load(fname string) *model.Feed2 {
r.logger.Errorf("error: %s", err.Error())
}

f.Active = true
return f
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/model/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type VideoConnections struct {
Feeds []*Feed `xml:"feed"`
}

type VideoConnections2 struct {
XMLName xml.Name `json:"-"`
Feeds []*Feed2 `xml:"feed" json:"feeds"`
}

type Feed struct {
Uid string `xml:"uid" yaml:"uid"`
Active bool `xml:"active" yaml:"active,omitempty"`
Expand Down Expand Up @@ -50,14 +55,15 @@ type Feed struct {

type Feed2 struct {
Uid string `yaml:"uid" json:"uid,omitempty"`
Active bool `yaml:"active" json:"active"`
Alias string `yaml:"alias" json:"alias,omitempty"`
Url string `yaml:"url" json:"url,omitempty"`
Latitude float64 `yaml:"lat,omitempty" json:"lat,omitempty"`
Longitude float64 `yaml:"lon,omitempty" json:"lon,omitempty"`
Fov string `yaml:"fov,omitempty" json:"fov,omitempty"`
Heading string `yaml:"heading,omitempty" json:"heading,omitempty"`
Range string `yaml:"range,omitempty" json:"range,omitempty"`
User string `yaml:"user"`
User string `yaml:"user" json:"-"`
}

func (f *Feed2) ToFeed() *Feed {
Expand Down Expand Up @@ -105,6 +111,7 @@ func (f *Feed) ToFeed2() *Feed2 {
}

return &Feed2{
Active: f.Active,
Uid: f.Uid,
Alias: f.Alias,
Url: toUrl(f.Protocol, f.Address, f.Port, f.Path),
Expand Down

0 comments on commit dd48e24

Please sign in to comment.