Skip to content

Commit

Permalink
Add init_user_credits config
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh authored and lyricat committed Mar 23, 2023
1 parent 95ff537 commit 2263004
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion cmd/httpd/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func NewCmdHttpd() *cobra.Command {
indexes := index.New(ctx, milvusClient)

userz := userServ.New(userServ.Config{
ExtraRate: cfg.Sys.ExtraRate,
ExtraRate: cfg.Sys.ExtraRate,
InitUserCredits: cfg.Sys.InitUserCredits,
}, client, users)
indexService := indexServ.NewService(ctx, gptHandler, indexes, userz)

Expand Down
1 change: 1 addition & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ openai:
sys:
secret_key: ""
extra_rate: 0.1
init_user_credits: 0.1

milvus:
address: "localhost:19530"
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ type DBConfig struct {
}

type System struct {
ExtraRate float64 `yaml:"extra_rate"`
SecretKey string `yaml:"secret_key"`
ExtraRate float64 `yaml:"extra_rate"`
InitUserCredits float64 `yaml:"init_user_credits"`
SecretKey string `yaml:"secret_key"`
}

type Auth struct {
Expand Down
4 changes: 2 additions & 2 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type (
App struct {
ID uint64 `json:"id"`
AppID string `json:"app_id"`
AppSecret string `json:"app_secret"`
SecureAppSecret string `json:"-"`
AppSecret string `gorm:"-" json:"app_secret"`
SecureAppSecret string `gorm:"-" json:"-"`
AppSecretEncrypted string `json:"-"`
UserID uint64 `json:"user_id"`
Name string `json:"name"`
Expand Down
4 changes: 2 additions & 2 deletions core/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ type (
// (
// @fullName, @avatarURL,
// @mixinUserID, @mixinIdentityNumber,
// @lang, 1,
// @lang, @credits,
// @mvmPublicKey,
// NOW(), NOW()
// )
// RETURNING "id"
CreateUser(ctx context.Context, fullName, avatarURL, mixinUserID, mixinIdentityNumber, lang, mvmPublicKey string) (uint64, error)
CreateUser(ctx context.Context, fullName, avatarURL, mixinUserID, mixinIdentityNumber, lang, mvmPublicKey string, credits decimal.Decimal) (uint64, error)

// UPDATE @@table
// {{set}}
Expand Down
5 changes: 3 additions & 2 deletions service/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func New(
}

type Config struct {
ExtraRate float64
ExtraRate float64
InitUserCredits float64
}

type UserService struct {
Expand Down Expand Up @@ -110,7 +111,7 @@ func (s *UserService) LoginWithMixin(ctx context.Context, token, pubkey, lang st
// create
if errors.Is(err, gorm.ErrRecordNotFound) {
newUserId, err := s.users.CreateUser(ctx, user.FullName, user.AvatarURL, user.MixinUserID, user.MixinIdentityNumber,
user.Lang, user.MvmPublicKey)
user.Lang, user.MvmPublicKey, decimal.NewFromFloat(s.cfg.InitUserCredits))
if err != nil {
fmt.Printf("err users.Create: %v\n", err)
return nil, err
Expand Down
6 changes: 1 addition & 5 deletions store/app/dao/apps.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions store/user/dao/users.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2263004

Please sign in to comment.