From a03b1310579e4267e7f1fb913a16b4e9ca7fd7a5 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:42:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=20(#6882)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/app/api/v2/app.go | 31 +++-- agent/app/api/v2/app_install.go | 39 +++--- agent/app/api/v2/backup.go | 42 +++--- agent/app/api/v2/clam.go | 27 ++-- agent/app/api/v2/compose_template.go | 11 +- agent/app/api/v2/container.go | 65 +++++----- agent/app/api/v2/cronjob.go | 21 ++- agent/app/api/v2/dashboard.go | 17 ++- agent/app/api/v2/database.go | 23 ++-- agent/app/api/v2/database_common.go | 7 +- agent/app/api/v2/database_mysql.go | 35 +++-- agent/app/api/v2/database_postgresql.go | 25 ++-- agent/app/api/v2/database_redis.go | 17 ++- agent/app/api/v2/device.go | 23 ++-- agent/app/api/v2/docker.go | 12 +- agent/app/api/v2/fail2ban.go | 15 +-- agent/app/api/v2/favorite.go | 7 +- agent/app/api/v2/file.go | 66 +++++----- agent/app/api/v2/firewall.go | 21 ++- agent/app/api/v2/ftp.go | 6 +- agent/app/api/v2/health.go | 3 +- agent/app/api/v2/helper/helper.go | 8 ++ agent/app/api/v2/host_tool.go | 17 ++- agent/app/api/v2/image.go | 21 ++- agent/app/api/v2/image_repo.go | 13 +- agent/app/api/v2/logs.go | 5 +- agent/app/api/v2/monitor.go | 9 +- agent/app/api/v2/nginx.go | 19 ++- agent/app/api/v2/php_extensions.go | 11 +- agent/app/api/v2/process.go | 3 +- agent/app/api/v2/recycle_bin.go | 9 +- agent/app/api/v2/runtime.go | 59 +++++---- agent/app/api/v2/setting.go | 5 +- agent/app/api/v2/snapshot.go | 21 ++- agent/app/api/v2/ssh.go | 17 ++- agent/app/api/v2/task.go | 3 +- agent/app/api/v2/website.go | 121 +++++++++--------- agent/app/api/v2/website_acme_account.go | 7 +- agent/app/api/v2/website_ca.go | 17 ++- agent/app/api/v2/website_dns_account.go | 9 +- agent/app/api/v2/website_domain.go | 11 +- agent/app/api/v2/website_ssl.go | 29 ++--- agent/app/service/runtime.go | 9 +- agent/app/service/runtime_utils.go | 27 ---- agent/app/service/website.go | 12 +- agent/app/service/website_utils.go | 33 +---- core/app/api/v2/auth.go | 16 +-- core/app/api/v2/backup.go | 17 ++- core/app/api/v2/command.go | 10 +- core/app/api/v2/group.go | 6 +- core/app/api/v2/helper/helper.go | 8 ++ core/app/api/v2/host.go | 20 +-- core/app/api/v2/logs.go | 4 +- core/app/api/v2/setting.go | 2 +- core/app/api/v2/upgrade.go | 4 +- .../src/components/layout-content/index.vue | 4 +- frontend/src/global/mimetype.ts | 54 +++++++- 57 files changed, 562 insertions(+), 591 deletions(-) diff --git a/agent/app/api/v2/app.go b/agent/app/api/v2/app.go index 3d04911ab..d1d16a357 100644 --- a/agent/app/api/v2/app.go +++ b/agent/app/api/v2/app.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/i18n" "github.com/gin-gonic/gin" ) @@ -24,7 +23,7 @@ func (b *BaseApi) SearchApp(c *gin.Context) { } list, err := appService.PageApp(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -44,7 +43,7 @@ func (b *BaseApi) SyncApp(c *gin.Context) { } res, err := appService.GetAppUpdate() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } if !res.CanUpdate { @@ -56,7 +55,7 @@ func (b *BaseApi) SyncApp(c *gin.Context) { return } if err = appService.SyncAppListFromRemote(req.TaskID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -89,12 +88,12 @@ func (b *BaseApi) SyncLocalApp(c *gin.Context) { func (b *BaseApi) GetApp(c *gin.Context) { appKey, err := helper.GetStrParamByKey(c, "key") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } appDTO, err := appService.GetApp(appKey) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, appDTO) @@ -113,14 +112,14 @@ func (b *BaseApi) GetApp(c *gin.Context) { func (b *BaseApi) GetAppDetail(c *gin.Context) { appID, err := helper.GetIntParamByKey(c, "appId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } version := c.Param("version") appType := c.Param("type") appDetailDTO, err := appService.GetAppDetail(appID, version, appType) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, appDetailDTO) @@ -137,12 +136,12 @@ func (b *BaseApi) GetAppDetail(c *gin.Context) { func (b *BaseApi) GetAppDetailByID(c *gin.Context) { appDetailID, err := helper.GetIntParamByKey(c, "id") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } appDetailDTO, err := appService.GetAppDetailByID(appDetailID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, appDetailDTO) @@ -158,7 +157,7 @@ func (b *BaseApi) GetAppDetailByID(c *gin.Context) { func (b *BaseApi) GetIgnoredApp(c *gin.Context) { res, err := appService.GetIgnoredApp() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -180,7 +179,7 @@ func (b *BaseApi) InstallApp(c *gin.Context) { } install, err := appService.Install(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, install) @@ -189,7 +188,7 @@ func (b *BaseApi) InstallApp(c *gin.Context) { func (b *BaseApi) GetAppTags(c *gin.Context) { tags, err := appService.GetAppTags() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, tags) @@ -204,7 +203,7 @@ func (b *BaseApi) GetAppTags(c *gin.Context) { func (b *BaseApi) GetAppListUpdate(c *gin.Context) { res, err := appService.GetAppUpdate() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -225,7 +224,7 @@ func (b *BaseApi) UpdateAppstoreConfig(c *gin.Context) { } err := appService.UpdateAppstoreConfig(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -240,7 +239,7 @@ func (b *BaseApi) UpdateAppstoreConfig(c *gin.Context) { func (b *BaseApi) GetAppstoreConfig(c *gin.Context) { res, err := appService.GetAppstoreConfig() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) diff --git a/agent/app/api/v2/app_install.go b/agent/app/api/v2/app_install.go index 172656f80..c9a3fd1bd 100644 --- a/agent/app/api/v2/app_install.go +++ b/agent/app/api/v2/app_install.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -25,14 +24,14 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { if req.All { list, err := appInstallService.SearchForWebsite(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) } else { total, list, err := appInstallService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -52,7 +51,7 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { func (b *BaseApi) ListAppInstalled(c *gin.Context) { list, err := appInstallService.GetInstallList() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -73,7 +72,7 @@ func (b *BaseApi) CheckAppInstalled(c *gin.Context) { } checkData, err := appInstallService.CheckExist(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, checkData) @@ -94,7 +93,7 @@ func (b *BaseApi) LoadPort(c *gin.Context) { } port, err := appInstallService.LoadPort(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, port) @@ -115,7 +114,7 @@ func (b *BaseApi) LoadConnInfo(c *gin.Context) { } conn, err := appInstallService.LoadConnInfo(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, conn) @@ -132,12 +131,12 @@ func (b *BaseApi) LoadConnInfo(c *gin.Context) { func (b *BaseApi) DeleteCheck(c *gin.Context) { appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } checkData, err := appInstallService.DeleteCheck(appInstallId) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, checkData) @@ -153,7 +152,7 @@ func (b *BaseApi) DeleteCheck(c *gin.Context) { // @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"同步已安装应用列表","formatEN":"Sync the list of installed apps"} func (b *BaseApi) SyncInstalled(c *gin.Context) { if err := appInstallService.SyncAll(false); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, "") @@ -174,7 +173,7 @@ func (b *BaseApi) OperateInstalled(c *gin.Context) { return } if err := appInstallService.Operate(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -192,7 +191,7 @@ func (b *BaseApi) GetServices(c *gin.Context) { key := c.Param("key") services, err := appInstallService.GetServices(key) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, services) @@ -213,7 +212,7 @@ func (b *BaseApi) GetUpdateVersions(c *gin.Context) { } versions, err := appInstallService.GetUpdateVersions(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, versions) @@ -234,7 +233,7 @@ func (b *BaseApi) ChangeAppPort(c *gin.Context) { return } if err := appInstallService.ChangeAppPort(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -255,7 +254,7 @@ func (b *BaseApi) GetDefaultConfig(c *gin.Context) { } content, err := appInstallService.GetDefaultConfigByKey(req.Type, req.Name) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -273,12 +272,12 @@ func (b *BaseApi) GetDefaultConfig(c *gin.Context) { func (b *BaseApi) GetParams(c *gin.Context) { appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } content, err := appInstallService.GetParams(appInstallId) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, content) @@ -299,7 +298,7 @@ func (b *BaseApi) UpdateInstalled(c *gin.Context) { return } if err := appInstallService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -320,7 +319,7 @@ func (b *BaseApi) IgnoreUpgrade(c *gin.Context) { return } if err := appInstallService.IgnoreUpgrade(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -341,7 +340,7 @@ func (b *BaseApi) UpdateAppConfig(c *gin.Context) { return } if err := appInstallService.UpdateAppConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/backup.go b/agent/app/api/v2/backup.go index a66dde142..c448b2616 100644 --- a/agent/app/api/v2/backup.go +++ b/agent/app/api/v2/backup.go @@ -13,12 +13,12 @@ import ( func (b *BaseApi) CheckBackupUsed(c *gin.Context) { id, err := helper.GetIntParamByKey(c, "id") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } if err := backupService.CheckUsed(id); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } @@ -41,7 +41,7 @@ func (b *BaseApi) SearchBackupRecords(c *gin.Context) { total, list, err := backupService.SearchRecordsWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -67,7 +67,7 @@ func (b *BaseApi) SearchBackupRecordsByCronjob(c *gin.Context) { total, list, err := backupService.SearchRecordsByCronjobWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -94,7 +94,7 @@ func (b *BaseApi) DownloadRecord(c *gin.Context) { filePath, err := backupService.DownloadRecord(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, filePath) @@ -116,7 +116,7 @@ func (b *BaseApi) DeleteBackupRecord(c *gin.Context) { } if err := backupService.BatchDeleteRecord(req.Ids); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -158,27 +158,27 @@ func (b *BaseApi) Backup(c *gin.Context) { switch req.Type { case "app": if _, err := backupService.AppBackup(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "mysql", "mariadb": if err := backupService.MysqlBackup(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case constant.AppPostgresql: if err := backupService.PostgresqlBackup(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "website": if err := backupService.WebsiteBackup(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "redis": if err := backupService.RedisBackup(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } } @@ -206,34 +206,34 @@ func (b *BaseApi) Recover(c *gin.Context) { FileName: path.Base(req.File), }) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, fmt.Errorf("download file failed, err: %v", err)) + helper.BadRequest(c, fmt.Errorf("download file failed, err: %v", err)) return } req.File = downloadPath switch req.Type { case "mysql", "mariadb": if err := backupService.MysqlRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case constant.AppPostgresql: if err := backupService.PostgresqlRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "website": if err := backupService.WebsiteRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "redis": if err := backupService.RedisRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "app": if err := backupService.AppRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } } @@ -258,22 +258,22 @@ func (b *BaseApi) RecoverByUpload(c *gin.Context) { switch req.Type { case "mysql", "mariadb": if err := backupService.MysqlRecoverByUpload(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case constant.AppPostgresql: if err := backupService.PostgresqlRecoverByUpload(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "app": if err := backupService.AppRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } case "website": if err := backupService.WebsiteRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } } diff --git a/agent/app/api/v2/clam.go b/agent/app/api/v2/clam.go index 4823628f9..c3d156cab 100644 --- a/agent/app/api/v2/clam.go +++ b/agent/app/api/v2/clam.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) CreateClam(c *gin.Context) { } if err := clamService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -45,7 +44,7 @@ func (b *BaseApi) UpdateClam(c *gin.Context) { } if err := clamService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -67,7 +66,7 @@ func (b *BaseApi) UpdateClamStatus(c *gin.Context) { } if err := clamService.UpdateStatus(req.ID, req.Status); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -89,7 +88,7 @@ func (b *BaseApi) SearchClam(c *gin.Context) { total, list, err := clamService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -109,7 +108,7 @@ func (b *BaseApi) SearchClam(c *gin.Context) { func (b *BaseApi) LoadClamBaseInfo(c *gin.Context) { info, err := clamService.LoadBaseInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -131,7 +130,7 @@ func (b *BaseApi) OperateClam(c *gin.Context) { } if err := clamService.Operate(req.Operation); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -152,7 +151,7 @@ func (b *BaseApi) CleanClamRecord(c *gin.Context) { return } if err := clamService.CleanRecord(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -175,7 +174,7 @@ func (b *BaseApi) SearchClamRecord(c *gin.Context) { total, list, err := clamService.LoadRecords(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -201,7 +200,7 @@ func (b *BaseApi) LoadClamRecordLog(c *gin.Context) { content, err := clamService.LoadRecordLog(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -224,7 +223,7 @@ func (b *BaseApi) SearchClamFile(c *gin.Context) { content, err := clamService.LoadFile(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -245,7 +244,7 @@ func (b *BaseApi) UpdateFile(c *gin.Context) { return } if err := clamService.UpdateFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -267,7 +266,7 @@ func (b *BaseApi) DeleteClam(c *gin.Context) { } if err := clamService.Delete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -289,7 +288,7 @@ func (b *BaseApi) HandleClamScan(c *gin.Context) { } if err := clamService.HandleOnce(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/compose_template.go b/agent/app/api/v2/compose_template.go index 553faa7df..621e75bc5 100644 --- a/agent/app/api/v2/compose_template.go +++ b/agent/app/api/v2/compose_template.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) CreateComposeTemplate(c *gin.Context) { } if err := composeTemplateService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -46,7 +45,7 @@ func (b *BaseApi) SearchComposeTemplate(c *gin.Context) { total, list, err := composeTemplateService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -66,7 +65,7 @@ func (b *BaseApi) SearchComposeTemplate(c *gin.Context) { func (b *BaseApi) ListComposeTemplate(c *gin.Context) { list, err := composeTemplateService.List() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -89,7 +88,7 @@ func (b *BaseApi) DeleteComposeTemplate(c *gin.Context) { } if err := composeTemplateService.Delete(req.Ids); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -114,7 +113,7 @@ func (b *BaseApi) UpdateComposeTemplate(c *gin.Context) { upMap["content"] = req.Content upMap["description"] = req.Description if err := composeTemplateService.Update(req.ID, upMap); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/container.go b/agent/app/api/v2/container.go index 146a20882..79cd79766 100644 --- a/agent/app/api/v2/container.go +++ b/agent/app/api/v2/container.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" "github.com/gin-gonic/gin" "github.com/pkg/errors" @@ -28,7 +27,7 @@ func (b *BaseApi) SearchContainer(c *gin.Context) { total, list, err := containerService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -48,7 +47,7 @@ func (b *BaseApi) SearchContainer(c *gin.Context) { func (b *BaseApi) ListContainer(c *gin.Context) { list, err := containerService.List() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -65,7 +64,7 @@ func (b *BaseApi) ListContainer(c *gin.Context) { func (b *BaseApi) LoadContainerStatus(c *gin.Context) { data, err := containerService.LoadStatus() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -87,7 +86,7 @@ func (b *BaseApi) SearchCompose(c *gin.Context) { total, list, err := containerService.PageCompose(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -113,7 +112,7 @@ func (b *BaseApi) TestCompose(c *gin.Context) { isOK, err := containerService.TestCompose(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, isOK) @@ -135,7 +134,7 @@ func (b *BaseApi) CreateCompose(c *gin.Context) { } if err := containerService.CreateCompose(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -157,7 +156,7 @@ func (b *BaseApi) OperatorCompose(c *gin.Context) { } if err := containerService.ComposeOperation(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -179,7 +178,7 @@ func (b *BaseApi) ContainerUpdate(c *gin.Context) { } if err := containerService.ContainerUpdate(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -201,7 +200,7 @@ func (b *BaseApi) ContainerInfo(c *gin.Context) { data, err := containerService.ContainerInfo(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -215,7 +214,7 @@ func (b *BaseApi) ContainerInfo(c *gin.Context) { func (b *BaseApi) LoadResourceLimit(c *gin.Context) { data, err := containerService.LoadResourceLimit() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -229,7 +228,7 @@ func (b *BaseApi) LoadResourceLimit(c *gin.Context) { func (b *BaseApi) ContainerListStats(c *gin.Context) { data, err := containerService.ContainerListStats() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -251,7 +250,7 @@ func (b *BaseApi) ContainerCreate(c *gin.Context) { } if err := containerService.ContainerCreate(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -272,7 +271,7 @@ func (b *BaseApi) ContainerCreateByCommand(c *gin.Context) { } if err := containerService.ContainerCreateByCommand(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -294,7 +293,7 @@ func (b *BaseApi) ContainerUpgrade(c *gin.Context) { } if err := containerService.ContainerUpgrade(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -317,7 +316,7 @@ func (b *BaseApi) ContainerPrune(c *gin.Context) { report, err := containerService.Prune(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, report) @@ -339,7 +338,7 @@ func (b *BaseApi) CleanContainerLog(c *gin.Context) { } if err := containerService.ContainerLogClean(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -379,7 +378,7 @@ func (b *BaseApi) ContainerRename(c *gin.Context) { } if err := containerService.ContainerRename(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -399,7 +398,7 @@ func (b *BaseApi) ContainerCommit(c *gin.Context) { } if err := containerService.ContainerCommit(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -421,7 +420,7 @@ func (b *BaseApi) ContainerOperation(c *gin.Context) { } if err := containerService.ContainerOperation(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -437,13 +436,13 @@ func (b *BaseApi) ContainerOperation(c *gin.Context) { func (b *BaseApi) ContainerStats(c *gin.Context) { containerID, ok := c.Params.Get("id") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error container id in path")) + helper.BadRequest(c, errors.New("error container id in path")) return } result, err := containerService.ContainerStats(containerID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, result) @@ -465,7 +464,7 @@ func (b *BaseApi) Inspect(c *gin.Context) { result, err := containerService.Inspect(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, result) @@ -508,7 +507,7 @@ func (b *BaseApi) DownloadContainerLogs(c *gin.Context) { } err := containerService.DownloadContainerLogs(req.ContainerType, req.Container, req.Since, strconv.Itoa(int(req.Tail)), c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) } } @@ -529,7 +528,7 @@ func (b *BaseApi) SearchNetwork(c *gin.Context) { total, list, err := containerService.PageNetwork(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -549,7 +548,7 @@ func (b *BaseApi) SearchNetwork(c *gin.Context) { func (b *BaseApi) ListNetwork(c *gin.Context) { list, err := containerService.ListNetwork() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -571,7 +570,7 @@ func (b *BaseApi) DeleteNetwork(c *gin.Context) { } if err := containerService.DeleteNetwork(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -593,7 +592,7 @@ func (b *BaseApi) CreateNetwork(c *gin.Context) { } if err := containerService.CreateNetwork(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -616,7 +615,7 @@ func (b *BaseApi) SearchVolume(c *gin.Context) { total, list, err := containerService.PageVolume(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -636,7 +635,7 @@ func (b *BaseApi) SearchVolume(c *gin.Context) { func (b *BaseApi) ListVolume(c *gin.Context) { list, err := containerService.ListVolume() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -658,7 +657,7 @@ func (b *BaseApi) DeleteVolume(c *gin.Context) { } if err := containerService.DeleteVolume(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -680,7 +679,7 @@ func (b *BaseApi) CreateVolume(c *gin.Context) { } if err := containerService.CreateVolume(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -702,7 +701,7 @@ func (b *BaseApi) ComposeUpdate(c *gin.Context) { } if err := containerService.ComposeUpdate(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/cronjob.go b/agent/app/api/v2/cronjob.go index 7d25e17ac..2424a38e2 100644 --- a/agent/app/api/v2/cronjob.go +++ b/agent/app/api/v2/cronjob.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/gin-gonic/gin" ) @@ -26,7 +25,7 @@ func (b *BaseApi) CreateCronjob(c *gin.Context) { } if err := cronjobService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -48,7 +47,7 @@ func (b *BaseApi) LoadNextHandle(c *gin.Context) { list, err := cronjobService.LoadNextHandle(req.Spec) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -70,7 +69,7 @@ func (b *BaseApi) SearchCronjob(c *gin.Context) { total, list, err := cronjobService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -100,7 +99,7 @@ func (b *BaseApi) SearchJobRecords(c *gin.Context) { total, list, err := cronjobService.SearchRecords(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -143,7 +142,7 @@ func (b *BaseApi) CleanRecord(c *gin.Context) { } if err := cronjobService.CleanRecord(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -166,7 +165,7 @@ func (b *BaseApi) DeleteCronjob(c *gin.Context) { } if err := cronjobService.Delete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -188,7 +187,7 @@ func (b *BaseApi) UpdateCronjob(c *gin.Context) { } if err := cronjobService.Update(req.ID, req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -210,7 +209,7 @@ func (b *BaseApi) UpdateCronjobStatus(c *gin.Context) { } if err := cronjobService.UpdateStatus(req.ID, req.Status); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -233,7 +232,7 @@ func (b *BaseApi) TargetDownload(c *gin.Context) { filePath, err := cronjobService.Download(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -256,7 +255,7 @@ func (b *BaseApi) HandleOnce(c *gin.Context) { } if err := cronjobService.HandleOnce(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/dashboard.go b/agent/app/api/v2/dashboard.go index 0c5936f73..32cc07801 100644 --- a/agent/app/api/v2/dashboard.go +++ b/agent/app/api/v2/dashboard.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -18,7 +17,7 @@ import ( func (b *BaseApi) LoadDashboardOsInfo(c *gin.Context) { data, err := dashboardService.LoadOsInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -36,17 +35,17 @@ func (b *BaseApi) LoadDashboardOsInfo(c *gin.Context) { func (b *BaseApi) LoadDashboardBaseInfo(c *gin.Context) { ioOption, ok := c.Params.Get("ioOption") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error ioOption in path")) + helper.BadRequest(c, errors.New("error ioOption in path")) return } netOption, ok := c.Params.Get("netOption") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error netOption in path")) + helper.BadRequest(c, errors.New("error ioOption in path")) return } data, err := dashboardService.LoadBaseInfo(ioOption, netOption) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -75,12 +74,12 @@ func (b *BaseApi) LoadCurrentInfoForNode(c *gin.Context) { func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) { ioOption, ok := c.Params.Get("ioOption") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error ioOption in path")) + helper.BadRequest(c, errors.New("error ioOption in path")) return } netOption, ok := c.Params.Get("netOption") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error netOption in path")) + helper.BadRequest(c, errors.New("error netOption in path")) return } @@ -99,11 +98,11 @@ func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) { func (b *BaseApi) SystemRestart(c *gin.Context) { operation, ok := c.Params.Get("operation") if !ok { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error operation in path")) + helper.BadRequest(c, errors.New("error operation in path")) return } if err := dashboardService.Restart(operation); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/database.go b/agent/app/api/v2/database.go index b1cf78379..7cc5de984 100644 --- a/agent/app/api/v2/database.go +++ b/agent/app/api/v2/database.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -33,7 +32,7 @@ func (b *BaseApi) CreateDatabase(c *gin.Context) { } if err := databaseService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -81,7 +80,7 @@ func (b *BaseApi) SearchDatabase(c *gin.Context) { total, list, err := databaseService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -100,12 +99,12 @@ func (b *BaseApi) SearchDatabase(c *gin.Context) { func (b *BaseApi) ListDatabase(c *gin.Context) { dbType, err := helper.GetStrParamByKey(c, "type") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } list, err := databaseService.List(dbType) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -121,12 +120,12 @@ func (b *BaseApi) ListDatabase(c *gin.Context) { func (b *BaseApi) LoadDatabaseItems(c *gin.Context) { dbType, err := helper.GetStrParamByKey(c, "type") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } list, err := databaseService.LoadItems(dbType) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -142,12 +141,12 @@ func (b *BaseApi) LoadDatabaseItems(c *gin.Context) { func (b *BaseApi) GetDatabase(c *gin.Context) { name, err := helper.GetStrParamByKey(c, "name") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } data, err := databaseService.Get(name) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -170,7 +169,7 @@ func (b *BaseApi) DeleteCheckDatabase(c *gin.Context) { apps, err := databaseService.DeleteCheck(req.ID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, apps) @@ -192,7 +191,7 @@ func (b *BaseApi) DeleteDatabase(c *gin.Context) { } if err := databaseService.Delete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -222,7 +221,7 @@ func (b *BaseApi) UpdateDatabase(c *gin.Context) { } if err := databaseService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/database_common.go b/agent/app/api/v2/database_common.go index df7d1b285..ad65b4caa 100644 --- a/agent/app/api/v2/database_common.go +++ b/agent/app/api/v2/database_common.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) LoadDBBaseInfo(c *gin.Context) { data, err := dbCommonService.LoadBaseInfo(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -45,7 +44,7 @@ func (b *BaseApi) LoadDBFile(c *gin.Context) { } content, err := dbCommonService.LoadDatabaseFile(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, content) @@ -67,7 +66,7 @@ func (b *BaseApi) UpdateDBConfByFile(c *gin.Context) { } if err := dbCommonService.UpdateConfByFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/database_mysql.go b/agent/app/api/v2/database_mysql.go index 5214203f0..5a9534684 100644 --- a/agent/app/api/v2/database_mysql.go +++ b/agent/app/api/v2/database_mysql.go @@ -6,7 +6,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -28,14 +27,14 @@ func (b *BaseApi) CreateMysql(c *gin.Context) { if len(req.Password) != 0 { password, err := base64.StdEncoding.DecodeString(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Password = string(password) } if _, err := mysqlService.Create(context.Background(), req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -59,14 +58,14 @@ func (b *BaseApi) BindUser(c *gin.Context) { if len(req.Password) != 0 { password, err := base64.StdEncoding.DecodeString(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Password = string(password) } if err := mysqlService.BindUser(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -88,7 +87,7 @@ func (b *BaseApi) UpdateMysqlDescription(c *gin.Context) { } if err := mysqlService.UpdateDescription(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -112,14 +111,14 @@ func (b *BaseApi) ChangeMysqlPassword(c *gin.Context) { if len(req.Value) != 0 { value, err := base64.StdEncoding.DecodeString(req.Value) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Value = string(value) } if err := mysqlService.ChangePassword(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -141,7 +140,7 @@ func (b *BaseApi) ChangeMysqlAccess(c *gin.Context) { } if err := mysqlService.ChangeAccess(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -163,7 +162,7 @@ func (b *BaseApi) UpdateMysqlVariables(c *gin.Context) { } if err := mysqlService.UpdateVariables(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -185,7 +184,7 @@ func (b *BaseApi) SearchMysql(c *gin.Context) { total, list, err := mysqlService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -206,7 +205,7 @@ func (b *BaseApi) SearchMysql(c *gin.Context) { func (b *BaseApi) ListDBName(c *gin.Context) { list, err := mysqlService.ListDBOption() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -227,7 +226,7 @@ func (b *BaseApi) LoadDBFromRemote(c *gin.Context) { } if err := mysqlService.LoadFromRemote(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -250,7 +249,7 @@ func (b *BaseApi) DeleteCheckMysql(c *gin.Context) { apps, err := mysqlService.DeleteCheck(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, apps) @@ -273,7 +272,7 @@ func (b *BaseApi) DeleteMysql(c *gin.Context) { tx, ctx := helper.GetTxAndContext() if err := mysqlService.Delete(ctx, req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) tx.Rollback() return } @@ -296,7 +295,7 @@ func (b *BaseApi) LoadRemoteAccess(c *gin.Context) { } isRemote, err := mysqlService.LoadRemoteAccess(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -319,7 +318,7 @@ func (b *BaseApi) LoadStatus(c *gin.Context) { data, err := mysqlService.LoadStatus(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -342,7 +341,7 @@ func (b *BaseApi) LoadVariables(c *gin.Context) { data, err := mysqlService.LoadVariables(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/database_postgresql.go b/agent/app/api/v2/database_postgresql.go index ff6deed3d..ffd9768bf 100644 --- a/agent/app/api/v2/database_postgresql.go +++ b/agent/app/api/v2/database_postgresql.go @@ -6,7 +6,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -28,14 +27,14 @@ func (b *BaseApi) CreatePostgresql(c *gin.Context) { if len(req.Password) != 0 { password, err := base64.StdEncoding.DecodeString(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Password = string(password) } if _, err := postgresqlService.Create(context.Background(), req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -57,7 +56,7 @@ func (b *BaseApi) BindPostgresqlUser(c *gin.Context) { } if err := postgresqlService.BindUser(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -79,7 +78,7 @@ func (b *BaseApi) UpdatePostgresqlDescription(c *gin.Context) { } if err := postgresqlService.UpdateDescription(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -101,7 +100,7 @@ func (b *BaseApi) ChangePostgresqlPrivileges(c *gin.Context) { } if err := postgresqlService.ChangePrivileges(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -125,14 +124,14 @@ func (b *BaseApi) ChangePostgresqlPassword(c *gin.Context) { if len(req.Value) != 0 { value, err := base64.StdEncoding.DecodeString(req.Value) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Value = string(value) } if err := postgresqlService.ChangePassword(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -154,7 +153,7 @@ func (b *BaseApi) SearchPostgresql(c *gin.Context) { total, list, err := postgresqlService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -174,12 +173,12 @@ func (b *BaseApi) SearchPostgresql(c *gin.Context) { func (b *BaseApi) LoadPostgresqlDBFromRemote(c *gin.Context) { database, err := helper.GetStrParamByKey(c, "database") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } if err := postgresqlService.LoadFromRemote(database); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -202,7 +201,7 @@ func (b *BaseApi) DeleteCheckPostgresql(c *gin.Context) { apps, err := postgresqlService.DeleteCheck(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, apps) @@ -224,7 +223,7 @@ func (b *BaseApi) DeletePostgresql(c *gin.Context) { } tx, ctx := helper.GetTxAndContext() if err := postgresqlService.Delete(ctx, req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) tx.Rollback() return } diff --git a/agent/app/api/v2/database_redis.go b/agent/app/api/v2/database_redis.go index 357d4e3b6..26926da2c 100644 --- a/agent/app/api/v2/database_redis.go +++ b/agent/app/api/v2/database_redis.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -24,7 +23,7 @@ func (b *BaseApi) LoadRedisStatus(c *gin.Context) { } data, err := redisService.LoadStatus(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -46,7 +45,7 @@ func (b *BaseApi) LoadRedisConf(c *gin.Context) { } data, err := redisService.LoadConf(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -68,7 +67,7 @@ func (b *BaseApi) LoadPersistenceConf(c *gin.Context) { } data, err := redisService.LoadPersistenceConf(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -87,7 +86,7 @@ func (b *BaseApi) CheckHasCli(c *gin.Context) { // @Router /databases/redis/install/cli [post] func (b *BaseApi) InstallCli(c *gin.Context) { if err := redisService.InstallCli(); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -110,7 +109,7 @@ func (b *BaseApi) UpdateRedisConf(c *gin.Context) { } if err := redisService.UpdateConf(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -134,14 +133,14 @@ func (b *BaseApi) ChangeRedisPassword(c *gin.Context) { if len(req.Value) != 0 { value, err := base64.StdEncoding.DecodeString(req.Value) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Value = string(value) } if err := redisService.ChangePassword(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -163,7 +162,7 @@ func (b *BaseApi) UpdateRedisPersistenceConf(c *gin.Context) { } if err := redisService.UpdatePersistenceConf(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/device.go b/agent/app/api/v2/device.go index fb8cc8222..f58dbe998 100644 --- a/agent/app/api/v2/device.go +++ b/agent/app/api/v2/device.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -18,7 +17,7 @@ import ( func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) { data, err := deviceService.LoadBaseInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -35,7 +34,7 @@ func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) { func (b *BaseApi) LoadTimeOption(c *gin.Context) { list, err := deviceService.LoadTimeZone() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -58,7 +57,7 @@ func (b *BaseApi) LoadDeviceConf(c *gin.Context) { list, err := deviceService.LoadConf(req.Name) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -79,7 +78,7 @@ func (b *BaseApi) UpdateDeviceByFile(c *gin.Context) { return } if err := deviceService.UpdateByConf(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -95,7 +94,7 @@ func (b *BaseApi) UpdateDeviceByFile(c *gin.Context) { func (b *BaseApi) LoadUsers(c *gin.Context) { users, err := deviceService.LoadUsers() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, users) @@ -117,7 +116,7 @@ func (b *BaseApi) UpdateDeviceConf(c *gin.Context) { } if err := deviceService.Update(req.Key, req.Value); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -138,7 +137,7 @@ func (b *BaseApi) UpdateDeviceHost(c *gin.Context) { } if err := deviceService.UpdateHosts(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -161,13 +160,13 @@ func (b *BaseApi) UpdateDevicePasswd(c *gin.Context) { if len(req.Passwd) != 0 { password, err := base64.StdEncoding.DecodeString(req.Passwd) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Passwd = string(password) } if err := deviceService.UpdatePasswd(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -189,7 +188,7 @@ func (b *BaseApi) UpdateDeviceSwap(c *gin.Context) { return } if err := deviceService.UpdateSwap(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -212,7 +211,7 @@ func (b *BaseApi) CheckDNS(c *gin.Context) { data, err := deviceService.CheckDNS(req.Key, req.Value) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/docker.go b/agent/app/api/v2/docker.go index 935930741..be7b00667 100644 --- a/agent/app/api/v2/docker.go +++ b/agent/app/api/v2/docker.go @@ -35,7 +35,7 @@ func (b *BaseApi) LoadDaemonJsonFile(c *gin.Context) { } content, err := os.ReadFile(constant.DaemonJsonPath) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, string(content)) @@ -69,7 +69,7 @@ func (b *BaseApi) UpdateDaemonJson(c *gin.Context) { } if err := dockerService.UpdateConf(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -92,7 +92,7 @@ func (b *BaseApi) UpdateLogOption(c *gin.Context) { } if err := dockerService.UpdateLogOption(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -115,7 +115,7 @@ func (b *BaseApi) UpdateIpv6Option(c *gin.Context) { } if err := dockerService.UpdateIpv6Option(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -138,7 +138,7 @@ func (b *BaseApi) UpdateDaemonJsonByFile(c *gin.Context) { } if err := dockerService.UpdateConfByFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -161,7 +161,7 @@ func (b *BaseApi) OperateDocker(c *gin.Context) { } if err := dockerService.OperateDocker(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/fail2ban.go b/agent/app/api/v2/fail2ban.go index 2171a9915..a1dd8ce1a 100644 --- a/agent/app/api/v2/fail2ban.go +++ b/agent/app/api/v2/fail2ban.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -18,7 +17,7 @@ import ( func (b *BaseApi) LoadFail2BanBaseInfo(c *gin.Context) { data, err := fail2banService.LoadBaseInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -41,7 +40,7 @@ func (b *BaseApi) SearchFail2Ban(c *gin.Context) { list, err := fail2banService.Search(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -63,7 +62,7 @@ func (b *BaseApi) OperateFail2Ban(c *gin.Context) { } if err := fail2banService.Operate(req.Operation); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -84,7 +83,7 @@ func (b *BaseApi) OperateSSHD(c *gin.Context) { } if err := fail2banService.OperateSSHD(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -107,7 +106,7 @@ func (b *BaseApi) UpdateFail2BanConf(c *gin.Context) { } if err := fail2banService.UpdateConf(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -124,7 +123,7 @@ func (b *BaseApi) LoadFail2BanConf(c *gin.Context) { path := "/etc/fail2ban/jail.local" file, err := os.ReadFile(path) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -145,7 +144,7 @@ func (b *BaseApi) UpdateFail2BanConfByFile(c *gin.Context) { return } if err := fail2banService.UpdateConfByFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/favorite.go b/agent/app/api/v2/favorite.go index 98a0e6724..5872a1fb8 100644 --- a/agent/app/api/v2/favorite.go +++ b/agent/app/api/v2/favorite.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) SearchFavorite(c *gin.Context) { } total, list, err := favoriteService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -48,7 +47,7 @@ func (b *BaseApi) CreateFavorite(c *gin.Context) { } favorite, err := favoriteService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, favorite) @@ -69,7 +68,7 @@ func (b *BaseApi) DeleteFavorite(c *gin.Context) { return } if err := favoriteService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/file.go b/agent/app/api/v2/file.go index fbc73a666..8ca505248 100644 --- a/agent/app/api/v2/file.go +++ b/agent/app/api/v2/file.go @@ -40,7 +40,7 @@ func (b *BaseApi) ListFiles(c *gin.Context) { } files, err := fileService.GetFileList(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, files) @@ -61,7 +61,7 @@ func (b *BaseApi) SearchUploadWithPage(c *gin.Context) { } total, files, err := fileService.SearchUploadWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -85,7 +85,7 @@ func (b *BaseApi) GetFileTree(c *gin.Context) { } tree, err := fileService.GetFileTree(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, tree) @@ -107,7 +107,7 @@ func (b *BaseApi) CreateFile(c *gin.Context) { } err := fileService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -129,7 +129,7 @@ func (b *BaseApi) DeleteFile(c *gin.Context) { } err := fileService.Delete(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -151,7 +151,7 @@ func (b *BaseApi) BatchDeleteFile(c *gin.Context) { } err := fileService.BatchDelete(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -173,7 +173,7 @@ func (b *BaseApi) ChangeFileMode(c *gin.Context) { } err := fileService.ChangeMode(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -194,7 +194,7 @@ func (b *BaseApi) ChangeFileOwner(c *gin.Context) { return } if err := fileService.ChangeOwner(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -216,7 +216,7 @@ func (b *BaseApi) CompressFile(c *gin.Context) { } err := fileService.Compress(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -238,7 +238,7 @@ func (b *BaseApi) DeCompressFile(c *gin.Context) { } err := fileService.DeCompress(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -260,7 +260,7 @@ func (b *BaseApi) GetContent(c *gin.Context) { } info, err := fileService.GetContent(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, info) @@ -281,7 +281,7 @@ func (b *BaseApi) SaveContent(c *gin.Context) { return } if err := fileService.SaveContent(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -298,7 +298,7 @@ func (b *BaseApi) SaveContent(c *gin.Context) { func (b *BaseApi) UploadFiles(c *gin.Context) { form, err := c.MultipartForm() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } uploadFiles := form.File["file"] @@ -322,7 +322,7 @@ func (b *BaseApi) UploadFiles(c *gin.Context) { if err != nil && os.IsNotExist(err) { mode, err := files.GetParentMode(dir) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } if err = os.MkdirAll(dir, mode); err != nil { @@ -332,7 +332,7 @@ func (b *BaseApi) UploadFiles(c *gin.Context) { } info, err := os.Stat(dir) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } mode := info.Mode() @@ -422,7 +422,7 @@ func (b *BaseApi) ChangeFileName(c *gin.Context) { return } if err := fileService.ChangeName(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -444,7 +444,7 @@ func (b *BaseApi) WgetFile(c *gin.Context) { } key, err := fileService.Wget(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, response.FileWgetRes{ @@ -467,7 +467,7 @@ func (b *BaseApi) MoveFile(c *gin.Context) { return } if err := fileService.MvFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -484,7 +484,7 @@ func (b *BaseApi) Download(c *gin.Context) { filePath := c.Query("path") file, err := os.Open(filePath) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) } defer file.Close() info, _ := file.Stat() @@ -515,12 +515,12 @@ func (b *BaseApi) DownloadChunkFiles(c *gin.Context) { filePath := req.Path fstFile, err := fileOp.OpenFile(filePath) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } info, err := fstFile.Stat() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } if info.IsDir() { @@ -553,7 +553,7 @@ func (b *BaseApi) DownloadChunkFiles(c *gin.Context) { buffer := make([]byte, 1024*1024) file, err := os.Open(filePath) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } defer file.Close() @@ -562,7 +562,7 @@ func (b *BaseApi) DownloadChunkFiles(c *gin.Context) { reader := io.LimitReader(file, endPos-startPos+1) _, err = io.CopyBuffer(c.Writer, reader, buffer) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } } else { @@ -586,7 +586,7 @@ func (b *BaseApi) Size(c *gin.Context) { } res, err := fileService.DirSize(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -650,30 +650,30 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) { var err error fileForm, err := c.FormFile("chunk") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } uploadFile, err := fileForm.Open() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } defer uploadFile.Close() chunkIndex, err := strconv.Atoi(c.PostForm("chunkIndex")) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } chunkCount, err := strconv.Atoi(c.PostForm("chunkCount")) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } fileOp := files.NewFileOp() tmpDir := path.Join(global.CONF.System.TmpDir, "upload") if !fileOp.Stat(tmpDir) { if err := fileOp.CreateDir(tmpDir, 0755); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } } @@ -699,7 +699,7 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) { emptyFile, err = os.Create(filePath) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } defer emptyFile.Close() @@ -753,7 +753,7 @@ func (b *BaseApi) Keys(c *gin.Context) { res := &response.FileProcessKeys{} keys, err := global.CACHE.PrefixScanKey("file-wget-") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } res.Keys = keys @@ -774,7 +774,7 @@ func (b *BaseApi) ReadFileByLine(c *gin.Context) { } res, err := fileService.ReadLogByLine(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -795,7 +795,7 @@ func (b *BaseApi) BatchChangeModeAndOwner(c *gin.Context) { return } if err := fileService.BatchChangeModeAndOwner(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) } helper.SuccessWithOutData(c) } diff --git a/agent/app/api/v2/firewall.go b/agent/app/api/v2/firewall.go index 761016507..42cee0e6a 100644 --- a/agent/app/api/v2/firewall.go +++ b/agent/app/api/v2/firewall.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -16,7 +15,7 @@ import ( func (b *BaseApi) LoadFirewallBaseInfo(c *gin.Context) { data, err := firewallService.LoadBaseInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -39,7 +38,7 @@ func (b *BaseApi) SearchFirewallRule(c *gin.Context) { total, list, err := firewallService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -65,7 +64,7 @@ func (b *BaseApi) OperateFirewall(c *gin.Context) { } if err := firewallService.OperateFirewall(req.Operation); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -88,7 +87,7 @@ func (b *BaseApi) OperatePortRule(c *gin.Context) { } if err := firewallService.OperatePortRule(req, true); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -111,7 +110,7 @@ func (b *BaseApi) OperateForwardRule(c *gin.Context) { } if err := firewallService.OperateForwardRule(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -133,7 +132,7 @@ func (b *BaseApi) OperateIPRule(c *gin.Context) { } if err := firewallService.OperateAddressRule(req, true); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -154,7 +153,7 @@ func (b *BaseApi) BatchOperateRule(c *gin.Context) { } if err := firewallService.BatchOperateRule(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -175,7 +174,7 @@ func (b *BaseApi) UpdateFirewallDescription(c *gin.Context) { } if err := firewallService.UpdateDescription(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -196,7 +195,7 @@ func (b *BaseApi) UpdatePortRule(c *gin.Context) { } if err := firewallService.UpdatePortRule(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -217,7 +216,7 @@ func (b *BaseApi) UpdateAddrRule(c *gin.Context) { } if err := firewallService.UpdateAddrRule(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/ftp.go b/agent/app/api/v2/ftp.go index c3073ac64..b82b415be 100644 --- a/agent/app/api/v2/ftp.go +++ b/agent/app/api/v2/ftp.go @@ -18,7 +18,7 @@ import ( func (b *BaseApi) LoadFtpBaseInfo(c *gin.Context) { data, err := ftpService.LoadBaseInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -117,7 +117,7 @@ func (b *BaseApi) CreateFtp(c *gin.Context) { if len(req.Password) != 0 { pass, err := base64.StdEncoding.DecodeString(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Password = string(pass) @@ -186,7 +186,7 @@ func (b *BaseApi) UpdateFtp(c *gin.Context) { if len(req.Password) != 0 { pass, err := base64.StdEncoding.DecodeString(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.Password = string(pass) diff --git a/agent/app/api/v2/health.go b/agent/app/api/v2/health.go index 2d5603847..57cf547bc 100644 --- a/agent/app/api/v2/health.go +++ b/agent/app/api/v2/health.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/utils/xpack" "github.com/gin-gonic/gin" ) @@ -12,7 +11,7 @@ import ( func (b *BaseApi) CheckHealth(c *gin.Context) { _, err := xpack.RequestToMaster("/api/v2/agent/health", http.MethodGet, nil) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/helper/helper.go b/agent/app/api/v2/helper/helper.go index 72e0b9897..f432d87f7 100644 --- a/agent/app/api/v2/helper/helper.go +++ b/agent/app/api/v2/helper/helper.go @@ -44,6 +44,14 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) { ctx.Abort() } +func InternalServer(ctx *gin.Context, err error) { + ErrorWithDetail(ctx, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) +} + +func BadRequest(ctx *gin.Context, err error) { + ErrorWithDetail(ctx, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) +} + func SuccessWithData(ctx *gin.Context, data interface{}) { if data == nil { data = gin.H{} diff --git a/agent/app/api/v2/host_tool.go b/agent/app/api/v2/host_tool.go index 9c6c214a4..9052b1b53 100644 --- a/agent/app/api/v2/host_tool.go +++ b/agent/app/api/v2/host_tool.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) GetToolStatus(c *gin.Context) { config, err := hostToolService.GetToolStatus(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, config) @@ -45,7 +44,7 @@ func (b *BaseApi) InitToolConfig(c *gin.Context) { } if err := hostToolService.CreateToolConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -67,7 +66,7 @@ func (b *BaseApi) OperateTool(c *gin.Context) { } err := hostToolService.OperateTool(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -90,7 +89,7 @@ func (b *BaseApi) OperateToolConfig(c *gin.Context) { config, err := hostToolService.OperateToolConfig(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, config) @@ -112,7 +111,7 @@ func (b *BaseApi) GetToolLog(c *gin.Context) { logContent, err := hostToolService.GetToolLog(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, logContent) @@ -135,7 +134,7 @@ func (b *BaseApi) OperateProcess(c *gin.Context) { err := hostToolService.OperateSupervisorProcess(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -151,7 +150,7 @@ func (b *BaseApi) OperateProcess(c *gin.Context) { func (b *BaseApi) GetProcess(c *gin.Context) { configs, err := hostToolService.GetSupervisorProcessConfig() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, configs) @@ -173,7 +172,7 @@ func (b *BaseApi) GetProcessFile(c *gin.Context) { } content, err := hostToolService.OperateSupervisorProcessFile(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, content) diff --git a/agent/app/api/v2/image.go b/agent/app/api/v2/image.go index cb41bd5b8..900068934 100644 --- a/agent/app/api/v2/image.go +++ b/agent/app/api/v2/image.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -24,7 +23,7 @@ func (b *BaseApi) SearchImage(c *gin.Context) { total, list, err := imageService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -44,7 +43,7 @@ func (b *BaseApi) SearchImage(c *gin.Context) { func (b *BaseApi) ListAllImage(c *gin.Context) { list, err := imageService.ListAll() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -60,7 +59,7 @@ func (b *BaseApi) ListAllImage(c *gin.Context) { func (b *BaseApi) ListImage(c *gin.Context) { list, err := imageService.List() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -82,7 +81,7 @@ func (b *BaseApi) ImageBuild(c *gin.Context) { } if err := imageService.ImageBuild(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -105,7 +104,7 @@ func (b *BaseApi) ImagePull(c *gin.Context) { } if err := imageService.ImagePull(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -128,7 +127,7 @@ func (b *BaseApi) ImagePush(c *gin.Context) { } if err := imageService.ImagePush(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -152,7 +151,7 @@ func (b *BaseApi) ImageRemove(c *gin.Context) { data, err := imageService.ImageRemove(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -175,7 +174,7 @@ func (b *BaseApi) ImageSave(c *gin.Context) { } if err := imageService.ImageSave(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -198,7 +197,7 @@ func (b *BaseApi) ImageTag(c *gin.Context) { } if err := imageService.ImageTag(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -221,7 +220,7 @@ func (b *BaseApi) ImageLoad(c *gin.Context) { } if err := imageService.ImageLoad(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/image_repo.go b/agent/app/api/v2/image_repo.go index 683d5bb70..32dc55f1c 100644 --- a/agent/app/api/v2/image_repo.go +++ b/agent/app/api/v2/image_repo.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -24,7 +23,7 @@ func (b *BaseApi) SearchRepo(c *gin.Context) { total, list, err := imageRepoService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -44,7 +43,7 @@ func (b *BaseApi) SearchRepo(c *gin.Context) { func (b *BaseApi) ListRepo(c *gin.Context) { list, err := imageRepoService.List() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -67,7 +66,7 @@ func (b *BaseApi) CheckRepoStatus(c *gin.Context) { } if err := imageRepoService.Login(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -90,7 +89,7 @@ func (b *BaseApi) CreateRepo(c *gin.Context) { } if err := imageRepoService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -113,7 +112,7 @@ func (b *BaseApi) DeleteRepo(c *gin.Context) { } if err := imageRepoService.BatchDelete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -136,7 +135,7 @@ func (b *BaseApi) UpdateRepo(c *gin.Context) { } if err := imageRepoService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/logs.go b/agent/app/api/v2/logs.go index 7c5f91291..b096ff5ee 100644 --- a/agent/app/api/v2/logs.go +++ b/agent/app/api/v2/logs.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -16,7 +15,7 @@ import ( func (b *BaseApi) GetSystemFiles(c *gin.Context) { data, err := logService.ListSystemLogFile() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -37,7 +36,7 @@ func (b *BaseApi) GetSystemLogs(c *gin.Context) { data, err := logService.LoadSystemLog(req.Name) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/monitor.go b/agent/app/api/v2/monitor.go index 66fc50b38..a23e38be5 100644 --- a/agent/app/api/v2/monitor.go +++ b/agent/app/api/v2/monitor.go @@ -5,7 +5,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" "github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/net" @@ -26,7 +25,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { data, err := monitorService.LoadMonitorData(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -41,7 +40,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { // @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空监控数据","formatEN":"clean monitor datas"} func (b *BaseApi) CleanMonitor(c *gin.Context) { if err := monitorService.CleanData(); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -57,7 +56,7 @@ func (b *BaseApi) CleanMonitor(c *gin.Context) { func (b *BaseApi) LoadMonitorSetting(c *gin.Context) { setting, err := monitorService.LoadSetting() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -78,7 +77,7 @@ func (b *BaseApi) UpdateMonitorSetting(c *gin.Context) { return } if err := monitorService.UpdateSetting(req.Key, req.Value); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/agent/app/api/v2/nginx.go b/agent/app/api/v2/nginx.go index 05d2a0999..a2a7e514c 100644 --- a/agent/app/api/v2/nginx.go +++ b/agent/app/api/v2/nginx.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -16,7 +15,7 @@ import ( func (b *BaseApi) GetNginx(c *gin.Context) { fileInfo, err := nginxService.GetNginxConfig() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, fileInfo) @@ -38,7 +37,7 @@ func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) { params, err := nginxService.GetConfigByScope(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, params) @@ -59,7 +58,7 @@ func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) { return } if err := nginxService.UpdateConfigByScope(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -74,7 +73,7 @@ func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) { func (b *BaseApi) GetNginxStatus(c *gin.Context) { res, err := nginxService.GetStatus() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -96,7 +95,7 @@ func (b *BaseApi) UpdateNginxFile(c *gin.Context) { } if err := nginxService.UpdateConfigFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -111,7 +110,7 @@ func (b *BaseApi) UpdateNginxFile(c *gin.Context) { // @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清理 Openresty 代理缓存","formatEN":"Clear nginx proxy cache"} func (b *BaseApi) ClearNginxProxyCache(c *gin.Context) { if err := nginxService.ClearProxyCache(); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -132,7 +131,7 @@ func (b *BaseApi) BuildNginx(c *gin.Context) { return } if err := nginxService.Build(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -153,7 +152,7 @@ func (b *BaseApi) UpdateNginxModule(c *gin.Context) { return } if err := nginxService.UpdateModule(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -168,7 +167,7 @@ func (b *BaseApi) UpdateNginxModule(c *gin.Context) { func (b *BaseApi) GetNginxModules(c *gin.Context) { modules, err := nginxService.GetModules() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, modules) diff --git a/agent/app/api/v2/php_extensions.go b/agent/app/api/v2/php_extensions.go index a031aa97b..4d9543511 100644 --- a/agent/app/api/v2/php_extensions.go +++ b/agent/app/api/v2/php_extensions.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -24,14 +23,14 @@ func (b *BaseApi) PagePHPExtensions(c *gin.Context) { if req.All { list, err := phpExtensionsService.List() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) } else { total, list, err := phpExtensionsService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -56,7 +55,7 @@ func (b *BaseApi) CreatePHPExtensions(c *gin.Context) { return } if err := phpExtensionsService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -76,7 +75,7 @@ func (b *BaseApi) UpdatePHPExtensions(c *gin.Context) { return } if err := phpExtensionsService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -96,7 +95,7 @@ func (b *BaseApi) DeletePHPExtensions(c *gin.Context) { return } if err := phpExtensionsService.Delete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/process.go b/agent/app/api/v2/process.go index 8aa2284c1..3bcfe1b2a 100644 --- a/agent/app/api/v2/process.go +++ b/agent/app/api/v2/process.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" websocket2 "github.com/1Panel-dev/1Panel/agent/utils/websocket" "github.com/gin-gonic/gin" ) @@ -32,7 +31,7 @@ func (b *BaseApi) StopProcess(c *gin.Context) { return } if err := processService.StopProcess(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/recycle_bin.go b/agent/app/api/v2/recycle_bin.go index b4af1483a..894eb59f2 100644 --- a/agent/app/api/v2/recycle_bin.go +++ b/agent/app/api/v2/recycle_bin.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) SearchRecycleBinFile(c *gin.Context) { } total, list, err := recycleBinService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -47,7 +46,7 @@ func (b *BaseApi) ReduceRecycleBinFile(c *gin.Context) { return } if err := recycleBinService.Reduce(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -63,7 +62,7 @@ func (b *BaseApi) ReduceRecycleBinFile(c *gin.Context) { // @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清空回收站","formatEN":"清空回收站"} func (b *BaseApi) ClearRecycleBinFile(c *gin.Context) { if err := recycleBinService.Clear(); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -79,7 +78,7 @@ func (b *BaseApi) ClearRecycleBinFile(c *gin.Context) { func (b *BaseApi) GetRecycleStatus(c *gin.Context) { settingInfo, err := settingService.GetSettingInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, settingInfo.FileRecycleBin) diff --git a/agent/app/api/v2/runtime.go b/agent/app/api/v2/runtime.go index 2b6d8468e..3f5e0fd08 100644 --- a/agent/app/api/v2/runtime.go +++ b/agent/app/api/v2/runtime.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) SearchRuntimes(c *gin.Context) { } total, items, err := runtimeService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -48,7 +47,7 @@ func (b *BaseApi) CreateRuntime(c *gin.Context) { } ssl, err := runtimeService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, ssl) @@ -70,7 +69,7 @@ func (b *BaseApi) DeleteRuntime(c *gin.Context) { } err := runtimeService.Delete(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -86,12 +85,12 @@ func (b *BaseApi) DeleteRuntime(c *gin.Context) { func (b *BaseApi) DeleteRuntimeCheck(c *gin.Context) { runTimeId, err := helper.GetIntParamByKey(c, "runTimeId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } checkData, err := runtimeService.DeleteCheck(runTimeId) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, checkData) @@ -112,7 +111,7 @@ func (b *BaseApi) UpdateRuntime(c *gin.Context) { return } if err := runtimeService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -129,12 +128,12 @@ func (b *BaseApi) UpdateRuntime(c *gin.Context) { func (b *BaseApi) GetRuntime(c *gin.Context) { id, err := helper.GetIntParamByKey(c, "id") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := runtimeService.Get(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -155,7 +154,7 @@ func (b *BaseApi) GetNodePackageRunScript(c *gin.Context) { } res, err := runtimeService.GetNodePackageRunScript(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -177,7 +176,7 @@ func (b *BaseApi) OperateRuntime(c *gin.Context) { } err := runtimeService.OperateRuntime(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -198,7 +197,7 @@ func (b *BaseApi) GetNodeModules(c *gin.Context) { } res, err := runtimeService.GetNodeModules(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -219,7 +218,7 @@ func (b *BaseApi) OperateNodeModules(c *gin.Context) { } err := runtimeService.OperateNodeModules(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -235,7 +234,7 @@ func (b *BaseApi) OperateNodeModules(c *gin.Context) { func (b *BaseApi) SyncStatus(c *gin.Context) { err := runtimeService.SyncRuntimeStatus() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -252,12 +251,12 @@ func (b *BaseApi) SyncStatus(c *gin.Context) { func (b *BaseApi) GetRuntimeExtension(c *gin.Context) { id, err := helper.GetIntParamByKey(c, "id") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := runtimeService.GetPHPExtensions(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -278,7 +277,7 @@ func (b *BaseApi) InstallPHPExtension(c *gin.Context) { } err := runtimeService.InstallPHPExtension(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -299,7 +298,7 @@ func (b *BaseApi) UnInstallPHPExtension(c *gin.Context) { } err := runtimeService.UnInstallPHPExtension(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -316,12 +315,12 @@ func (b *BaseApi) UnInstallPHPExtension(c *gin.Context) { func (b *BaseApi) GetPHPConfig(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } data, err := runtimeService.GetPHPConfig(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -342,7 +341,7 @@ func (b *BaseApi) UpdatePHPConfig(c *gin.Context) { return } if err := runtimeService.UpdatePHPConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -363,7 +362,7 @@ func (b *BaseApi) UpdatePHPFile(c *gin.Context) { return } if err := runtimeService.UpdatePHPConfigFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -384,7 +383,7 @@ func (b *BaseApi) GetPHPConfigFile(c *gin.Context) { } data, err := runtimeService.GetPHPConfigFile(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -404,7 +403,7 @@ func (b *BaseApi) UpdateFPMConfig(c *gin.Context) { return } if err := runtimeService.UpdateFPMConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -421,12 +420,12 @@ func (b *BaseApi) UpdateFPMConfig(c *gin.Context) { func (b *BaseApi) GetFPMConfig(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } data, err := runtimeService.GetFPMConfig(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -443,12 +442,12 @@ func (b *BaseApi) GetFPMConfig(c *gin.Context) { func (b *BaseApi) GetSupervisorProcess(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } data, err := runtimeService.GetSupervisorProcess(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -469,7 +468,7 @@ func (b *BaseApi) OperateSupervisorProcess(c *gin.Context) { } err := runtimeService.OperateSupervisorProcess(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -490,7 +489,7 @@ func (b *BaseApi) OperateSupervisorProcessFile(c *gin.Context) { } res, err := runtimeService.OperateSupervisorProcessFile(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) diff --git a/agent/app/api/v2/setting.go b/agent/app/api/v2/setting.go index 21859336e..7af05e35f 100644 --- a/agent/app/api/v2/setting.go +++ b/agent/app/api/v2/setting.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" "github.com/gin-gonic/gin" ) @@ -17,7 +16,7 @@ import ( func (b *BaseApi) GetSettingInfo(c *gin.Context) { setting, err := settingService.GetSettingInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, setting) @@ -49,7 +48,7 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) { } if err := settingService.Update(req.Key, req.Value); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/snapshot.go b/agent/app/api/v2/snapshot.go index 0ec84daaf..de9e809b0 100644 --- a/agent/app/api/v2/snapshot.go +++ b/agent/app/api/v2/snapshot.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -16,7 +15,7 @@ import ( func (b *BaseApi) LoadSnapshotData(c *gin.Context) { data, err := snapshotService.LoadSnapshotData() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -38,7 +37,7 @@ func (b *BaseApi) CreateSnapshot(c *gin.Context) { } if err := snapshotService.SnapshotCreate(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -60,7 +59,7 @@ func (b *BaseApi) RecreateSnapshot(c *gin.Context) { } if err := snapshotService.SnapshotReCreate(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -82,7 +81,7 @@ func (b *BaseApi) ImportSnapshot(c *gin.Context) { } if err := snapshotService.SnapshotImport(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -104,7 +103,7 @@ func (b *BaseApi) UpdateSnapDescription(c *gin.Context) { } if err := snapshotService.UpdateDescription(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -126,7 +125,7 @@ func (b *BaseApi) SearchSnapshot(c *gin.Context) { total, accounts, err := snapshotService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -151,7 +150,7 @@ func (b *BaseApi) LoadSnapshotSize(c *gin.Context) { accounts, err := snapshotService.LoadSize(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, accounts) @@ -173,7 +172,7 @@ func (b *BaseApi) RecoverSnapshot(c *gin.Context) { } if err := snapshotService.SnapshotRecover(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -195,7 +194,7 @@ func (b *BaseApi) RollbackSnapshot(c *gin.Context) { } if err := snapshotService.SnapshotRollback(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -217,7 +216,7 @@ func (b *BaseApi) DeleteSnapshot(c *gin.Context) { } if err := snapshotService.Delete(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/ssh.go b/agent/app/api/v2/ssh.go index 60f69f996..f9faf6d4c 100644 --- a/agent/app/api/v2/ssh.go +++ b/agent/app/api/v2/ssh.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -16,7 +15,7 @@ import ( func (b *BaseApi) GetSSHInfo(c *gin.Context) { info, err := sshService.GetSSHInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, info) @@ -37,7 +36,7 @@ func (b *BaseApi) OperateSSH(c *gin.Context) { } if err := sshService.OperateSSH(req.Operation); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -59,7 +58,7 @@ func (b *BaseApi) UpdateSSH(c *gin.Context) { } if err := sshService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -81,7 +80,7 @@ func (b *BaseApi) UpdateSSHByfile(c *gin.Context) { } if err := sshService.UpdateByFile(req.File); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -103,7 +102,7 @@ func (b *BaseApi) GenerateSSH(c *gin.Context) { } if err := sshService.GenerateSSH(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -125,7 +124,7 @@ func (b *BaseApi) LoadSSHSecret(c *gin.Context) { data, err := sshService.LoadSSHSecret(req.EncryptionMode) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -147,7 +146,7 @@ func (b *BaseApi) LoadSSHLogs(c *gin.Context) { data, err := sshService.LoadLog(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -162,7 +161,7 @@ func (b *BaseApi) LoadSSHLogs(c *gin.Context) { func (b *BaseApi) LoadSSHConf(c *gin.Context) { data, err := sshService.LoadSSHConf() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) diff --git a/agent/app/api/v2/task.go b/agent/app/api/v2/task.go index 310cc0e51..edc1e2b9a 100644 --- a/agent/app/api/v2/task.go +++ b/agent/app/api/v2/task.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -22,7 +21,7 @@ func (b *BaseApi) PageTasks(c *gin.Context) { } total, list, err := taskService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ diff --git a/agent/app/api/v2/website.go b/agent/app/api/v2/website.go index 8960542e2..f16ec0b73 100644 --- a/agent/app/api/v2/website.go +++ b/agent/app/api/v2/website.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) PageWebsite(c *gin.Context) { } total, websites, err := websiteService.PageWebsite(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -41,7 +40,7 @@ func (b *BaseApi) PageWebsite(c *gin.Context) { func (b *BaseApi) GetWebsites(c *gin.Context) { websites, err := websiteService.GetWebsites() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, websites) @@ -60,7 +59,7 @@ func (b *BaseApi) GetWebsiteOptions(c *gin.Context) { } websites, err := websiteService.GetWebsiteOptions(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, websites) @@ -82,7 +81,7 @@ func (b *BaseApi) CreateWebsite(c *gin.Context) { } err := websiteService.CreateWebsite(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -104,7 +103,7 @@ func (b *BaseApi) OpWebsite(c *gin.Context) { } err := websiteService.OpWebsite(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -126,7 +125,7 @@ func (b *BaseApi) DeleteWebsite(c *gin.Context) { } err := websiteService.DeleteWebsite(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -147,7 +146,7 @@ func (b *BaseApi) UpdateWebsite(c *gin.Context) { return } if err := websiteService.UpdateWebsite(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -164,12 +163,12 @@ func (b *BaseApi) UpdateWebsite(c *gin.Context) { func (b *BaseApi) GetWebsite(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } website, err := websiteService.GetWebsite(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, website) @@ -186,14 +185,14 @@ func (b *BaseApi) GetWebsite(c *gin.Context) { func (b *BaseApi) GetWebsiteNginx(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } configType := c.Param("type") fileInfo, err := websiteService.GetWebsiteNginxConfig(id, configType) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, fileInfo) @@ -214,7 +213,7 @@ func (b *BaseApi) GetNginxConfig(c *gin.Context) { } config, err := websiteService.GetNginxConfigByScope(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, config) @@ -235,7 +234,7 @@ func (b *BaseApi) UpdateNginxConfig(c *gin.Context) { return } if err := websiteService.UpdateNginxConfigByScope(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -252,12 +251,12 @@ func (b *BaseApi) UpdateNginxConfig(c *gin.Context) { func (b *BaseApi) GetHTTPSConfig(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := websiteService.GetWebsiteHTTPS(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -281,7 +280,7 @@ func (b *BaseApi) UpdateHTTPSConfig(c *gin.Context) { res, err := websiteService.OpWebsiteHTTPS(ctx, req) if err != nil { tx.Rollback() - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } tx.Commit() @@ -303,7 +302,7 @@ func (b *BaseApi) CreateWebsiteCheck(c *gin.Context) { } data, err := websiteService.PreInstallCheck(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -324,7 +323,7 @@ func (b *BaseApi) UpdateWebsiteNginxConfig(c *gin.Context) { return } if err := websiteService.UpdateNginxConfigFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -346,7 +345,7 @@ func (b *BaseApi) OpWebsiteLog(c *gin.Context) { } res, err := websiteService.OpWebsiteLog(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -367,7 +366,7 @@ func (b *BaseApi) ChangeDefaultServer(c *gin.Context) { return } if err := websiteService.ChangeDefaultServer(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -388,7 +387,7 @@ func (b *BaseApi) ChangePHPVersion(c *gin.Context) { return } if err := websiteService.ChangePHPVersion(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -409,7 +408,7 @@ func (b *BaseApi) GetRewriteConfig(c *gin.Context) { } res, err := websiteService.GetRewriteConfig(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -430,7 +429,7 @@ func (b *BaseApi) UpdateRewriteConfig(c *gin.Context) { return } if err := websiteService.UpdateRewriteConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -451,7 +450,7 @@ func (b *BaseApi) UpdateSiteDir(c *gin.Context) { return } if err := websiteService.UpdateSiteDir(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -472,7 +471,7 @@ func (b *BaseApi) UpdateSiteDirPermission(c *gin.Context) { return } if err := websiteService.UpdateSitePermission(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -493,7 +492,7 @@ func (b *BaseApi) GetProxyConfig(c *gin.Context) { } res, err := websiteService.GetProxies(req.ID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -515,7 +514,7 @@ func (b *BaseApi) UpdateProxyConfig(c *gin.Context) { } err := websiteService.OperateProxy(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -536,7 +535,7 @@ func (b *BaseApi) UpdateProxyConfigFile(c *gin.Context) { return } if err := websiteService.UpdateProxyFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -557,7 +556,7 @@ func (b *BaseApi) GetAuthConfig(c *gin.Context) { } res, err := websiteService.GetAuthBasics(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -577,7 +576,7 @@ func (b *BaseApi) UpdateAuthConfig(c *gin.Context) { return } if err := websiteService.UpdateAuthBasic(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -598,7 +597,7 @@ func (b *BaseApi) GetPathAuthConfig(c *gin.Context) { } res, err := websiteService.GetPathAuthBasics(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -618,7 +617,7 @@ func (b *BaseApi) UpdatePathAuthConfig(c *gin.Context) { return } if err := websiteService.UpdatePathAuthBasic(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -639,7 +638,7 @@ func (b *BaseApi) GetAntiLeech(c *gin.Context) { } res, err := websiteService.GetAntiLeech(req.WebsiteID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -659,7 +658,7 @@ func (b *BaseApi) UpdateAntiLeech(c *gin.Context) { return } if err := websiteService.UpdateAntiLeech(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -681,7 +680,7 @@ func (b *BaseApi) UpdateRedirectConfig(c *gin.Context) { } err := websiteService.OperateRedirect(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -702,7 +701,7 @@ func (b *BaseApi) GetRedirectConfig(c *gin.Context) { } res, err := websiteService.GetRedirect(req.WebsiteID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -723,7 +722,7 @@ func (b *BaseApi) UpdateRedirectConfigFile(c *gin.Context) { return } if err := websiteService.UpdateRedirectFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -744,7 +743,7 @@ func (b *BaseApi) GetDirConfig(c *gin.Context) { } res, err := websiteService.LoadWebsiteDirConfig(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -760,12 +759,12 @@ func (b *BaseApi) GetDirConfig(c *gin.Context) { func (b *BaseApi) GetDefaultHtml(c *gin.Context) { resourceType, err := helper.GetStrParamByKey(c, "type") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } fileInfo, err := websiteService.GetDefaultHtml(resourceType) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, fileInfo) @@ -786,7 +785,7 @@ func (b *BaseApi) UpdateDefaultHtml(c *gin.Context) { return } if err := websiteService.UpdateDefaultHtml(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -803,12 +802,12 @@ func (b *BaseApi) UpdateDefaultHtml(c *gin.Context) { func (b *BaseApi) GetLoadBalances(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := websiteService.GetLoadBalances(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -828,7 +827,7 @@ func (b *BaseApi) CreateLoadBalance(c *gin.Context) { return } if err := websiteService.CreateLoadBalance(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -848,7 +847,7 @@ func (b *BaseApi) DeleteLoadBalance(c *gin.Context) { return } if err := websiteService.DeleteLoadBalance(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -868,7 +867,7 @@ func (b *BaseApi) UpdateLoadBalance(c *gin.Context) { return } if err := websiteService.UpdateLoadBalance(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -888,7 +887,7 @@ func (b *BaseApi) UpdateLoadBalanceFile(c *gin.Context) { return } if err := websiteService.UpdateLoadBalanceFile(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -900,7 +899,7 @@ func (b *BaseApi) ChangeWebsiteGroup(c *gin.Context) { return } if err := websiteService.ChangeGroup(req.Group, req.NewGroup); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -920,7 +919,7 @@ func (b *BaseApi) UpdateProxyCache(c *gin.Context) { return } if err := websiteService.UpdateProxyCache(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -936,12 +935,12 @@ func (b *BaseApi) UpdateProxyCache(c *gin.Context) { func (b *BaseApi) GetProxyCache(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := websiteService.GetProxyCache(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -962,7 +961,7 @@ func (b *BaseApi) SetRealIPConfig(c *gin.Context) { return } if err := websiteService.SetRealIPConfig(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -979,12 +978,12 @@ func (b *BaseApi) SetRealIPConfig(c *gin.Context) { func (b *BaseApi) GetRealIPConfig(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := websiteService.GetRealIPConfig(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -1001,12 +1000,12 @@ func (b *BaseApi) GetRealIPConfig(c *gin.Context) { func (b *BaseApi) GetWebsiteResource(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } res, err := websiteService.GetWebsiteResource(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -1022,7 +1021,7 @@ func (b *BaseApi) GetWebsiteResource(c *gin.Context) { func (b *BaseApi) GetWebsiteDatabase(c *gin.Context) { res, err := websiteService.ListDatabases() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -1042,7 +1041,7 @@ func (b *BaseApi) ChangeWebsiteDatabase(c *gin.Context) { return } if err := websiteService.ChangeDatabase(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -1062,7 +1061,7 @@ func (b *BaseApi) OperateCustomRewrite(c *gin.Context) { return } if err := websiteService.OperateCustomRewrite(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -1078,7 +1077,7 @@ func (b *BaseApi) OperateCustomRewrite(c *gin.Context) { func (b *BaseApi) ListCustomRewrite(c *gin.Context) { res, err := websiteService.ListCustomRewrite() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) diff --git a/agent/app/api/v2/website_acme_account.go b/agent/app/api/v2/website_acme_account.go index e807b6a57..ea98d5a94 100644 --- a/agent/app/api/v2/website_acme_account.go +++ b/agent/app/api/v2/website_acme_account.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) PageWebsiteAcmeAccount(c *gin.Context) { } total, accounts, err := websiteAcmeAccountService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -48,7 +47,7 @@ func (b *BaseApi) CreateWebsiteAcmeAccount(c *gin.Context) { } res, err := websiteAcmeAccountService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -69,7 +68,7 @@ func (b *BaseApi) DeleteWebsiteAcmeAccount(c *gin.Context) { return } if err := websiteAcmeAccountService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/website_ca.go b/agent/app/api/v2/website_ca.go index 381952509..3f8fa3d93 100644 --- a/agent/app/api/v2/website_ca.go +++ b/agent/app/api/v2/website_ca.go @@ -8,7 +8,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -27,7 +26,7 @@ func (b *BaseApi) PageWebsiteCA(c *gin.Context) { } total, cas, err := websiteCAService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -52,7 +51,7 @@ func (b *BaseApi) CreateWebsiteCA(c *gin.Context) { } res, err := websiteCAService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -73,7 +72,7 @@ func (b *BaseApi) GetWebsiteCA(c *gin.Context) { } res, err := websiteCAService.GetCA(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -94,7 +93,7 @@ func (b *BaseApi) DeleteWebsiteCA(c *gin.Context) { return } if err := websiteCAService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -115,7 +114,7 @@ func (b *BaseApi) ObtainWebsiteCA(c *gin.Context) { return } if _, err := websiteCAService.ObtainSSL(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -141,7 +140,7 @@ func (b *BaseApi) RenewWebsiteCA(c *gin.Context) { Unit: "year", Time: 1, }); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -163,13 +162,13 @@ func (b *BaseApi) DownloadCAFile(c *gin.Context) { } file, err := websiteCAService.DownloadFile(req.ID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } defer file.Close() info, err := file.Stat() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } c.Header("Content-Length", strconv.FormatInt(info.Size(), 10)) diff --git a/agent/app/api/v2/website_dns_account.go b/agent/app/api/v2/website_dns_account.go index a00244583..7902b51a8 100644 --- a/agent/app/api/v2/website_dns_account.go +++ b/agent/app/api/v2/website_dns_account.go @@ -4,7 +4,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) PageWebsiteDnsAccount(c *gin.Context) { } total, accounts, err := websiteDnsAccountService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -47,7 +46,7 @@ func (b *BaseApi) CreateWebsiteDnsAccount(c *gin.Context) { return } if _, err := websiteDnsAccountService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -68,7 +67,7 @@ func (b *BaseApi) UpdateWebsiteDnsAccount(c *gin.Context) { return } if _, err := websiteDnsAccountService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -89,7 +88,7 @@ func (b *BaseApi) DeleteWebsiteDnsAccount(c *gin.Context) { return } if err := websiteDnsAccountService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/agent/app/api/v2/website_domain.go b/agent/app/api/v2/website_domain.go index 769a85b7e..7d08e32ff 100644 --- a/agent/app/api/v2/website_domain.go +++ b/agent/app/api/v2/website_domain.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -22,7 +21,7 @@ func (b *BaseApi) DeleteWebDomain(c *gin.Context) { return } if err := websiteService.DeleteWebsiteDomain(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -44,7 +43,7 @@ func (b *BaseApi) CreateWebDomain(c *gin.Context) { } domain, err := websiteService.CreateWebsiteDomain(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, domain) @@ -61,12 +60,12 @@ func (b *BaseApi) CreateWebDomain(c *gin.Context) { func (b *BaseApi) GetWebDomains(c *gin.Context) { websiteId, err := helper.GetIntParamByKey(c, "websiteId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + helper.BadRequest(c, err) return } list, err := websiteService.GetWebsiteDomain(websiteId) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -88,7 +87,7 @@ func (b *BaseApi) UpdateWebDomain(c *gin.Context) { return } if err := websiteService.UpdateWebsiteDomain(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) diff --git a/agent/app/api/v2/website_ssl.go b/agent/app/api/v2/website_ssl.go index 4d41b413a..ca08d361a 100644 --- a/agent/app/api/v2/website_ssl.go +++ b/agent/app/api/v2/website_ssl.go @@ -9,7 +9,6 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/gin-gonic/gin" ) @@ -29,7 +28,7 @@ func (b *BaseApi) PageWebsiteSSL(c *gin.Context) { if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) { total, accounts, err := websiteSSLService.Page(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, dto.PageResult{ @@ -39,7 +38,7 @@ func (b *BaseApi) PageWebsiteSSL(c *gin.Context) { } else { list, err := websiteSSLService.Search(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -62,7 +61,7 @@ func (b *BaseApi) CreateWebsiteSSL(c *gin.Context) { } res, err := websiteSSLService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -83,7 +82,7 @@ func (b *BaseApi) ApplyWebsiteSSL(c *gin.Context) { return } if err := websiteSSLService.ObtainSSL(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithOutData(c) @@ -104,7 +103,7 @@ func (b *BaseApi) GetDNSResolve(c *gin.Context) { } res, err := websiteSSLService.GetDNSResolve(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, res) @@ -125,7 +124,7 @@ func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) { return } if err := websiteSSLService.Delete(req.IDs); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -142,12 +141,12 @@ func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) { func (b *BaseApi) GetWebsiteSSLByWebsiteId(c *gin.Context) { websiteId, err := helper.GetIntParamByKey(c, "websiteId") if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } websiteSSL, err := websiteSSLService.GetWebsiteSSL(websiteId) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, websiteSSL) @@ -164,12 +163,12 @@ func (b *BaseApi) GetWebsiteSSLByWebsiteId(c *gin.Context) { func (b *BaseApi) GetWebsiteSSLById(c *gin.Context) { id, err := helper.GetParamID(c) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } websiteSSL, err := websiteSSLService.GetSSL(id) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, websiteSSL) @@ -190,7 +189,7 @@ func (b *BaseApi) UpdateWebsiteSSL(c *gin.Context) { return } if err := websiteSSLService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -211,7 +210,7 @@ func (b *BaseApi) UploadWebsiteSSL(c *gin.Context) { return } if err := websiteSSLService.Upload(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -233,13 +232,13 @@ func (b *BaseApi) DownloadWebsiteSSL(c *gin.Context) { } file, err := websiteSSLService.DownloadFile(req.ID) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } defer file.Close() info, err := file.Stat() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } c.Header("Content-Length", strconv.FormatInt(info.Size(), 10)) diff --git a/agent/app/service/runtime.go b/agent/app/service/runtime.go index f143dae32..1529759df 100644 --- a/agent/app/service/runtime.go +++ b/agent/app/service/runtime.go @@ -103,8 +103,10 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e return nil, buserr.New(constant.ErrImageExist) } portValue, _ := create.Params["PANEL_APP_PORT_HTTP"] - if err := checkPortExist(int(portValue.(float64))); err != nil { - return nil, err + if portValue != nil { + if err := checkPortExist(int(portValue.(float64))); err != nil { + return nil, err + } } case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython: if !fileOp.Stat(create.CodeDir) { @@ -747,6 +749,9 @@ func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq) defer client.Close() if err == nil { oldImageID, err := client.GetImageIDByName(runtime.Image) + if err != nil { + return err + } commitCmd := fmt.Sprintf("docker commit %s %s", runtime.ContainerName, runtime.Image) err = cmd2.ExecWithLogFile(commitCmd, 15*time.Minute, t.Task.LogFile) if err != nil { diff --git a/agent/app/service/runtime_utils.go b/agent/app/service/runtime_utils.go index ddd4f646b..72cb20739 100644 --- a/agent/app/service/runtime_utils.go +++ b/agent/app/service/runtime_utils.go @@ -207,33 +207,6 @@ func getRuntimeEnv(envStr, key string) string { return "" } -func getRuntimeEnvironments(composeByte []byte) ([]request.Environment, error) { - var environments []request.Environment - var composeMap map[string]interface{} - if err := yaml.Unmarshal(composeByte, &composeMap); err != nil { - return nil, err - } - services, ok := composeMap["services"].(map[string]interface{}) - if !ok { - return nil, buserr.New(constant.ErrFileParse) - } - for _, service := range services { - envs, ok := service.(map[string]interface{})["environment"].([]interface{}) - if !ok { - continue - } - for _, env := range envs { - envStr := env.(string) - envArray := strings.Split(envStr, "=") - environments = append(environments, request.Environment{ - Key: envArray[0], - Value: envArray[1], - }) - } - } - return environments, nil -} - func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebuild bool) { runtimePath := runtime.GetPath() composePath := runtime.GetComposePath() diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 15be3f03a..b512aad95 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1673,10 +1673,12 @@ func (w WebsiteService) GetProxyCache(id uint) (res response.NginxProxyCache, er if len(params) == 0 { return } + zoneRegexp := regexp.MustCompile(`keys_zone=proxy_cache_zone_of_[\w.]+:(\d+)([kmgt]?)`) + sizeRegexp := regexp.MustCompile(`max_size=([0-9.]+)([kmgt]?)`) + inactiveRegexp := regexp.MustCompile(`inactive=(\d+)([smhd])`) for _, param := range params { if match, _ := regexp.MatchString(`keys_zone=proxy_cache_zone_of_[\w.]+:\d+[kmgt]?`, param); match { - r := regexp.MustCompile(`keys_zone=proxy_cache_zone_of_[\w.]+:(\d+)([kmgt]?)`) - matches := r.FindStringSubmatch(param) + matches := zoneRegexp.FindStringSubmatch(param) if len(matches) > 0 { res.ShareCache, _ = strconv.Atoi(matches[1]) res.ShareCacheUnit = matches[2] @@ -1684,16 +1686,14 @@ func (w WebsiteService) GetProxyCache(id uint) (res response.NginxProxyCache, er } if match, _ := regexp.MatchString(`max_size=\d+(\.\d+)?[kmgt]?`, param); match { - r := regexp.MustCompile(`max_size=([0-9.]+)([kmgt]?)`) - matches := r.FindStringSubmatch(param) + matches := sizeRegexp.FindStringSubmatch(param) if len(matches) > 0 { res.CacheLimit, _ = strconv.ParseFloat(matches[1], 64) res.CacheLimitUnit = matches[2] } } if match, _ := regexp.MatchString(`inactive=\d+[smhd]`, param); match { - r := regexp.MustCompile(`inactive=(\d+)([smhd])`) - matches := r.FindStringSubmatch(param) + matches := inactiveRegexp.FindStringSubmatch(param) if len(matches) > 0 { res.CacheExpire, _ = strconv.Atoi(matches[1]) res.CacheExpireUnit = matches[2] diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go index 0b78900b5..e51432b50 100644 --- a/agent/app/service/website_utils.go +++ b/agent/app/service/website_utils.go @@ -13,15 +13,13 @@ import ( "github.com/1Panel-dev/1Panel/agent/utils/xpack" + "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/i18n" "github.com/1Panel-dev/1Panel/agent/utils/cmd" "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/nginx/components" - "gopkg.in/yaml.v3" - - "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" @@ -934,35 +932,6 @@ func chownRootDir(path string) error { return nil } -func changeServiceName(newComposeContent, newServiceName string) (composeByte []byte, err error) { - composeMap := make(map[string]interface{}) - if err = yaml.Unmarshal([]byte(newComposeContent), &composeMap); err != nil { - return - } - value, ok := composeMap["services"] - if !ok || value == nil { - err = buserr.New(constant.ErrFileParse) - return - } - servicesMap := value.(map[string]interface{}) - - index := 0 - serviceName := "" - for k := range servicesMap { - serviceName = k - if index > 0 { - continue - } - index++ - } - if newServiceName != serviceName { - servicesMap[newServiceName] = servicesMap[serviceName] - delete(servicesMap, serviceName) - } - - return yaml.Marshal(composeMap) -} - func getWebsiteDomains(domains []request.WebsiteDomain, defaultPort int, websiteID uint) (domainModels []model.WebsiteDomain, addPorts []int, addDomains []string, err error) { var ( ports = make(map[int]struct{}) diff --git a/core/app/api/v2/auth.go b/core/app/api/v2/auth.go index 8536749bc..1ebc86022 100644 --- a/core/app/api/v2/auth.go +++ b/core/app/api/v2/auth.go @@ -32,7 +32,7 @@ func (b *BaseApi) Login(c *gin.Context) { if req.AuthMethod != "jwt" && !req.IgnoreCaptcha { if err := captcha.VerifyCode(req.CaptchaID, req.Captcha); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } } @@ -45,7 +45,7 @@ func (b *BaseApi) Login(c *gin.Context) { user, err := authService.Login(c, req, string(entrance)) go saveLoginLogs(c, err) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, user) @@ -73,7 +73,7 @@ func (b *BaseApi) MFALogin(c *gin.Context) { user, err := authService.MFALogin(c, req, string(entrance)) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, user) @@ -87,7 +87,7 @@ func (b *BaseApi) MFALogin(c *gin.Context) { // @Router /core/auth/logout [post] func (b *BaseApi) LogOut(c *gin.Context) { if err := authService.LogOut(c); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -101,7 +101,7 @@ func (b *BaseApi) LogOut(c *gin.Context) { func (b *BaseApi) Captcha(c *gin.Context) { captcha, err := captcha.CreateCaptcha() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, captcha) @@ -116,7 +116,7 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) { code := c.DefaultQuery("code", "") status, err := authService.CheckIsSafety(code) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } if status == "disable" && len(code) != 0 { @@ -137,7 +137,7 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) { func (b *BaseApi) GetResponsePage(c *gin.Context) { pageCode, err := authService.GetResponsePage() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, pageCode) @@ -160,7 +160,7 @@ func (b *BaseApi) CheckIsDemo(c *gin.Context) { func (b *BaseApi) GetLanguage(c *gin.Context) { settingInfo, err := settingService.GetSettingInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, settingInfo.Language) diff --git a/core/app/api/v2/backup.go b/core/app/api/v2/backup.go index 29a75c259..11e286baa 100644 --- a/core/app/api/v2/backup.go +++ b/core/app/api/v2/backup.go @@ -3,7 +3,6 @@ package v2 import ( "github.com/1Panel-dev/1Panel/core/app/api/v2/helper" "github.com/1Panel-dev/1Panel/core/app/dto" - "github.com/1Panel-dev/1Panel/core/constant" "github.com/gin-gonic/gin" ) @@ -23,7 +22,7 @@ func (b *BaseApi) CreateBackup(c *gin.Context) { } if err := backupService.Create(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -56,7 +55,7 @@ func (b *BaseApi) ListBuckets(c *gin.Context) { buckets, err := backupService.GetBuckets(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, buckets) @@ -72,7 +71,7 @@ func (b *BaseApi) ListBuckets(c *gin.Context) { func (b *BaseApi) LoadOneDriveInfo(c *gin.Context) { data, err := backupService.LoadOneDriveInfo() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, data) @@ -88,7 +87,7 @@ func (b *BaseApi) LoadOneDriveInfo(c *gin.Context) { func (b *BaseApi) LoadBackupOptions(c *gin.Context) { list, err := backupService.LoadBackupOptions() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, list) @@ -110,7 +109,7 @@ func (b *BaseApi) DeleteBackup(c *gin.Context) { } if err := backupService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -132,7 +131,7 @@ func (b *BaseApi) UpdateBackup(c *gin.Context) { } if err := backupService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -154,7 +153,7 @@ func (b *BaseApi) SearchBackup(c *gin.Context) { total, list, err := backupService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -173,7 +172,7 @@ func (b *BaseApi) SearchBackup(c *gin.Context) { func (b *BaseApi) GetLocalDir(c *gin.Context) { dir, err := backupService.GetLocalDir() if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/core/app/api/v2/command.go b/core/app/api/v2/command.go index 54c1b848e..e8956dd62 100644 --- a/core/app/api/v2/command.go +++ b/core/app/api/v2/command.go @@ -45,7 +45,7 @@ func (b *BaseApi) SearchCommand(c *gin.Context) { total, list, err := commandService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -71,7 +71,7 @@ func (b *BaseApi) SearchCommandTree(c *gin.Context) { list, err := commandService.SearchForTree(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -94,7 +94,7 @@ func (b *BaseApi) ListCommand(c *gin.Context) { list, err := commandService.List(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -117,7 +117,7 @@ func (b *BaseApi) DeleteCommand(c *gin.Context) { } if err := commandService.Delete(req.IDs); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -143,7 +143,7 @@ func (b *BaseApi) UpdateCommand(c *gin.Context) { upMap["group_id"] = req.GroupID upMap["command"] = req.Command if err := commandService.Update(req.ID, upMap); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/core/app/api/v2/group.go b/core/app/api/v2/group.go index ef6a56f4f..80940e8b0 100644 --- a/core/app/api/v2/group.go +++ b/core/app/api/v2/group.go @@ -45,7 +45,7 @@ func (b *BaseApi) DeleteGroup(c *gin.Context) { } if err := groupService.Delete(req.ID); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -67,7 +67,7 @@ func (b *BaseApi) UpdateGroup(c *gin.Context) { } if err := groupService.Update(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -89,7 +89,7 @@ func (b *BaseApi) ListGroup(c *gin.Context) { list, err := groupService.List(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/core/app/api/v2/helper/helper.go b/core/app/api/v2/helper/helper.go index 5e6bf7e8b..994f4b241 100644 --- a/core/app/api/v2/helper/helper.go +++ b/core/app/api/v2/helper/helper.go @@ -47,6 +47,14 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) { ctx.Abort() } +func InternalServer(ctx *gin.Context, err error) { + ErrorWithDetail(ctx, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) +} + +func BadRequest(ctx *gin.Context, err error) { + ErrorWithDetail(ctx, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) +} + func SuccessWithData(ctx *gin.Context, data interface{}) { if data == nil { data = gin.H{} diff --git a/core/app/api/v2/host.go b/core/app/api/v2/host.go index f5ed73055..e62599811 100644 --- a/core/app/api/v2/host.go +++ b/core/app/api/v2/host.go @@ -37,7 +37,7 @@ func (b *BaseApi) CreateHost(c *gin.Context) { host, err := hostService.Create(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, host) @@ -77,7 +77,7 @@ func (b *BaseApi) TestByID(c *gin.Context) { } intNum, err := strconv.Atoi(idParam) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } @@ -101,7 +101,7 @@ func (b *BaseApi) HostTree(c *gin.Context) { data, err := hostService.SearchForTree(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -124,7 +124,7 @@ func (b *BaseApi) SearchHost(c *gin.Context) { total, list, err := hostService.SearchWithPage(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -150,7 +150,7 @@ func (b *BaseApi) DeleteHost(c *gin.Context) { } if err := hostService.Delete(req.IDs); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -175,7 +175,7 @@ func (b *BaseApi) UpdateHost(c *gin.Context) { if len(req.Password) != 0 && req.AuthMode == "password" { req.Password, err = hostService.EncryptHost(req.Password) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.PrivateKey = "" @@ -184,13 +184,13 @@ func (b *BaseApi) UpdateHost(c *gin.Context) { if len(req.PrivateKey) != 0 && req.AuthMode == "key" { req.PrivateKey, err = hostService.EncryptHost(req.PrivateKey) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } if len(req.PassPhrase) != 0 { req.PassPhrase, err = encrypt.StringEncrypt(req.PassPhrase) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } } @@ -216,7 +216,7 @@ func (b *BaseApi) UpdateHost(c *gin.Context) { } upMap["description"] = req.Description if err := hostService.Update(req.ID, upMap); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) @@ -240,7 +240,7 @@ func (b *BaseApi) UpdateHostGroup(c *gin.Context) { upMap := make(map[string]interface{}) upMap["group_id"] = req.GroupID if err := hostService.Update(req.ID, upMap); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/core/app/api/v2/logs.go b/core/app/api/v2/logs.go index 7b560e24e..86282d513 100644 --- a/core/app/api/v2/logs.go +++ b/core/app/api/v2/logs.go @@ -49,7 +49,7 @@ func (b *BaseApi) GetOperationLogs(c *gin.Context) { total, list, err := logService.PageOperationLog(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } @@ -75,7 +75,7 @@ func (b *BaseApi) CleanLogs(c *gin.Context) { } if err := logService.CleanLogs(req.LogType); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } diff --git a/core/app/api/v2/setting.go b/core/app/api/v2/setting.go index a3b8c09db..ec138b137 100644 --- a/core/app/api/v2/setting.go +++ b/core/app/api/v2/setting.go @@ -116,7 +116,7 @@ func (b *BaseApi) UpdateProxy(c *gin.Context) { if len(req.ProxyPasswd) != 0 && len(req.ProxyType) != 0 { pass, err := base64.StdEncoding.DecodeString(req.ProxyPasswd) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + helper.BadRequest(c, err) return } req.ProxyPasswd = string(pass) diff --git a/core/app/api/v2/upgrade.go b/core/app/api/v2/upgrade.go index 90da70b90..17802aac8 100644 --- a/core/app/api/v2/upgrade.go +++ b/core/app/api/v2/upgrade.go @@ -38,7 +38,7 @@ func (b *BaseApi) GetNotesByVersion(c *gin.Context) { notes, err := upgradeService.LoadNotes(req) if err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, notes) @@ -60,7 +60,7 @@ func (b *BaseApi) Upgrade(c *gin.Context) { } if err := upgradeService.Upgrade(req); err != nil { - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + helper.InternalServer(c, err) return } helper.SuccessWithData(c, nil) diff --git a/frontend/src/components/layout-content/index.vue b/frontend/src/components/layout-content/index.vue index 6507ed4ac..656c94b46 100644 --- a/frontend/src/components/layout-content/index.vue +++ b/frontend/src/components/layout-content/index.vue @@ -41,8 +41,8 @@