mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-11 18:05:59 +08:00
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
"github.com/gin-gonic/gin"
|
|
"reflect"
|
|
)
|
|
|
|
func (b *BaseApi) PageWebsiteSSL(c *gin.Context) {
|
|
var req request.WebsiteSSLSearch
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) {
|
|
total, accounts, err := websiteSSLService.Page(req)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
Total: total,
|
|
Items: accounts,
|
|
})
|
|
} else {
|
|
list, err := websiteSSLService.Search()
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, list)
|
|
}
|
|
}
|
|
|
|
func (b *BaseApi) CreateWebsiteSSL(c *gin.Context) {
|
|
var req request.WebsiteSSLCreate
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
res, err := websiteSSLService.Create(req)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, res)
|
|
}
|
|
|
|
func (b *BaseApi) RenewWebsiteSSL(c *gin.Context) {
|
|
var req request.WebsiteSSLRenew
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
if err := websiteSSLService.Renew(req.SSLID); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, nil)
|
|
}
|
|
|
|
func (b *BaseApi) GetDNSResolve(c *gin.Context) {
|
|
var req request.WebsiteDNSReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
res, err := websiteSSLService.GetDNSResolve(req)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, res)
|
|
}
|
|
|
|
func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) {
|
|
var req request.WebsiteResourceReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
if err := websiteSSLService.Delete(req.ID); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, nil)
|
|
}
|
|
|
|
func (b *BaseApi) GetWebsiteSSL(c *gin.Context) {
|
|
websiteId, err := helper.GetIntParamByKey(c, "websiteId")
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
websiteSSL, err := websiteSSLService.GetWebsiteSSL(websiteId)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, websiteSSL)
|
|
}
|