1Panel/backend/app/api/v1/nginx.go

107 lines
3.6 KiB
Go
Raw Normal View History

2022-11-23 08:19:05 +00:00
package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
2022-12-13 09:20:13 +00:00
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
2022-11-23 08:19:05 +00:00
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
// @Tags OpenResty
// @Summary Load OpenResty conf
// @Description 获取 OpenResty 配置信息
2023-01-04 14:31:51 +00:00
// @Success 200 {object} response.FileInfo
// @Security ApiKeyAuth
// @Router /openResty [get]
2022-11-23 08:19:05 +00:00
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 02:28:39 +00:00
// @Tags OpenResty
// @Summary Load partial OpenResty conf
// @Description 获取部分 OpenResty 配置信息
2023-01-04 14:31:51 +00:00
// @Accept json
// @Param request body request.NginxScopeReq true "request"
2023-01-04 14:31:51 +00:00
// @Success 200 {anrry} response.NginxParam
// @Security ApiKeyAuth
// @Router /openResty/scope [post]
2022-11-24 02:28:39 +00:00
func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) {
2022-12-13 10:54:46 +00:00
var req request.NginxScopeReq
2022-11-24 02:28:39 +00: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)
}
// @Tags OpenResty
// @Summary Update OpenResty conf
// @Description 更新 OpenResty 配置信息
2023-01-04 14:31:51 +00:00
// @Accept json
// @Param request body request.NginxConfigUpdate true "request"
2023-01-04 14:31:51 +00:00
// @Success 200
// @Security ApiKeyAuth
// @Router /openResty/update [post]
2023-01-04 14:31:51 +00:00
// @x-panel-log {"bodyKeys":["websiteId"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"websiteId","isList":false,"db":"websites","output_colume":"primary_domain","output_value":"domain"}],"formatZH":"更新 nginx 配置 [domain]","formatEN":"Update nginx conf [domain]"}
2022-12-13 10:54:46 +00:00
func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
var req request.NginxConfigUpdate
2022-11-24 02:28:39 +00: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 08:06:18 +00:00
// @Tags OpenResty
// @Summary Load OpenResty status info
// @Description 获取 OpenResty 状态信息
2023-01-04 14:31:51 +00:00
// @Success 200 {object} response.NginxStatus
// @Security ApiKeyAuth
// @Router /openResty/status [get]
2022-11-24 08:06:18 +00: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 09:16:07 +00:00
// @Tags OpenResty
// @Summary Update OpenResty conf by upload file
// @Description 上传更新 OpenResty 配置文件
2023-01-04 14:31:51 +00:00
// @Accept json
// @Param request body request.NginxConfigFileUpdate true "request"
2023-01-04 14:31:51 +00:00
// @Success 200
// @Security ApiKeyAuth
// @Router /openResty/file [post]
2023-01-04 14:31:51 +00:00
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新 nginx 配置","formatEN":"Update nginx conf"}
2022-12-09 09:16:07 +00: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)
}