Skip to content

Commit

Permalink
fix: 修正部分接口未跟随更新状态码
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Mar 5, 2024
1 parent d3e758f commit 5dcfe41
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 46 deletions.
9 changes: 3 additions & 6 deletions app/http/middleware/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,17 +25,15 @@ 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
}

token = "Bearer " + token
} else {
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
"code": 401,
ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{
"message": "登录已过期",
})
return
Expand Down
15 changes: 5 additions & 10 deletions app/http/middleware/must_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions app/http/middleware/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2533,9 +2533,6 @@ const docTemplate = `{
"controllers.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
Expand All @@ -2544,9 +2541,6 @@ const docTemplate = `{
"controllers.SuccessResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"data": {},
"message": {
"type": "string"
Expand Down Expand Up @@ -2595,7 +2589,7 @@ const docTemplate = `{
"type": "string"
},
"php": {
"type": "integer"
"type": "string"
},
"ports": {
"type": "array",
Expand Down Expand Up @@ -2854,7 +2848,7 @@ const docTemplate = `{
"type": "string"
},
"php": {
"type": "integer"
"type": "string"
},
"ports": {
"type": "array",
Expand Down
10 changes: 2 additions & 8 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2526,9 +2526,6 @@
"controllers.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
Expand All @@ -2537,9 +2534,6 @@
"controllers.SuccessResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"data": {},
"message": {
"type": "string"
Expand Down Expand Up @@ -2588,7 +2582,7 @@
"type": "string"
},
"php": {
"type": "integer"
"type": "string"
},
"ports": {
"type": "array",
Expand Down Expand Up @@ -2847,7 +2841,7 @@
"type": "string"
},
"php": {
"type": "integer"
"type": "string"
},
"ports": {
"type": "array",
Expand Down
8 changes: 2 additions & 6 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,7 +63,7 @@ definitions:
path:
type: string
php:
type: integer
type: string
ports:
items:
type: integer
Expand Down Expand Up @@ -241,7 +237,7 @@ definitions:
path:
type: string
php:
type: integer
type: string
ports:
items:
type: integer
Expand Down

0 comments on commit 5dcfe41

Please sign in to comment.