mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
实现Web静态文件分发
This commit is contained in:
@@ -87,7 +87,16 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
config := &serverconfigs.HTTPWebConfig{}
|
||||
config.Id = webId
|
||||
config.IsOn = web.IsOn == 1
|
||||
config.Root = web.Root
|
||||
|
||||
// root
|
||||
if IsNotNull(web.Root) {
|
||||
rootConfig := &serverconfigs.HTTPRootConfig{}
|
||||
err = json.Unmarshal([]byte(web.Root), rootConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Root = rootConfig
|
||||
}
|
||||
|
||||
// gzip
|
||||
if IsNotNull(web.Gzip) {
|
||||
@@ -255,10 +264,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
}
|
||||
|
||||
// 创建Web配置
|
||||
func (this *HTTPWebDAO) CreateWeb(root string) (int64, error) {
|
||||
func (this *HTTPWebDAO) CreateWeb(rootJSON []byte) (int64, error) {
|
||||
op := NewHTTPWebOperator()
|
||||
op.State = HTTPWebStateEnabled
|
||||
op.Root = root
|
||||
op.Root = rootJSON
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -267,13 +276,13 @@ func (this *HTTPWebDAO) CreateWeb(root string) (int64, error) {
|
||||
}
|
||||
|
||||
// 修改Web配置
|
||||
func (this *HTTPWebDAO) UpdateWeb(webId int64, root string) error {
|
||||
func (this *HTTPWebDAO) UpdateWeb(webId int64, rootJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.Root = root
|
||||
op.Root = rootJSON
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -129,6 +129,12 @@ func (this *ServerDAO) CreateServer(adminId int64, userId int64, serverType serv
|
||||
}
|
||||
|
||||
serverId = types.Int64(op.Id)
|
||||
|
||||
_, err = this.RenewServerConfig(serverId)
|
||||
if err != nil {
|
||||
return serverId, err
|
||||
}
|
||||
|
||||
return serverId, nil
|
||||
}
|
||||
|
||||
@@ -320,7 +326,7 @@ func (this *ServerDAO) InitServerWeb(serverId int64) (int64, error) {
|
||||
return 0, errors.New("serverId should not be smaller than 0")
|
||||
}
|
||||
|
||||
webId, err := SharedHTTPWebDAO.CreateWeb("")
|
||||
webId, err := SharedHTTPWebDAO.CreateWeb(nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (this *HTTPLocationService) FindAndInitHTTPLocationWebConfig(ctx context.Co
|
||||
}
|
||||
|
||||
if webId <= 0 {
|
||||
webId, err = models.SharedHTTPWebDAO.CreateWeb("")
|
||||
webId, err = models.SharedHTTPWebDAO.CreateWeb(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func (this *HTTPWebService) CreateHTTPWeb(ctx context.Context, req *pb.CreateHTT
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webId, err := models.SharedHTTPWebDAO.CreateWeb(req.Root)
|
||||
webId, err := models.SharedHTTPWebDAO.CreateWeb(req.RootJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -47,7 +47,6 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
result := &pb.HTTPWeb{}
|
||||
result.Id = int64(web.Id)
|
||||
result.IsOn = web.IsOn == 1
|
||||
result.Root = web.Root
|
||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTT
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWeb(req.WebId, req.Root)
|
||||
err = models.SharedHTTPWebDAO.UpdateWeb(req.WebId, req.RootJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user