From f7f7fff84ddb1eb1c895ea885a0a6b00579c017e Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Fri, 23 Dec 2022 11:08:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/website.go | 9 ++++----- backend/app/api/v1/website_group.go | 8 ++++---- backend/app/api/v1/website_ssl.go | 6 +++--- backend/app/service/website.go | 14 +++++++++----- backend/router/ro_website.go | 2 +- backend/router/ro_website_group.go | 4 ++-- backend/router/ro_website_ssl.go | 2 +- frontend/src/api/interface/website.ts | 4 ++++ frontend/src/api/modules/website.ts | 14 +++++++------- frontend/src/views/website/ssl/index.vue | 2 +- .../src/views/website/website/backup/index.vue | 2 +- frontend/src/views/website/website/group/index.vue | 2 +- 12 files changed, 38 insertions(+), 31 deletions(-) diff --git a/backend/app/api/v1/website.go b/backend/app/api/v1/website.go index 6c9ee71dd..d92ab8586 100644 --- a/backend/app/api/v1/website.go +++ b/backend/app/api/v1/website.go @@ -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 } diff --git a/backend/app/api/v1/website_group.go b/backend/app/api/v1/website_group.go index 636974511..5ec4a1995 100644 --- a/backend/app/api/v1/website_group.go +++ b/backend/app/api/v1/website_group.go @@ -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 } diff --git a/backend/app/api/v1/website_ssl.go b/backend/app/api/v1/website_ssl.go index 46b40b0eb..152fd0c52 100644 --- a/backend/app/api/v1/website_ssl.go +++ b/backend/app/api/v1/website_ssl.go @@ -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 } diff --git a/backend/app/service/website.go b/backend/app/service/website.go index da3ff35b8..675a4f678 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -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 diff --git a/backend/router/ro_website.go b/backend/router/ro_website.go index e7e1e7725..60aa9adef 100644 --- a/backend/router/ro_website.go +++ b/backend/router/ro_website.go @@ -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) diff --git a/backend/router/ro_website_group.go b/backend/router/ro_website_group.go index d67bcf4b1..ff9524ab5 100644 --- a/backend/router/ro_website_group.go +++ b/backend/router/ro_website_group.go @@ -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) } } diff --git a/backend/router/ro_website_ssl.go b/backend/router/ro_website_ssl.go index 2b338b78f..2305d052d 100644 --- a/backend/router/ro_website_ssl.go +++ b/backend/router/ro_website_ssl.go @@ -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) } } diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 4bd3a3219..c6847cb67 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -232,4 +232,8 @@ export namespace Website { export interface DelReq { id: number; } + + export interface BackupReq { + id: number; + } } diff --git a/frontend/src/api/modules/website.ts b/frontend/src/api/modules/website.ts index 645f2ae9f..552b13cdd 100644 --- a/frontend/src/api/modules/website.ts +++ b/frontend/src/api/modules/website.ts @@ -11,8 +11,8 @@ export const CreateWebsite = (req: Website.WebSiteCreateReq) => { return http.post(`/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(`/websites/groups`, req); + return http.post(`/websites/groups/update`, req); }; -export const DeleteGroup = (id: number) => { - return http.delete(`/websites/groups/${id}`); +export const DeleteGroup = (req: Website.DelReq) => { + return http.post(`/websites/groups/del`, req); }; export const ListDomains = (id: number) => { @@ -119,8 +119,8 @@ export const CreateSSL = (req: Website.SSLCreate) => { return http.post(`/websites/ssl`, req); }; -export const DeleteSSL = (id: number) => { - return http.delete(`/websites/ssl/${id}`); +export const DeleteSSL = (req: Website.DelReq) => { + return http.post(`/websites/ssl/del`, req); }; export const GetWebsiteSSL = (websiteId: number) => { diff --git a/frontend/src/views/website/ssl/index.vue b/frontend/src/views/website/ssl/index.vue index 2f78b6564..d58a240cd 100644 --- a/frontend/src/views/website/ssl/index.vue +++ b/frontend/src/views/website/ssl/index.vue @@ -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(); }; diff --git a/frontend/src/views/website/website/backup/index.vue b/frontend/src/views/website/website/backup/index.vue index 3b79dca3c..58a6aa265 100644 --- a/frontend/src/views/website/website/backup/index.vue +++ b/frontend/src/views/website/website/backup/index.vue @@ -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')); diff --git a/frontend/src/views/website/website/group/index.vue b/frontend/src/views/website/website/group/index.vue index 5c7f5249f..f34e596e2 100644 --- a/frontend/src/views/website/website/group/index.vue +++ b/frontend/src/views/website/website/group/index.vue @@ -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')); });