2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

fix: 修正部分接口未跟随更新状态码

This commit is contained in:
耗子
2024-03-06 03:42:15 +08:00
parent d3e758f61a
commit 5dcfe4126c
6 changed files with 18 additions and 46 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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",

View File

@@ -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",

View File

@@ -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