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

+18 -24
View File
@@ -12,6 +12,7 @@ import (
"time"
"server/models"
"server/pkg/identity"
"server/pkg/jwtutil"
"github.com/beego/beego/v2/client/orm"
@@ -74,22 +75,7 @@ func (c *PlatformAgentApiController) ok(msg string, data interface{}) {
}
func (c *PlatformAgentApiController) 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)
}
// agentApiPayload 新增/更新请求体
@@ -338,7 +324,8 @@ func buildAgentEndpoint(protocol, base, model, apiKey string) string {
// List GET /platform/agentApi/list?page=1&pageSize=24&keyword=&provider=&status=
func (c *PlatformAgentApiController) List() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -415,7 +402,8 @@ func (c *PlatformAgentApiController) List() {
// Detail GET /platform/agentApi/:id
func (c *PlatformAgentApiController) Detail() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -455,7 +443,8 @@ func (c *PlatformAgentApiController) findByID() (*models.PlatformAgentApi, error
func (c *PlatformAgentApiController) Create() {
claims, err := c.platformClaims()
if err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -510,7 +499,8 @@ func (c *PlatformAgentApiController) Create() {
// Update PUT /platform/agentApi/:id
func (c *PlatformAgentApiController) Update() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -569,7 +559,8 @@ func (c *PlatformAgentApiController) Update() {
// Delete DELETE /platform/agentApi/:id
func (c *PlatformAgentApiController) Delete() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -596,7 +587,8 @@ func (c *PlatformAgentApiController) Delete() {
// BatchDelete POST /platform/agentApi/batchDelete
func (c *PlatformAgentApiController) BatchDelete() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -637,7 +629,8 @@ func (c *PlatformAgentApiController) BatchDelete() {
// ToggleStatus POST /platform/agentApi/:id/status
func (c *PlatformAgentApiController) ToggleStatus() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
@@ -707,7 +700,8 @@ func redactKeyInURL(rawURL, key string) string {
// key_index 指定用密钥列表中的第几个密钥,缺省用第一个
func (c *PlatformAgentApiController) Test() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}