👽 Support better metadata encoder / decoder

This commit is contained in:
LittleSheep 2024-10-16 01:01:39 +08:00
parent be32ad1522
commit df8058e794
4 changed files with 13 additions and 13 deletions

View File

@ -4,10 +4,11 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: New login alert"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Bug fixes in non-cached notification preferences">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/preferences.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/preferences.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/ticket.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/ticket.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -154,7 +155,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Fix api key wasn't in auto maintain range" />
<MESSAGE value=":bug: Fix api key missing account id" /> <MESSAGE value=":bug: Fix api key missing account id" />
<MESSAGE value=":sparkles: Preload api key's ticket" /> <MESSAGE value=":sparkles: Preload api key's ticket" />
<MESSAGE value=":bug: Fix preloading issue" /> <MESSAGE value=":bug: Fix preloading issue" />
@ -179,7 +179,8 @@
<MESSAGE value=":sparkles: Implement event recorder grpc" /> <MESSAGE value=":sparkles: Implement event recorder grpc" />
<MESSAGE value=":sparkles: More event logs point" /> <MESSAGE value=":sparkles: More event logs point" />
<MESSAGE value=":sparkles: New login alert" /> <MESSAGE value=":sparkles: New login alert" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: New login alert" /> <MESSAGE value=":bug: Bug fixes in non-cached notification preferences" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Bug fixes in non-cached notification preferences" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22
toolchain go1.22.5 toolchain go1.22.5
require ( require (
git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782
github.com/dgraph-io/ristretto v0.1.1 github.com/dgraph-io/ristretto v0.1.1
github.com/eko/gocache/lib/v4 v4.1.6 github.com/eko/gocache/lib/v4 v4.1.6
github.com/eko/gocache/store/ristretto/v4 v4.2.2 github.com/eko/gocache/store/ristretto/v4 v4.2.2

2
go.sum
View File

@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 h1:1ACMPm2ArRpVNYrND/y/R6oPiuMfKe49fP+lG3mcNug= git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 h1:1ACMPm2ArRpVNYrND/y/R6oPiuMfKe49fP+lG3mcNug=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782 h1:HUgt8RmDp5AKLlT/QGk4QXcO23OEMVpRYRjgLfOf45c=
git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=

View File

@ -3,10 +3,10 @@ package grpc
import ( import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
jsoniter "github.com/json-iterator/go"
"github.com/samber/lo" "github.com/samber/lo"
"git.solsynth.dev/hydrogen/dealer/pkg/proto" "git.solsynth.dev/hydrogen/dealer/pkg/proto"
@ -21,8 +21,7 @@ func (v *Server) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*pr
return nil, fmt.Errorf("unable to get account: %v", err) return nil, fmt.Errorf("unable to get account: %v", err)
} }
var metadata map[string]any metadata := hyper.DecodeMap(in.GetNotify().GetMetadata())
_ = jsoniter.Unmarshal(in.GetNotify().GetMetadata(), &metadata)
notification := models.Notification{ notification := models.Notification{
Topic: in.GetNotify().GetTopic(), Topic: in.GetNotify().GetTopic(),
@ -64,8 +63,7 @@ func (v *Server) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchReq
return nil, fmt.Errorf("unable to get account: %v", err) return nil, fmt.Errorf("unable to get account: %v", err)
} }
var metadata map[string]any metadata := hyper.DecodeMap(in.GetNotify().GetMetadata())
_ = jsoniter.Unmarshal(in.GetNotify().GetMetadata(), &metadata)
var checklist = make(map[uint]bool, len(users)) var checklist = make(map[uint]bool, len(users))
var notifications []models.Notification var notifications []models.Notification
@ -113,8 +111,7 @@ func (v *Server) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*pro
return nil, fmt.Errorf("unable to get account: %v", err) return nil, fmt.Errorf("unable to get account: %v", err)
} }
var metadata map[string]any metadata := hyper.DecodeMap(in.GetMetadata())
_ = jsoniter.Unmarshal(in.GetMetadata(), &metadata)
var checklist = make(map[uint]bool, len(users)) var checklist = make(map[uint]bool, len(users))
var notifications []models.Notification var notifications []models.Notification