This commit is contained in:
hero920103 committed 2026-10-19 01:13:17 +08:00
1 parent 5718a00e31
commit 1850ac640e
226 files changed
+37772 -12071

No files matched your search

+12 -22
View File
@@ -2,13 +2,13 @@ package controllers
import (
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"time"
"server/models"
"server/pkg/identity"
"server/pkg/jwtutil"
"server/services"
@@ -21,22 +21,7 @@ type PlatformSoftwareUpgradeController struct {
}
func (c *PlatformSoftwareUpgradeController) platformClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("认证信息格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("无效的token")
}
if claims.UserType != "platform" {
return nil, fmt.Errorf("无权访问")
}
return claims, nil
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndPlatform)
}
func (c *PlatformSoftwareUpgradeController) jsonErr(httpStatus, bizCode int, msg string) {
@@ -101,7 +86,8 @@ func (c *PlatformSoftwareUpgradeController) rowToMap(row *models.SystemSoftwareU
// List GET /platform/softwareupgrade/list
func (c *PlatformSoftwareUpgradeController) List() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
page, _ := c.GetInt("page", 1)
@@ -140,7 +126,8 @@ func (c *PlatformSoftwareUpgradeController) List() {
// Detail GET /platform/softwareupgrade/:id
func (c *PlatformSoftwareUpgradeController) Detail() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
@@ -176,7 +163,8 @@ type softwareUpgradePayload struct {
// Create POST /platform/softwareupgrade
func (c *PlatformSoftwareUpgradeController) Create() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
body, _ := io.ReadAll(c.Ctx.Request.Body)
@@ -239,7 +227,8 @@ func (c *PlatformSoftwareUpgradeController) Create() {
// Update POST /platform/softwareupgrade/:id
func (c *PlatformSoftwareUpgradeController) Update() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
@@ -324,7 +313,8 @@ func (c *PlatformSoftwareUpgradeController) Update() {
// Delete DELETE /platform/softwareupgrade/:id
func (c *PlatformSoftwareUpgradeController) Delete() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)