From 5dcfe4126cabc8eba1019eb67abc482117cc4487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Wed, 6 Mar 2024 03:42:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=9C=AA=E8=B7=9F=E9=9A=8F=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/middleware/jwt.go | 9 +++------ app/http/middleware/must_install.go | 15 +++++---------- app/http/middleware/status.go | 12 ++++-------- docs/docs.go | 10 ++-------- docs/swagger.json | 10 ++-------- docs/swagger.yaml | 8 ++------ 6 files changed, 18 insertions(+), 46 deletions(-) diff --git a/app/http/middleware/jwt.go b/app/http/middleware/jwt.go index 3d1bd4e490..b862271c48 100644 --- a/app/http/middleware/jwt.go +++ b/app/http/middleware/jwt.go @@ -13,8 +13,7 @@ func Jwt() http.Middleware { return func(ctx http.Context) { token := ctx.Request().Header("Authorization", ctx.Request().Header("Sec-WebSocket-Protocol")) if len(token) == 0 { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 401, + ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ "message": "未登录", }) return @@ -26,8 +25,7 @@ func Jwt() http.Middleware { token, err = facades.Auth(ctx).Refresh() if err != nil { // 到达刷新时间上限 - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 401, + ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ "message": "登录已过期", }) return @@ -35,8 +33,7 @@ func Jwt() http.Middleware { token = "Bearer " + token } else { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 401, + ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ "message": "登录已过期", }) return diff --git a/app/http/middleware/must_install.go b/app/http/middleware/must_install.go index eb626dd56a..6c2b4a9550 100644 --- a/app/http/middleware/must_install.go +++ b/app/http/middleware/must_install.go @@ -18,8 +18,7 @@ func MustInstall() http.Middleware { } else { pathArr := strings.Split(path, "/") if len(pathArr) < 4 { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": http.StatusForbidden, + ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ "message": "插件不存在", }) return @@ -31,16 +30,14 @@ func MustInstall() http.Middleware { installedPlugin := services.NewPluginImpl().GetInstalledBySlug(slug) installedPlugins, err := services.NewPluginImpl().AllInstalled() if err != nil { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": http.StatusInternalServerError, + ctx.Request().AbortWithStatusJson(http.StatusInternalServerError, http.Json{ "message": "系统内部错误", }) return } if installedPlugin.Version != plugin.Version || installedPlugin.Slug != plugin.Slug { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": http.StatusForbidden, + ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ "message": "插件 " + slug + " 需要更新至 " + plugin.Version + " 版本", }) return @@ -55,8 +52,7 @@ func MustInstall() http.Middleware { for _, require := range plugin.Requires { _, requireFound := pluginsMap[require] if !requireFound { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": http.StatusForbidden, + ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ "message": "插件 " + slug + " 需要依赖 " + require + " 插件", }) return @@ -66,8 +62,7 @@ func MustInstall() http.Middleware { for _, exclude := range plugin.Excludes { _, excludeFound := pluginsMap[exclude] if excludeFound { - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": http.StatusForbidden, + ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ "message": "插件 " + slug + " 不兼容 " + exclude + " 插件", }) return diff --git a/app/http/middleware/status.go b/app/http/middleware/status.go index ef67d4656b..c9525c1ae7 100644 --- a/app/http/middleware/status.go +++ b/app/http/middleware/status.go @@ -11,26 +11,22 @@ func Status() http.Middleware { return func(ctx http.Context) { switch internal.Status { case internal.StatusUpgrade: - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 503, + ctx.Request().AbortWithStatusJson(http.StatusServiceUnavailable, http.Json{ "message": "面板升级中,请稍后", }) return case internal.StatusMaintain: - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 503, + ctx.Request().AbortWithStatusJson(http.StatusServiceUnavailable, http.Json{ "message": "面板正在运行维护,请稍后", }) return case internal.StatusClosed: - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 403, + ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ "message": "面板已关闭", }) return case internal.StatusFailed: - ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ - "code": 500, + ctx.Request().AbortWithStatusJson(http.StatusInternalServerError, http.Json{ "message": "面板运行出错,请检查排除或联系支持", }) return diff --git a/docs/docs.go b/docs/docs.go index 2ddd09ead8..e18747fa46 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2533,9 +2533,6 @@ const docTemplate = `{ "controllers.ErrorResponse": { "type": "object", "properties": { - "code": { - "type": "integer" - }, "message": { "type": "string" } @@ -2544,9 +2541,6 @@ const docTemplate = `{ "controllers.SuccessResponse": { "type": "object", "properties": { - "code": { - "type": "integer" - }, "data": {}, "message": { "type": "string" @@ -2595,7 +2589,7 @@ const docTemplate = `{ "type": "string" }, "php": { - "type": "integer" + "type": "string" }, "ports": { "type": "array", @@ -2854,7 +2848,7 @@ const docTemplate = `{ "type": "string" }, "php": { - "type": "integer" + "type": "string" }, "ports": { "type": "array", diff --git a/docs/swagger.json b/docs/swagger.json index 921092e5b1..ec8828ec14 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2526,9 +2526,6 @@ "controllers.ErrorResponse": { "type": "object", "properties": { - "code": { - "type": "integer" - }, "message": { "type": "string" } @@ -2537,9 +2534,6 @@ "controllers.SuccessResponse": { "type": "object", "properties": { - "code": { - "type": "integer" - }, "data": {}, "message": { "type": "string" @@ -2588,7 +2582,7 @@ "type": "string" }, "php": { - "type": "integer" + "type": "string" }, "ports": { "type": "array", @@ -2847,7 +2841,7 @@ "type": "string" }, "php": { - "type": "integer" + "type": "string" }, "ports": { "type": "array", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 44bb232ca1..d7591b26e1 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -26,15 +26,11 @@ definitions: type: object controllers.ErrorResponse: properties: - code: - type: integer message: type: string type: object controllers.SuccessResponse: properties: - code: - type: integer data: {} message: type: string @@ -67,7 +63,7 @@ definitions: path: type: string php: - type: integer + type: string ports: items: type: integer @@ -241,7 +237,7 @@ definitions: path: type: string php: - type: integer + type: string ports: items: type: integer