diff --git a/pkg/calls/call.go b/pkg/calls/call.go index e523031..d3a4bc3 100644 --- a/pkg/calls/call.go +++ b/pkg/calls/call.go @@ -3,9 +3,11 @@ package calls import ( "encoding/json" "fmt" + "net/url" "time" "dynatron.me/x/stillbox/internal/audio" + "dynatron.me/x/stillbox/internal/common" "dynatron.me/x/stillbox/internal/jsontypes" "dynatron.me/x/stillbox/pkg/pb" "dynatron.me/x/stillbox/pkg/rbac/entities" @@ -94,6 +96,11 @@ func (c *Call) ShouldStore() bool { return c.shouldStore } +func (c *Call) SetShareURL(baseURL url.URL, shareID string) { + baseURL.Path = fmt.Sprintf("/share/%s/call", shareID) + c.AudioURL = common.PtrTo(baseURL.String()) +} + func Make(call *Call, dontStore bool) (*Call, error) { err := call.computeLength() if err != nil { diff --git a/pkg/incidents/incident.go b/pkg/incidents/incident.go index 0cc378b..9477454 100644 --- a/pkg/incidents/incident.go +++ b/pkg/incidents/incident.go @@ -2,8 +2,11 @@ package incidents import ( "encoding/json" + "fmt" + "net/url" "strings" + "dynatron.me/x/stillbox/internal/common" "dynatron.me/x/stillbox/internal/jsontypes" "dynatron.me/x/stillbox/pkg/calls" "dynatron.me/x/stillbox/pkg/rbac/entities" @@ -23,6 +26,13 @@ type Incident struct { Calls []IncidentCall `json:"calls"` } +func (inc *Incident) SetShareURL(bu url.URL, shareID string) { + bu.Path = fmt.Sprintf("/share/%s/call/", shareID) + for i := range inc.Calls { + inc.Calls[i].AudioURL = common.PtrTo(bu.String() + inc.Calls[i].ID.String()) + } +} + func (inc *Incident) GetResourceName() string { return entities.ResourceIncident } diff --git a/pkg/rest/share.go b/pkg/rest/share.go index d57b442..b0846da 100644 --- a/pkg/rest/share.go +++ b/pkg/rest/share.go @@ -35,9 +35,9 @@ const ( func (s *api) shareHandlers() ShareHandlers { return ShareHandlers{ ShareRequestCall: s.calls.shareCallRoute, - ShareRequestCallInfo: respondShareHandler(s.calls.getCallInfo), + ShareRequestCallInfo: s.respondShareHandler(s.calls.getCallInfo), ShareRequestCallDL: s.calls.shareCallDLRoute, - ShareRequestIncident: respondShareHandler(s.incidents.getIncident), + ShareRequestIncident: s.respondShareHandler(s.incidents.getIncident), ShareRequestIncidentM3U: s.incidents.getCallsM3U, ShareRequestTalkgroups: s.tgs.getTGsShareRoute, } @@ -65,6 +65,7 @@ type shareAPI struct { type EntityFunc func(ctx context.Context, id ID) (SharedItem, error) type SharedItem interface { + SetShareURL(baseURL url.URL, shareID string) } type shareResponse struct { @@ -81,7 +82,7 @@ func ShareFrom(ctx context.Context) *shares.Share { return nil } -func respondShareHandler(ie EntityFunc) ShareHandlerFunc { +func (s *api) respondShareHandler(ie EntityFunc) ShareHandlerFunc { return func(id ID, w http.ResponseWriter, r *http.Request) { ctx := r.Context() share := ShareFrom(ctx) @@ -102,6 +103,8 @@ func respondShareHandler(ie EntityFunc) ShareHandlerFunc { SharedItem: res, } + sRes.SharedItem.SetShareURL(*s.baseURL, share.ID) + respond(w, r, sRes) } }