add audioURL to shares
This commit is contained in:
parent
0adf3b4978
commit
3f4fe56ed0
3 changed files with 23 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue