♻️ 迁移到 Dealer #3
10
go.mod
10
go.mod
@ -3,21 +3,18 @@ module git.solsynth.dev/hydrogen/interactive
|
||||
go 1.21.6
|
||||
|
||||
require (
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951
|
||||
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745
|
||||
git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a
|
||||
github.com/go-playground/validator/v10 v10.17.0
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
github.com/gofiber/template/html/v2 v2.1.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/hashicorp/consul/api v1.29.1
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/pemistahl/lingua-go v1.4.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/samber/lo v1.39.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
golang.org/x/crypto v0.24.0
|
||||
google.golang.org/grpc v1.64.0
|
||||
gorm.io/datatypes v1.2.0
|
||||
gorm.io/driver/postgres v1.5.4
|
||||
@ -36,6 +33,7 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||
github.com/gofiber/template v1.8.3 // indirect
|
||||
github.com/gofiber/utils v1.1.0 // indirect
|
||||
github.com/hashicorp/consul/api v1.29.1 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
||||
@ -64,7 +62,6 @@ require (
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/pemistahl/lingua-go v1.4.0 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
@ -81,6 +78,7 @@ require (
|
||||
github.com/valyala/fasthttp v1.52.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/crypto v0.24.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
|
||||
golang.org/x/net v0.26.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
|
14
go.sum
14
go.sum
@ -1,9 +1,9 @@
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024414-abba3b1c259d h1:cBDO9mJRz6BW3OXm14svCb+LtERp332nOmrfs6AKNQg=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024414-abba3b1c259d/go.mod h1:eZwAwP7ahL7TO8GWBlYFYDdjlna+8zHYbDfNabnuUEU=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951 h1:RgZJK4PXhrjhUX75BclBCg2xfetMkswcMwMqfTBtryQ=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951/go.mod h1:eZwAwP7ahL7TO8GWBlYFYDdjlna+8zHYbDfNabnuUEU=
|
||||
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 h1:40BUsQMNXjqHyytkyF9py1HjTAWlRgO6R57YXUrHNy4=
|
||||
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745/go.mod h1:FsQGSLTl0gvo+9Jmbot02S72suyF9tFTrzDj70Xhifo=
|
||||
git.solsynth.dev/hydrogen/passport v0.0.0-20240623081149-7ddbea8bcb86 h1:cxjBOhemnyxf49CJyPmnt1RKFHerK45rXXBPwsIFrhA=
|
||||
git.solsynth.dev/hydrogen/passport v0.0.0-20240623081149-7ddbea8bcb86/go.mod h1:tUr7x1v0trG3ALDacdDuhJiPRPgFhJ1Si9OqNlYbgSk=
|
||||
git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a h1:oxNbS6Q+sSOfYUQTcx9/awCmlk/lpVP997hgpMmFsyw=
|
||||
git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a/go.mod h1:tUr7x1v0trG3ALDacdDuhJiPRPgFhJ1Si9OqNlYbgSk=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
@ -68,8 +68,6 @@ github.com/gofiber/template/html/v2 v2.1.1/go.mod h1:2G0GHHOUx70C1LDncoBpe4T6maQ
|
||||
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
|
||||
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
||||
@ -147,8 +145,6 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
@ -310,8 +306,6 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
|
||||
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
|
@ -1,12 +0,0 @@
|
||||
package gap
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/hyper"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var H *hyper.HyperConn
|
||||
|
||||
func NewHyperClient() {
|
||||
H = hyper.NewHyperConn(viper.GetString("consul.addr"))
|
||||
}
|
@ -2,38 +2,41 @@ package gap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"github.com/rs/zerolog/log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func Register() error {
|
||||
cfg := api.DefaultConfig()
|
||||
cfg.Address = viper.GetString("consul.addr")
|
||||
|
||||
client, err := api.NewClient(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var H *hyper.HyperConn
|
||||
|
||||
func RegisterService() error {
|
||||
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
||||
httpBind := strings.SplitN(viper.GetString("bind"), ":", 2)
|
||||
|
||||
outboundIp, _ := GetOutboundIP()
|
||||
port, _ := strconv.Atoi(grpcBind[1])
|
||||
|
||||
registration := new(api.AgentServiceRegistration)
|
||||
registration.ID = viper.GetString("id")
|
||||
registration.Name = "Hydrogen.Interactive"
|
||||
registration.Address = outboundIp.String()
|
||||
registration.Port = port
|
||||
registration.Check = &api.AgentServiceCheck{
|
||||
GRPC: fmt.Sprintf("%s:%s", outboundIp, grpcBind[1]),
|
||||
Timeout: "5s",
|
||||
Interval: "1m",
|
||||
DeregisterCriticalServiceAfter: "3m",
|
||||
grpcOutbound := fmt.Sprintf("%s:%s", outboundIp, grpcBind[1])
|
||||
httpOutbound := fmt.Sprintf("%s:%s", outboundIp, httpBind[1])
|
||||
|
||||
var err error
|
||||
H, err = hyper.NewHyperConn(viper.GetString("dealer.addr"), &proto.ServiceInfo{
|
||||
Id: viper.GetString("id"),
|
||||
Type: hyper.ServiceTypeAuthProvider,
|
||||
Label: "Passport",
|
||||
GrpcAddr: grpcOutbound,
|
||||
HttpAddr: &httpOutbound,
|
||||
})
|
||||
if err == nil {
|
||||
go func() {
|
||||
err := H.KeepRegisterService()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred while registering service...")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return client.Agent().ServiceRegister(registration)
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package exts
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/services"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func LinkAccountMiddleware(c *fiber.Ctx) error {
|
||||
if val, ok := c.Locals("p_user").(*proto.Userinfo); ok {
|
||||
if val, ok := c.Locals("p_user").(*proto.UserInfo); ok {
|
||||
if account, err := services.LinkAccount(val); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
|
@ -2,62 +2,37 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) {
|
||||
var user models.Account
|
||||
if err := database.C.Where("id = ?", userId).First(&user).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var related models.Account
|
||||
if err := database.C.Where("id = ?", relatedId).First(&related).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func NotifyPosterAccount(user models.Account, title, body string, subtitle *string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return proto.NewFriendshipsClient(pc).GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{
|
||||
AccountId: uint64(user.ExternalID),
|
||||
RelatedId: uint64(related.ExternalID),
|
||||
Status: uint32(status),
|
||||
})
|
||||
}
|
||||
|
||||
func NotifyPosterAccount(user models.Account, subject, content string, links ...*proto.NotifyLink) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = proto.NewNotifyClient(pc).NotifyUser(ctx, &proto.NotifyRequest{
|
||||
ClientId: viper.GetString("passport.client_id"),
|
||||
ClientSecret: viper.GetString("passport.client_secret"),
|
||||
Type: "interactive.feedback",
|
||||
Subject: subject,
|
||||
Content: content,
|
||||
Links: links,
|
||||
RecipientId: uint64(user.ExternalID),
|
||||
IsRealtime: false,
|
||||
IsForcePush: true,
|
||||
_, err = proto.NewNotifierClient(pc).NotifyUser(ctx, &proto.NotifyUserRequest{
|
||||
UserId: uint64(user.ExternalID),
|
||||
Notify: &proto.NotifyRequest{
|
||||
Topic: "interactive.feedback",
|
||||
Title: title,
|
||||
Subtitle: subtitle,
|
||||
Body: body,
|
||||
IsRealtime: false,
|
||||
IsForcePush: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("An error occurred when notify account...")
|
||||
} else {
|
||||
log.Debug().Uint("eid", user.ExternalID).Msg("Notified account.")
|
||||
log.Debug().Uint("uid", user.ExternalID).Msg("Notified account.")
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/viper"
|
||||
@ -211,12 +210,11 @@ func ReactArticle(user models.Account, reaction models.Reaction) (bool, models.R
|
||||
Preload("Author").
|
||||
First(&op).Error; err == nil {
|
||||
if op.Author.ID != user.ID {
|
||||
articleUrl := fmt.Sprintf("https://%s/articles/%s", viper.GetString("domain"), op.Alias)
|
||||
err := NotifyPosterAccount(
|
||||
err = NotifyPosterAccount(
|
||||
op.Author,
|
||||
fmt.Sprintf("%s reacted your article", user.Nick),
|
||||
"Article got reacted",
|
||||
fmt.Sprintf("%s (%s) reacted your article a %s", user.Nick, user.Name, reaction.Symbol),
|
||||
&proto.NotifyLink{Label: "Related article", Url: articleUrl},
|
||||
lo.ToPtr(fmt.Sprintf("%s reacted your article", user.Nick)),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when notifying user...")
|
||||
|
@ -2,13 +2,14 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hydrogen/paperclip/pkg/proto"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func CheckAttachmentByIDExists(id uint, usage string) bool {
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Paperclip")
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeFileProvider)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ package services
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func LinkAccount(userinfo *proto.Userinfo) (models.Account, error) {
|
||||
func LinkAccount(userinfo *proto.UserInfo) (models.Account, error) {
|
||||
var account models.Account
|
||||
if userinfo == nil {
|
||||
return account, fmt.Errorf("remote userinfo was not found")
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/viper"
|
||||
@ -266,12 +265,11 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
||||
Preload("Author").
|
||||
First(&op).Error; err == nil {
|
||||
if op.Author.ID != user.ID {
|
||||
postUrl := fmt.Sprintf("https://%s/posts/%s", viper.GetString("domain"), item.Alias)
|
||||
err := NotifyPosterAccount(
|
||||
err = NotifyPosterAccount(
|
||||
op.Author,
|
||||
fmt.Sprintf("%s replied you", user.Nick),
|
||||
"Post got replied",
|
||||
fmt.Sprintf("%s (%s) replied your post #%s.", user.Nick, user.Name, op.Alias),
|
||||
&proto.NotifyLink{Label: "Related post", Url: postUrl},
|
||||
lo.ToPtr(fmt.Sprintf("%s replied you", user.Nick)),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when notifying user...")
|
||||
@ -308,12 +306,11 @@ func ReactPost(user models.Account, reaction models.Reaction) (bool, models.Reac
|
||||
Preload("Author").
|
||||
First(&op).Error; err == nil {
|
||||
if op.Author.ID != user.ID {
|
||||
postUrl := fmt.Sprintf("https://%s/posts/%s", viper.GetString("domain"), op.Alias)
|
||||
err := NotifyPosterAccount(
|
||||
err = NotifyPosterAccount(
|
||||
op.Author,
|
||||
fmt.Sprintf("%s reacted your post", user.Nick),
|
||||
fmt.Sprintf("%s (%s) reacted your post a %s", user.Nick, user.Name, reaction.Symbol),
|
||||
&proto.NotifyLink{Label: "Related post", Url: postUrl},
|
||||
"Post got replied",
|
||||
fmt.Sprintf("%s (%s) replied your post #%s.", user.Nick, user.Name, op.Alias),
|
||||
lo.ToPtr(fmt.Sprintf("%s replied you", user.Nick)),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when notifying user...")
|
||||
|
@ -4,10 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
"github.com/samber/lo"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
@ -15,11 +16,11 @@ import (
|
||||
|
||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||
var realm models.Realm
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
|
||||
if err != nil {
|
||||
return realm, err
|
||||
}
|
||||
response, err := proto.NewRealmsClient(pc).GetRealm(context.Background(), &proto.RealmLookupRequest{
|
||||
response, err := proto.NewRealmClient(pc).GetRealm(context.Background(), &proto.LookupRealmRequest{
|
||||
Id: lo.ToPtr(uint64(id)),
|
||||
})
|
||||
if err != nil {
|
||||
@ -30,11 +31,11 @@ func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||
|
||||
func GetRealmWithAlias(alias string) (models.Realm, error) {
|
||||
var realm models.Realm
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
|
||||
if err != nil {
|
||||
return realm, err
|
||||
}
|
||||
response, err := proto.NewRealmsClient(pc).GetRealm(context.Background(), &proto.RealmLookupRequest{
|
||||
response, err := proto.NewRealmClient(pc).GetRealm(context.Background(), &proto.LookupRealmRequest{
|
||||
Alias: &alias,
|
||||
})
|
||||
if err != nil {
|
||||
@ -43,16 +44,16 @@ func GetRealmWithAlias(alias string) (models.Realm, error) {
|
||||
return LinkRealm(response)
|
||||
}
|
||||
|
||||
func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberResponse, error) {
|
||||
func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberInfo, error) {
|
||||
var realm models.Realm
|
||||
if err := database.C.Where("id = ?", realmId).First(&realm).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := proto.NewRealmsClient(pc).GetRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
|
||||
response, err := proto.NewRealmClient(pc).GetRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
|
||||
RealmId: uint64(realm.ExternalID),
|
||||
UserId: lo.ToPtr(uint64(userId)),
|
||||
})
|
||||
@ -63,22 +64,7 @@ func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberResponse, erro
|
||||
}
|
||||
}
|
||||
|
||||
func ListRealmMember(realmId uint) ([]*proto.RealmMemberResponse, error) {
|
||||
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := proto.NewRealmsClient(pc).ListRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
|
||||
RealmId: uint64(realmId),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return response.Data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func LinkRealm(info *proto.RealmResponse) (models.Realm, error) {
|
||||
func LinkRealm(info *proto.RealmInfo) (models.Realm, error) {
|
||||
var realm models.Realm
|
||||
if info == nil {
|
||||
return realm, fmt.Errorf("remote realm info was not found")
|
||||
|
@ -42,10 +42,8 @@ func main() {
|
||||
}
|
||||
|
||||
// Connect other services
|
||||
if err := gap.Register(); err != nil {
|
||||
if err := gap.RegisterService(); err != nil {
|
||||
log.Fatal().Err(err).Msg("An error occurred when connecting to consul...")
|
||||
} else {
|
||||
gap.NewHyperClient()
|
||||
}
|
||||
|
||||
// Configure timed tasks
|
||||
|
@ -11,15 +11,8 @@ secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
|
||||
database = false
|
||||
print_routes = false
|
||||
|
||||
[paperclip]
|
||||
endpoint = "http://localhost:8443"
|
||||
grpc_endpoint = "localhost:7443"
|
||||
|
||||
[passport]
|
||||
client_id = "solarplaza"
|
||||
client_secret = "Z9k9AFTj^p"
|
||||
endpoint = "http://localhost:8444"
|
||||
grpc_endpoint = "localhost:7444"
|
||||
[dealer]
|
||||
addr = "127.0.0.1:7442"
|
||||
|
||||
[mailer]
|
||||
name = "Alphabot <alphabot@smartsheep.studio>"
|
||||
|
Loading…
Reference in New Issue
Block a user