Make makeCall
This commit is contained in:
parent
d4b3d57a89
commit
7638564b81
3 changed files with 20 additions and 12 deletions
|
@ -50,6 +50,15 @@ type Call struct {
|
|||
TalkgroupTag *string
|
||||
}
|
||||
|
||||
func Make(call *Call) (*Call, error) {
|
||||
err := call.computeLength()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return call, nil
|
||||
}
|
||||
|
||||
func toInt64Slice(s []int) []int64 {
|
||||
n := make([]int64, len(s))
|
||||
for i := range s {
|
||||
|
@ -85,7 +94,7 @@ func (c *Call) ToPB() *pb.Call {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Call) ComputeLength() (err error) {
|
||||
func (c *Call) computeLength() (err error) {
|
||||
var td time.Duration
|
||||
|
||||
switch c.AudioType {
|
||||
|
|
|
@ -4,15 +4,8 @@ import (
|
|||
"context"
|
||||
|
||||
"dynatron.me/x/stillbox/pkg/calls"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *Server) Ingest(ctx context.Context, call *calls.Call) {
|
||||
err := call.ComputeLength()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("compute length failed")
|
||||
}
|
||||
|
||||
s.sinks.EmitCall(context.Background(), call)
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ func (car *callUploadRequest) mimeType() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (car *callUploadRequest) toCall(submitter auth.UserID) *calls.Call {
|
||||
return &calls.Call{
|
||||
func (car *callUploadRequest) toCall(submitter auth.UserID) (*calls.Call, error) {
|
||||
return calls.Make(&calls.Call{
|
||||
Submitter: &submitter,
|
||||
System: car.System,
|
||||
Talkgroup: car.Talkgroup,
|
||||
|
@ -89,7 +89,7 @@ func (car *callUploadRequest) toCall(submitter auth.UserID) *calls.Call {
|
|||
TalkgroupTag: common.PtrOrNull(car.TalkgroupTag),
|
||||
TalkgroupGroup: common.PtrOrNull(car.TalkgroupGroup),
|
||||
Source: car.Source,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RdioHTTP) routeCallUpload(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -120,7 +120,13 @@ func (h *RdioHTTP) routeCallUpload(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
h.ing.Ingest(ctx, cur.toCall(*submitter))
|
||||
call, err := cur.toCall(*submitter)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("toCall failed")
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
h.ing.Ingest(ctx, call)
|
||||
|
||||
log.Info().Int("system", cur.System).Int("tgid", cur.Talkgroup).Msg("ingested")
|
||||
|
||||
|
|
Loading…
Reference in a new issue