diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index 4a941594d..d322d0132 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -2,6 +2,7 @@ package v1 import ( "errors" + "time" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/dto" @@ -87,7 +88,7 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) { func (b *BaseApi) SyncTime(c *gin.Context) { ntime, err := ntp.Getremotetime() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.SuccessWithData(c, time.Now().Format("2006-01-02 15:04:05 MST -0700")) return } diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go index e6b18938b..254020aea 100644 --- a/backend/app/dto/database.go +++ b/backend/app/dto/database.go @@ -21,7 +21,7 @@ type MysqlDBInfo struct { type MysqlDBCreate struct { Name string `json:"name" validate:"required"` - Format string `json:"format" validate:"required,oneof=utf8mb4 utf-8 gbk big5"` + Format string `json:"format" validate:"required,oneof=utf8mb4 utf8 gbk big5"` Username string `json:"username" validate:"required"` Password string `json:"password" validate:"required"` Permission string `json:"permission" validate:"required"` diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index 79e3a10bf..6f59782dc 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -154,6 +154,13 @@ func (u *MysqlService) ListDBName() ([]string, error) { return dbNames, err } +var formatMap = map[string]string{ + "utf8": "utf8_general_ci", + "utf8mb4": "utf8mb4_general_ci", + "gbk": "gbk_chinese_ci", + "big5": "big5_chinese_ci", +} + func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*model.DatabaseMysql, error) { if req.Username == "root" { return nil, errors.New("Cannot set root as user name") @@ -170,7 +177,8 @@ func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*mode return nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) } - if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists `%s` character set=%s", req.Name, req.Format)); err != nil { + createSql := fmt.Sprintf("create database if not exists `%s` default character set %s collate %s", req.Name, req.Format, formatMap[req.Format]) + if err := excuteSql(app.ContainerName, app.Password, createSql); err != nil { return nil, err } tmpPermission := req.Permission diff --git a/frontend/index.html b/frontend/index.html index 63e019d81..fa89b6e6c 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ -