feat: 修改接口 方便记录日志

pull/89/head
zhengkunwang223 2022-12-23 11:08:28 +08:00 committed by zhengkunwang223
parent 76f5e83eed
commit f7f7fff84d
12 changed files with 38 additions and 31 deletions

View File

@ -1,7 +1,6 @@
package v1
import (
"errors"
"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"
@ -51,12 +50,12 @@ func (b *BaseApi) CreateWebsite(c *gin.Context) {
}
func (b *BaseApi) BackupWebsite(c *gin.Context) {
domain, ok := c.Params.Get("domain")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error domain in path"))
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteService.Backup(domain); err != nil {
if err := websiteService.Backup(req.ID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}

View File

@ -43,12 +43,12 @@ func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
}
func (b *BaseApi) DeleteWebGroup(c *gin.Context) {
groupId, err := helper.GetIntParamByKey(c, "groupId")
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.DeleteGroup(groupId); err != nil {
if err := websiteGroupService.DeleteGroup(req.ID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}

View File

@ -77,12 +77,12 @@ func (b *BaseApi) GetDNSResolve(c *gin.Context) {
}
func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteSSLService.Delete(id); err != nil {
if err := websiteSSLService.Delete(req.ID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}

View File

@ -30,7 +30,7 @@ type IWebsiteService interface {
PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error)
CreateWebsite(create request.WebsiteCreate) error
GetWebsiteOptions() ([]string, error)
Backup(domain string) error
Backup(id uint) error
Recover(req request.WebsiteRecover) error
RecoverByUpload(req request.WebsiteRecoverByFile) error
UpdateWebsite(req request.WebsiteUpdate) error
@ -165,15 +165,19 @@ func (w WebsiteService) GetWebsiteOptions() ([]string, error) {
return datas, nil
}
func (w WebsiteService) Backup(domain string) error {
func (w WebsiteService) Backup(id uint) error {
localDir, err := loadLocalDir()
if err != nil {
return err
}
fileName := fmt.Sprintf("%s_%s", domain, time.Now().Format("20060102150405"))
backupDir := fmt.Sprintf("website/%s", domain)
website, err := websiteRepo.GetFirst(commonRepo.WithByID(id))
if err != nil {
return err
}
if err := handleWebsiteBackup("LOCAL", localDir, backupDir, domain, fileName); err != nil {
fileName := fmt.Sprintf("%s_%s", website.PrimaryDomain, time.Now().Format("20060102150405"))
backupDir := fmt.Sprintf("website/%s", website.PrimaryDomain)
if err := handleWebsiteBackup("LOCAL", localDir, backupDir, website.PrimaryDomain, fileName); err != nil {
return err
}
return nil

View File

@ -22,7 +22,7 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
groupRouter.POST("/update", baseApi.UpdateWebsite)
groupRouter.GET("/:id", baseApi.GetWebsite)
groupRouter.POST("/del", baseApi.DeleteWebsite)
groupRouter.POST("/backup/:domain", baseApi.BackupWebsite)
groupRouter.POST("/backup", baseApi.BackupWebsite)
groupRouter.POST("/recover", baseApi.RecoverWebsite)
groupRouter.POST("/recover/byupload", baseApi.RecoverWebsiteByUpload)

View File

@ -17,7 +17,7 @@ func (a *WebsiteGroupRouter) InitWebsiteGroupRouter(Router *gin.RouterGroup) {
{
groupRouter.GET("", baseApi.GetWebGroups)
groupRouter.POST("", baseApi.CreateWebGroup)
groupRouter.PUT("", baseApi.UpdateWebGroup)
groupRouter.DELETE("/:groupId", baseApi.DeleteWebGroup)
groupRouter.POST("/update", baseApi.UpdateWebGroup)
groupRouter.POST("/del", baseApi.DeleteWebGroup)
}
}

View File

@ -19,7 +19,7 @@ func (a *WebsiteSSLRouter) InitWebsiteSSLRouter(Router *gin.RouterGroup) {
groupRouter.POST("/renew", baseApi.RenewWebsiteSSL)
groupRouter.POST("", baseApi.CreateWebsiteSSL)
groupRouter.POST("/resolve", baseApi.GetDNSResolve)
groupRouter.DELETE("/:id", baseApi.DeleteWebsiteSSL)
groupRouter.POST("/del", baseApi.DeleteWebsiteSSL)
groupRouter.GET("/:websiteId", baseApi.GetWebsiteSSL)
}
}

View File

@ -232,4 +232,8 @@ export namespace Website {
export interface DelReq {
id: number;
}
export interface BackupReq {
id: number;
}
}

View File

@ -11,8 +11,8 @@ export const CreateWebsite = (req: Website.WebSiteCreateReq) => {
return http.post<any>(`/websites`, req);
};
export const BackupWebsite = (id: number) => {
return http.post(`/websites/backup/${id}`);
export const BackupWebsite = (req: Website.BackupReq) => {
return http.post(`/websites/backup`, req);
};
export const RecoverWebsite = (req: Website.WebSiteRecover) => {
@ -52,11 +52,11 @@ export const CreateGroup = (req: Website.GroupOp) => {
};
export const UpdateGroup = (req: Website.GroupOp) => {
return http.put<any>(`/websites/groups`, req);
return http.post<any>(`/websites/groups/update`, req);
};
export const DeleteGroup = (id: number) => {
return http.delete<any>(`/websites/groups/${id}`);
export const DeleteGroup = (req: Website.DelReq) => {
return http.post<any>(`/websites/groups/del`, req);
};
export const ListDomains = (id: number) => {
@ -119,8 +119,8 @@ export const CreateSSL = (req: Website.SSLCreate) => {
return http.post<Website.SSLCreate>(`/websites/ssl`, req);
};
export const DeleteSSL = (id: number) => {
return http.delete<any>(`/websites/ssl/${id}`);
export const DeleteSSL = (req: Website.DelReq) => {
return http.post<any>(`/websites/ssl/del`, req);
};
export const GetWebsiteSSL = (websiteId: number) => {

View File

@ -129,7 +129,7 @@ const openRenewSSL = (id: number) => {
const deleteSSL = async (id: number) => {
loading.value = true;
await useDeleteData(DeleteSSL, id, 'commons.msg.delete');
await useDeleteData(DeleteSSL, { id: id }, 'commons.msg.delete');
loading.value = false;
search();
};

View File

@ -108,7 +108,7 @@ const onRecover = async (row: Backup.RecordInfo) => {
const onBackup = async () => {
loading.value = true;
await BackupWebsite(websiteName.value)
await BackupWebsite({ id: websiteID.value })
.then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));

View File

@ -127,7 +127,7 @@ const deleteGroup = (index: number) => {
const group = data.value[index];
if (group.id > 0) {
DeleteGroup(group.id).then(() => {
DeleteGroup({ id: group.id }).then(() => {
data.value.splice(index, 1);
ElMessage.success(i18n.global.t('commons.msg.deleteSuccess'));
});