mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-14 19:48:12 +08:00
106 lines
3.6 KiB
Go
106 lines
3.6 KiB
Go
package v1
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Tags Nginx
|
|
// @Summary Load nginx conf
|
|
// @Description 获取 nginx 配置信息
|
|
// @Success 200 {object} response.FileInfo
|
|
// @Security ApiKeyAuth
|
|
// @Router /nginx [get]
|
|
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)
|
|
}
|
|
|
|
// @Tags Nginx
|
|
// @Summary Load partial nginx conf
|
|
// @Description 获取部分 nginx 配置信息
|
|
// @Accept json
|
|
// @Param request body request.NginxScopeReq true "request"
|
|
// @Success 200 {anrry} response.NginxParam
|
|
// @Security ApiKeyAuth
|
|
// @Router /nginx/scope [post]
|
|
func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) {
|
|
var req request.NginxScopeReq
|
|
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 Nginx
|
|
// @Summary Update nginx conf
|
|
// @Description 更新 nginx 配置信息
|
|
// @Accept json
|
|
// @Param request body request.NginxConfigUpdate true "request"
|
|
// @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]"}
|
|
func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
|
|
var req request.NginxConfigUpdate
|
|
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)
|
|
}
|
|
|
|
// @Tags Nginx
|
|
// @Summary Load nginx status info
|
|
// @Description 获取 nginx 状态信息
|
|
// @Success 200 {object} response.NginxStatus
|
|
// @Security ApiKeyAuth
|
|
// @Router /nginx/status [get]
|
|
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)
|
|
}
|
|
|
|
// @Tags Nginx
|
|
// @Summary Update nginx conf by upload file
|
|
// @Description 上传更新 nginx 配置文件
|
|
// @Accept json
|
|
// @Param request body request.NginxConfigFileUpdate true "request"
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Router /nginx/file [post]
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新 nginx 配置","formatEN":"Update nginx conf"}
|
|
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)
|
|
}
|