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

107 lines
3.6 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"
)
2023-01-04 22:31:51 +08:00
// @Tags Nginx
// @Summary Load nginx conf
// @Description 获取 nginx 配置信息
// @Success 200 {object} response.FileInfo
// @Security ApiKeyAuth
// @Router /nginx [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
2023-01-04 22:31:51 +08:00
// @Tags Nginx
// @Summary Load partial nginx conf
// @Description 获取部分 nginx 配置信息
// @Accept json
// @Param request body request.NginxScopeReq true "request"
2023-01-04 22:31:51 +08:00
// @Success 200 {anrry} response.NginxParam
// @Security ApiKeyAuth
// @Router /nginx/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
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)
}
2023-01-04 22:31:51 +08:00
// @Tags Nginx
// @Summary Update nginx conf
// @Description 更新 nginx 配置信息
// @Accept json
// @Param request body request.NginxConfigUpdate true "request"
2023-01-04 22:31:51 +08:00
// @Success 200
// @Security ApiKeyAuth
// @Router /nginx/update [post]
// @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 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
2023-01-04 22:31:51 +08:00
// @Tags Nginx
// @Summary Load nginx status info
// @Description 获取 nginx 状态信息
// @Success 200 {object} response.NginxStatus
// @Security ApiKeyAuth
// @Router /nginx/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
2023-01-04 22:31:51 +08:00
// @Tags Nginx
// @Summary Update nginx conf by upload file
// @Description 上传更新 nginx 配置文件
// @Accept json
// @Param request body request.NginxConfigFileUpdate true "request"
2023-01-04 22:31:51 +08:00
// @Success 200
// @Security ApiKeyAuth
// @Router /nginx/file [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"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 := 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)
}