From 89c0d0e51950052a841cc897730fefd5364de09b Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 18 Aug 2024 08:44:44 -0400 Subject: [PATCH] dontstore --- pkg/calls/call.go | 14 +++++++++++++- pkg/gordio/nexus/commands.go | 5 ++++- pkg/gordio/sinks/database.go | 4 ++++ pkg/gordio/sources/http.go | 18 +++++++++++++++--- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/pkg/calls/call.go b/pkg/calls/call.go index c5e569b..6c21f13 100644 --- a/pkg/calls/call.go +++ b/pkg/calls/call.go @@ -48,14 +48,26 @@ type Call struct { TalkgroupGroup *string TalkgroupLabel *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() if err != nil { return nil, err } + call.shouldStore = dontStore + return call, nil } diff --git a/pkg/gordio/nexus/commands.go b/pkg/gordio/nexus/commands.go index daa9390..c3147a0 100644 --- a/pkg/gordio/nexus/commands.go +++ b/pkg/gordio/nexus/commands.go @@ -8,6 +8,7 @@ import ( "dynatron.me/x/stillbox/pkg/gordio/database" "dynatron.me/x/stillbox/pkg/pb" + "github.com/jackc/pgx/v5" "github.com/rs/zerolog/log" "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) tgi, err := db.GetTalkgroupWithLearned(ctx, int(tg.System), int(tg.Talkgroup)) if err != nil { - log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("get talkgroup fail") + if err != pgx.ErrNoRows { + log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("get talkgroup fail") + } return err } diff --git a/pkg/gordio/sinks/database.go b/pkg/gordio/sinks/database.go index 458b574..f0d15d8 100644 --- a/pkg/gordio/sinks/database.go +++ b/pkg/gordio/sinks/database.go @@ -20,6 +20,10 @@ func NewDatabaseSink(db *database.DB) *DatabaseSink { } 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)) if err != nil { return fmt.Errorf("add call: %w", err) diff --git a/pkg/gordio/sources/http.go b/pkg/gordio/sources/http.go index cd574d8..9e70a91 100644 --- a/pkg/gordio/sources/http.go +++ b/pkg/gordio/sources/http.go @@ -56,6 +56,7 @@ type callUploadRequest struct { TalkgroupGroup string `form:"talkgroupGroup"` TalkgroupLabel string `form:"talkgroupLabel"` TalkgroupTag string `form:"talkgroupTag"` + DontStore bool `form:"dontStore"` } func (car *callUploadRequest) mimeType() string { @@ -89,7 +90,7 @@ func (car *callUploadRequest) toCall(submitter auth.UserID) (*calls.Call, error) TalkgroupTag: common.PtrOrNull(car.TalkgroupTag), TalkgroupGroup: common.PtrOrNull(car.TalkgroupGroup), Source: car.Source, - }) + }, !car.DontStore) } 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)) case int: - val, err := strconv.Atoi(r.Form.Get(formField)) + ff := r.Form.Get(formField) + val, err := strconv.Atoi(ff) if err != nil { - return fmt.Errorf("atoi('%s'): %w", formField, err) + return fmt.Errorf("atoi('%s'): %w", ff, err) } f.SetInt(int64(val)) case string: 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: panic(fmt.Errorf("unsupported type %T", v)) }