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

104 lines
3.4 KiB
Go
Raw Normal View History

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"
)
// @Tags OpenResty
// @Summary Load OpenResty conf
// @Description 获取 OpenResty 配置信息
2023-01-04 22:31:51 +08:00
// @Success 200 {object} response.FileInfo
// @Security ApiKeyAuth
// @Router /openResty [get]
2022-11-23 16:19:05 +08: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 10:28:39 +08:00
// @Tags OpenResty
// @Summary Load partial OpenResty conf
// @Description 获取部分 OpenResty 配置信息
2023-01-04 22:31:51 +08:00
// @Accept json
// @Param request body request.NginxScopeReq true "request"
// @Success 200 {array} response.NginxParam
2023-01-04 22:31:51 +08:00
// @Security ApiKeyAuth
// @Router /openResty/scope [post]
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
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-11-24 10:28:39 +08:00
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 22:31:51 +08:00
// @Accept json
// @Param request body request.NginxConfigUpdate true "request"
2023-01-04 22:31:51 +08:00
// @Success 200
// @Security ApiKeyAuth
// @Router /openResty/update [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["websiteId"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"websiteId","isList":false,"db":"websites","output_column":"primary_domain","output_value":"domain"}],"formatZH":"更新 nginx 配置 [domain]","formatEN":"Update nginx conf [domain]"}
2022-12-13 18:54:46 +08:00
func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
var req request.NginxConfigUpdate
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-11-24 10:28:39 +08:00
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
// @Tags OpenResty
// @Summary Load OpenResty status info
// @Description 获取 OpenResty 状态信息
2023-01-04 22:31:51 +08:00
// @Success 200 {object} response.NginxStatus
// @Security ApiKeyAuth
// @Router /openResty/status [get]
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
// @Tags OpenResty
// @Summary Update OpenResty conf by upload file
// @Description 上传更新 OpenResty 配置文件
2023-01-04 22:31:51 +08:00
// @Accept json
// @Param request body request.NginxConfigFileUpdate true "request"
2023-01-04 22:31:51 +08:00
// @Success 200
// @Security ApiKeyAuth
// @Router /openResty/file [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新 nginx 配置","formatEN":"Update nginx conf"}
2022-12-09 17:16:07 +08:00
func (b *BaseApi) UpdateNginxFile(c *gin.Context) {
var req request.NginxConfigFileUpdate
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-12-09 17:16:07 +08:00
return
}
if err := nginxService.UpdateConfigFile(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}