更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services"
|
||||
|
||||
@@ -44,22 +45,7 @@ var platformAllowedExtByCategory = map[string][]string{
|
||||
}
|
||||
|
||||
func (c *PlatformFileController) 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 *PlatformFileController) effectiveTid(claims *jwtutil.Claims) uint64 {
|
||||
@@ -151,7 +137,8 @@ func platformRemovePhysicalBySrc(webSrc string) {
|
||||
func (c *PlatformFileController) GetAllFiles() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -203,7 +190,8 @@ func (c *PlatformFileController) GetAllFiles() {
|
||||
func (c *PlatformFileController) GetUserCate() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -244,7 +232,8 @@ type platformCreateCateBody struct {
|
||||
func (c *PlatformFileController) CreateFileCate() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -319,7 +308,8 @@ func isProtectedFileCate(name string) bool {
|
||||
func (c *PlatformFileController) RenameFileCate() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -381,7 +371,8 @@ func (c *PlatformFileController) RenameFileCate() {
|
||||
func (c *PlatformFileController) DeleteFileCate() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -441,7 +432,8 @@ func (c *PlatformFileController) DeleteFileCate() {
|
||||
func (c *PlatformFileController) GetCateFiles() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -497,7 +489,8 @@ func (c *PlatformFileController) GetCateFiles() {
|
||||
func (c *PlatformFileController) GetFileByID() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -524,7 +517,8 @@ func (c *PlatformFileController) GetFileByID() {
|
||||
func (c *PlatformFileController) UploadFile() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
if err := c.Ctx.Request.ParseMultipartForm(platformFileUploadMaxBytes); err != nil {
|
||||
@@ -665,7 +659,8 @@ type platformUpdateFileBody struct {
|
||||
func (c *PlatformFileController) UpdateFile() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -719,7 +714,8 @@ func (c *PlatformFileController) UpdateFile() {
|
||||
func (c *PlatformFileController) DeleteFile() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -751,7 +747,8 @@ func (c *PlatformFileController) DeleteFile() {
|
||||
func (c *PlatformFileController) DeleteFilePermanently() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -789,7 +786,8 @@ func (c *PlatformFileController) DeleteFilePermanently() {
|
||||
func (c *PlatformFileController) MoveFile() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -827,7 +825,8 @@ type platformIdsBody struct {
|
||||
func (c *PlatformFileController) BatchDeleteFiles() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -867,7 +866,8 @@ func (c *PlatformFileController) BatchDeleteFiles() {
|
||||
func (c *PlatformFileController) BatchDeleteFilesPermanently() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
@@ -931,7 +931,8 @@ func (c *PlatformFileController) UpdateAvatar() {
|
||||
func (c *PlatformFileController) BatchMoveFiles() {
|
||||
claims, err := c.platformClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
tid := c.effectiveTid(claims)
|
||||
|
||||
Reference in new issue
Block a user