diff --git a/.gitignore b/.gitignore index bb40d4fc..d6aebbb2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ sonic.db sonic __debug_bin /resources/template/theme/ -!/resources/template/theme/default-theme-anatole \ No newline at end of file +!/resources/template/theme/default-theme-anatole +/conf/config.local.yaml \ No newline at end of file diff --git a/scripts/gen/generate.go b/scripts/gen/generate.go new file mode 100644 index 00000000..67243635 --- /dev/null +++ b/scripts/gen/generate.go @@ -0,0 +1,70 @@ +package main + +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 +} diff --git a/scripts/generate.sh b/scripts/generate.sh new file mode 100755 index 00000000..5387a0bf --- /dev/null +++ b/scripts/generate.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +PROJECT_DIR=$(dirname "$0") +GENERATE_DIR="$PROJECT_DIR/gen" + +cd "$GENERATE_DIR" || exit + +echo "Start Generating" +go run . diff --git a/service/impl/install.go b/service/impl/install.go index 93695834..780ea803 100644 --- a/service/impl/install.go +++ b/service/impl/install.go @@ -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