2022-11-23 16:19:05 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2022-12-13 17:20:13 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
2022-11-23 16:19:05 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (b *BaseApi) GetNginx(c *gin.Context) {
|
|
|
|
fileInfo, err := nginxService.GetNginxConfig()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, fileInfo)
|
|
|
|
}
|
2022-11-24 10:28:39 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) {
|
2022-12-13 18:54:46 +08:00
|
|
|
var req request.NginxScopeReq
|
2022-11-24 10:28:39 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
params, err := nginxService.GetConfigByScope(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, params)
|
|
|
|
}
|
|
|
|
|
2022-12-13 18:54:46 +08:00
|
|
|
func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
|
|
|
|
var req request.NginxConfigUpdate
|
2022-11-24 10:28:39 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := nginxService.UpdateConfigByScope(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-11-24 16:06:18 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) GetNginxStatus(c *gin.Context) {
|
|
|
|
res, err := nginxService.GetStatus()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
2022-12-09 17:16:07 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) UpdateNginxFile(c *gin.Context) {
|
|
|
|
var req request.NginxConfigFileUpdate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := nginxService.UpdateConfigFile(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|