dontstore

This commit is contained in:
Daniel 2024-08-18 08:44:44 -04:00
parent f16f545961
commit 89c0d0e519
4 changed files with 36 additions and 5 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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)

View file

@ -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))
}