mirror of https://gitee.com/answerdev/answer.git
feat: add install request limiting condition
This commit is contained in:
parent
9c8838a1b0
commit
f14040b9b8
|
@ -12,12 +12,14 @@ import (
|
|||
|
||||
const (
|
||||
DefaultConfigFileName = "config.yaml"
|
||||
DefaultCacheFileName = "cache.db"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigFilePath = "/conf/"
|
||||
UploadFilePath = "/upfiles/"
|
||||
I18nPath = "/i18n/"
|
||||
CachePath = "/cache/"
|
||||
)
|
||||
|
||||
// InstallAllInitialEnvironment install all initial environment
|
||||
|
@ -25,6 +27,7 @@ func InstallAllInitialEnvironment(dataDirPath string) {
|
|||
ConfigFilePath = filepath.Join(dataDirPath, ConfigFilePath)
|
||||
UploadFilePath = filepath.Join(dataDirPath, UploadFilePath)
|
||||
I18nPath = filepath.Join(dataDirPath, I18nPath)
|
||||
CachePath = filepath.Join(dataDirPath, CachePath)
|
||||
|
||||
installUploadDir()
|
||||
installI18nBundle()
|
||||
|
|
|
@ -2,6 +2,7 @@ package install
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/configs"
|
||||
|
@ -116,6 +117,9 @@ func InitEnvironment(ctx *gin.Context) {
|
|||
}
|
||||
c.Data.Database.Driver = req.DbType
|
||||
c.Data.Database.Connection = req.GetConnection()
|
||||
c.Data.Cache.FilePath = filepath.Join(cli.CachePath, cli.DefaultCacheFileName)
|
||||
c.I18n.BundleDir = cli.I18nPath
|
||||
c.ServiceConfig.UploadPath = cli.UploadFilePath
|
||||
|
||||
if err := conf.RewriteConfig(confPath, c); err != nil {
|
||||
log.Errorf("rewrite config failed %s", err)
|
||||
|
|
|
@ -15,7 +15,7 @@ type CheckConfigFileResp struct {
|
|||
|
||||
// CheckDatabaseReq check database
|
||||
type CheckDatabaseReq struct {
|
||||
DbType string `json:"db_type"`
|
||||
DbType string `validate:"required,oneof=postgres sqlite3 mysql" json:"db_type"`
|
||||
DbUsername string `json:"db_username"`
|
||||
DbPassword string `json:"db_password"`
|
||||
DbHost string `json:"db_host"`
|
||||
|
@ -71,11 +71,11 @@ type InitEnvironmentResp struct {
|
|||
|
||||
// InitBaseInfoReq init base info request
|
||||
type InitBaseInfoReq struct {
|
||||
Language string `json:"language"`
|
||||
SiteName string `json:"site_name"`
|
||||
SiteURL string `json:"site_url"`
|
||||
ContactEmail string `json:"contact_email"`
|
||||
AdminName string `json:"admin_name"`
|
||||
AdminPassword string `json:"admin_password"`
|
||||
AdminEmail string `json:"admin_email"`
|
||||
Language string `validate:"required,gt=0,lte=30" json:"lang"`
|
||||
SiteName string `validate:"required,gt=0,lte=30" json:"site_name"`
|
||||
SiteURL string `validate:"required,gt=0,lte=512" json:"site_url"`
|
||||
ContactEmail string `validate:"required,email,gt=0,lte=500" json:"contact_email"`
|
||||
AdminName string `validate:"required,gt=4,lte=30" json:"admin_name"`
|
||||
AdminPassword string `validate:"required,gte=8,lte=32" json:"admin_password"`
|
||||
AdminEmail string `validate:"required,email,gt=0,lte=500" json:"admin_email"`
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/data"
|
||||
|
@ -79,19 +80,31 @@ func initAdminUser(engine *xorm.Engine) error {
|
|||
}
|
||||
|
||||
func initSiteInfo(engine *xorm.Engine, language, siteName, siteURL, contactEmail string) error {
|
||||
interfaceData := map[string]string{
|
||||
"logo": "",
|
||||
"theme": "black",
|
||||
"language": language,
|
||||
}
|
||||
interfaceDataBytes, _ := json.Marshal(interfaceData)
|
||||
_, err := engine.InsertOne(&entity.SiteInfo{
|
||||
Type: "interface",
|
||||
Content: fmt.Sprintf(`{"logo":"","theme":"black","language":%s}`, language),
|
||||
Content: string(interfaceDataBytes),
|
||||
Status: 1,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
generalData := map[string]string{
|
||||
"name": siteName,
|
||||
"site_url": siteURL,
|
||||
"contact_email": contactEmail,
|
||||
}
|
||||
generalDataBytes, _ := json.Marshal(generalData)
|
||||
_, err = engine.InsertOne(&entity.SiteInfo{
|
||||
Type: "general",
|
||||
Content: fmt.Sprintf(`{"name":"%s","site_url":"%s","contact_email":"%s"}`,
|
||||
siteName, siteURL, contactEmail),
|
||||
Status: 1,
|
||||
Type: "general",
|
||||
Content: string(generalDataBytes),
|
||||
Status: 1,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
@ -108,7 +121,7 @@ func updateAdminInfo(engine *xorm.Engine, adminName, adminPassword, adminEmail s
|
|||
Username: adminName,
|
||||
Pass: adminPassword,
|
||||
EMail: adminEmail,
|
||||
DisplayName: "admin",
|
||||
DisplayName: adminName,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("update admin user info failed: %s", err)
|
||||
|
|
Loading…
Reference in New Issue