🐛 Bug fixes in grpc unable to get avatar and banner url

This commit is contained in:
LittleSheep 2024-05-22 23:21:31 +08:00
parent 31139e943f
commit 4fb4abda89

View File

@ -3,6 +3,7 @@ package grpc
import ( import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto" "git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/passport/pkg/services" "git.solsynth.dev/hydrogen/passport/pkg/services"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
@ -19,21 +20,29 @@ func (v *Server) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto.
} else { } else {
user := ctx.Account user := ctx.Account
rawPerms, _ := jsoniter.Marshal(perms) rawPerms, _ := jsoniter.Marshal(perms)
userinfo := &proto.Userinfo{
Id: uint64(user.ID),
Name: user.Name,
Nick: user.Nick,
Email: user.GetPrimaryEmail().Content,
Description: &user.Description,
}
if user.Avatar != nil {
userinfo.Avatar = fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *user.Avatar)
}
if user.Banner != nil {
userinfo.Banner = fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *user.Banner)
}
return &proto.AuthReply{ return &proto.AuthReply{
IsValid: true, IsValid: true,
AccessToken: &atk, AccessToken: &atk,
RefreshToken: &rtk, RefreshToken: &rtk,
Permissions: rawPerms, Permissions: rawPerms,
TicketId: lo.ToPtr(uint64(ctx.Ticket.ID)), TicketId: lo.ToPtr(uint64(ctx.Ticket.ID)),
Userinfo: &proto.Userinfo{ Userinfo: userinfo,
Id: uint64(user.ID),
Name: user.Name,
Nick: user.Nick,
Email: user.GetPrimaryEmail().Content,
Avatar: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Avatar),
Banner: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Banner),
Description: &user.Description,
},
}, nil }, nil
} }
} }