Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get avatar base url from option service #371

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ sonic.db
sonic
__debug_bin
/resources/template/theme/
!/resources/template/theme/default-theme-anatole
!/resources/template/theme/default-theme-anatole
/conf/config.local.yaml
70 changes: 70 additions & 0 deletions scripts/gen/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件是做什么用的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提错仓库了Orz

import (
"fmt"
"strings"

"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"

"gorm.io/gen"
)

const MySQLDSN = ""

var DB *gorm.DB

func init() {
DB = ConnectDB(MySQLDSN).Debug()
}

var dataMap = map[string]func(gorm.ColumnType) (dataType string){}

func main() {
g := gen.NewGenerator(gen.Config{
OutPath: "../../dal",
ModelPkgPath: "../../model/entity",
Mode: gen.WithDefaultQuery,

WithUnitTest: false,
//FieldNullable: true,
//FieldCoverable: true,
FieldWithIndexTag: true,
//FieldSignable: true,
FieldWithTypeTag: true,
})

g.WithModelNameStrategy(func(tableName string) (modelName string) {
if tableName == "meta" {
return "Meta"
}
return DB.NamingStrategy.SchemaName(tableName)
})
g.UseDB(DB)

//g.WithDataTypeMap(dataMap)
//g.WithJSONTagNameStrategy(func(c string) string { return "-" })
//
//g.ApplyBasic(dto.AttachmentDTO{})
g.ApplyBasic(g.GenerateAllTable()...)
g.GenerateAllTable()

g.Execute()
}

func ConnectDB(dsn string) (db *gorm.DB) {
var err error

if strings.HasSuffix(dsn, "sqlite.db") {
db, err = gorm.Open(sqlite.Open(dsn), &gorm.Config{})
} else {
db, err = gorm.Open(mysql.Open(dsn))
}

if err != nil {
panic(fmt.Errorf("connect db fail: %w", err))
}

return db
}
9 changes: 9 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

PROJECT_DIR=$(dirname "$0")
GENERATE_DIR="$PROJECT_DIR/gen"

cd "$GENERATE_DIR" || exit

echo "Start Generating"
go run .
3 changes: 2 additions & 1 deletion service/impl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ func (i installServiceImpl) createDefaultSetting(ctx context.Context, installPar

func (i installServiceImpl) createUser(ctx context.Context, user param.User) (*entity.User, error) {
emailMd5 := md5.Sum([]byte(user.Email))
avatar := "//cn.gravatar.com/avatar/" + hex.EncodeToString(emailMd5[:]) + "?s=256&d=mm"
avatarSource, err := i.OptionService.GetOrByDefaultWithErr(ctx, property.CommentGravatarSource, property.CommentGravatarSource.DefaultValue)
avatar := avatarSource.(string) + hex.EncodeToString(emailMd5[:]) + "?s=256&d=mm"
user.Avatar = avatar
userEntity, err := i.UerService.CreateByParam(ctx, user)
return userEntity, err
Expand Down