dontstore
This commit is contained in:
parent
f16f545961
commit
89c0d0e519
4 changed files with 36 additions and 5 deletions
|
@ -48,14 +48,26 @@ type Call struct {
|
||||||
TalkgroupGroup *string
|
TalkgroupGroup *string
|
||||||
TalkgroupLabel *string
|
TalkgroupLabel *string
|
||||||
TalkgroupTag *string
|
TalkgroupTag *string
|
||||||
|
|
||||||
|
shouldStore bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Make(call *Call) (*Call, error) {
|
func (c *Call) String() string {
|
||||||
|
return fmt.Sprintf("%s to %d from %d", c.AudioName, c.Talkgroup, c.Source)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Call) ShouldStore() bool {
|
||||||
|
return c.shouldStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func Make(call *Call, dontStore bool) (*Call, error) {
|
||||||
err := call.computeLength()
|
err := call.computeLength()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
call.shouldStore = dontStore
|
||||||
|
|
||||||
return call, nil
|
return call, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"dynatron.me/x/stillbox/pkg/gordio/database"
|
"dynatron.me/x/stillbox/pkg/gordio/database"
|
||||||
"dynatron.me/x/stillbox/pkg/pb"
|
"dynatron.me/x/stillbox/pkg/pb"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"google.golang.org/protobuf/types/known/structpb"
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
)
|
)
|
||||||
|
@ -45,7 +46,9 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
|
||||||
db := database.FromCtx(ctx)
|
db := database.FromCtx(ctx)
|
||||||
tgi, err := db.GetTalkgroupWithLearned(ctx, int(tg.System), int(tg.Talkgroup))
|
tgi, err := db.GetTalkgroupWithLearned(ctx, int(tg.System), int(tg.Talkgroup))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err != pgx.ErrNoRows {
|
||||||
log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("get talkgroup fail")
|
log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("get talkgroup fail")
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@ func NewDatabaseSink(db *database.DB) *DatabaseSink {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error {
|
func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error {
|
||||||
|
if !call.ShouldStore() {
|
||||||
|
log.Debug().Str("call", call.String()).Msg("received dontStore call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
dbCall, err := s.db.AddCall(ctx, s.toAddCallParams(call))
|
dbCall, err := s.db.AddCall(ctx, s.toAddCallParams(call))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("add call: %w", err)
|
return fmt.Errorf("add call: %w", err)
|
||||||
|
|
|
@ -56,6 +56,7 @@ type callUploadRequest struct {
|
||||||
TalkgroupGroup string `form:"talkgroupGroup"`
|
TalkgroupGroup string `form:"talkgroupGroup"`
|
||||||
TalkgroupLabel string `form:"talkgroupLabel"`
|
TalkgroupLabel string `form:"talkgroupLabel"`
|
||||||
TalkgroupTag string `form:"talkgroupTag"`
|
TalkgroupTag string `form:"talkgroupTag"`
|
||||||
|
DontStore bool `form:"dontStore"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (car *callUploadRequest) mimeType() string {
|
func (car *callUploadRequest) mimeType() string {
|
||||||
|
@ -89,7 +90,7 @@ func (car *callUploadRequest) toCall(submitter auth.UserID) (*calls.Call, error)
|
||||||
TalkgroupTag: common.PtrOrNull(car.TalkgroupTag),
|
TalkgroupTag: common.PtrOrNull(car.TalkgroupTag),
|
||||||
TalkgroupGroup: common.PtrOrNull(car.TalkgroupGroup),
|
TalkgroupGroup: common.PtrOrNull(car.TalkgroupGroup),
|
||||||
Source: car.Source,
|
Source: car.Source,
|
||||||
})
|
}, !car.DontStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *RdioHTTP) routeCallUpload(w http.ResponseWriter, r *http.Request) {
|
func (h *RdioHTTP) routeCallUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -184,13 +185,24 @@ func (car *callUploadRequest) fill(r *http.Request) error {
|
||||||
}
|
}
|
||||||
f.Set(reflect.ValueOf(ar))
|
f.Set(reflect.ValueOf(ar))
|
||||||
case int:
|
case int:
|
||||||
val, err := strconv.Atoi(r.Form.Get(formField))
|
ff := r.Form.Get(formField)
|
||||||
|
val, err := strconv.Atoi(ff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("atoi('%s'): %w", formField, err)
|
return fmt.Errorf("atoi('%s'): %w", ff, err)
|
||||||
}
|
}
|
||||||
f.SetInt(int64(val))
|
f.SetInt(int64(val))
|
||||||
case string:
|
case string:
|
||||||
f.SetString(r.Form.Get(formField))
|
f.SetString(r.Form.Get(formField))
|
||||||
|
case bool:
|
||||||
|
ff := r.Form.Get(formField)
|
||||||
|
if ff == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val, err := strconv.ParseBool(ff)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("parsebool('%s'): %w", ff, err)
|
||||||
|
}
|
||||||
|
f.SetBool(val)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unsupported type %T", v))
|
panic(fmt.Errorf("unsupported type %T", v))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue