Merge branch 'ai_0.3_install_api' into 'test'

Ai 0.3 install api

See merge request opensource/answer!217
This commit is contained in:
linkinstar 2022-11-10 03:41:11 +00:00
commit ee412d2781
6 changed files with 33 additions and 6 deletions

View File

@ -143,6 +143,7 @@ func InitBaseInfo(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.FormatSiteUrl()
c, err := conf.ReadConfig(confPath)
if err != nil {

View File

@ -2,6 +2,7 @@ package install
import (
"fmt"
"net/url"
"strings"
"xorm.io/xorm/schemas"
@ -73,9 +74,17 @@ type InitEnvironmentResp struct {
type InitBaseInfoReq struct {
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"`
SiteURL string `validate:"required,gt=0,lte=512,url" 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"`
}
func (r *InitBaseInfoReq) FormatSiteUrl() {
parsedUrl, err := url.Parse(r.SiteURL)
if err != nil {
return
}
r.SiteURL = fmt.Sprintf("%s://%s", parsedUrl.Scheme, parsedUrl.Host)
}

View File

@ -35,16 +35,16 @@ func NewInstallHTTPServer() *gin.Engine {
installApi := r.Group("")
installApi.GET("/install", WebPage)
installApi.GET("/50x", WebPage)
installApi.GET("/installation/language/options", LangOptions)
installApi.POST("/installation/db/check", CheckDatabase)
installApi.POST("/installation/config-file/check", CheckConfigFile)
installApi.POST("/installation/init", InitEnvironment)
installApi.POST("/installation/base-info", InitBaseInfo)
r.NoRoute(func(ctx *gin.Context) {
ctx.Redirect(http.StatusFound, "/50x")
})
return r
}

View File

@ -78,6 +78,9 @@ func (a *UIRouter) Register(r *gin.Engine) {
filePath = UIRootFilePath + name
case "/manifest.json":
filePath = UIRootFilePath + name
case "/install":
c.Redirect(http.StatusFound, "/")
return
default:
filePath = UIIndexFilePath
c.Header("content-type", "text/html;charset=utf-8")

View File

@ -1,5 +1,10 @@
package schema
import (
"fmt"
"net/url"
)
// SiteGeneralReq site general request
type SiteGeneralReq struct {
Name string `validate:"required,gt=1,lte=128" form:"name" json:"name"`
@ -9,6 +14,14 @@ type SiteGeneralReq struct {
ContactEmail string `validate:"required,gt=1,lte=512,email" form:"contact_email" json:"contact_email"`
}
func (r *SiteGeneralReq) FormatSiteUrl() {
parsedUrl, err := url.Parse(r.SiteUrl)
if err != nil {
return
}
r.SiteUrl = fmt.Sprintf("%s://%s", parsedUrl.Scheme, parsedUrl.Host)
}
// SiteInterfaceReq site interface request
type SiteInterfaceReq struct {
Logo string `validate:"omitempty,gt=0,lte=256" form:"logo" json:"logo"`

View File

@ -57,6 +57,7 @@ func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.Si
}
func (s *SiteInfoService) SaveSiteGeneral(ctx context.Context, req schema.SiteGeneralReq) (err error) {
req.FormatSiteUrl()
var (
siteType = "general"
content []byte