some cleaning up
This commit is contained in:
parent
e3049dddd9
commit
a6a02d3521
4 changed files with 25 additions and 27 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/h2non/filetype"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"stereo.cat/backend/internal/auth"
|
||||
"stereo.cat/backend/internal/auth/token"
|
||||
"stereo.cat/backend/internal/types"
|
||||
)
|
||||
|
||||
|
@ -20,7 +21,7 @@ func intoReader(buf []byte) io.Reader {
|
|||
}
|
||||
|
||||
func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||
api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
api.POST("/upload", token.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
||||
|
@ -88,7 +89,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
c.JSON(200, gin.H{"message": "file uploaded successfully", "id": fileMeta.ID.String()})
|
||||
})
|
||||
|
||||
api.DELETE("/:id", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
api.DELETE("/:id", token.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
||||
|
@ -100,15 +101,10 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
|
||||
var file *types.File
|
||||
|
||||
cfg.Database.First(&file, fileID)
|
||||
err = cfg.Database.First(&file, fileID).Error
|
||||
|
||||
if file == nil {
|
||||
err := cfg.Database.Delete(&file).Error
|
||||
if err != nil {
|
||||
types.ErrorDatabase.Throw(c, err)
|
||||
return
|
||||
}
|
||||
types.ErrorFileNotFound.Throw(c, nil)
|
||||
if err != nil {
|
||||
types.ErrorFileNotFound.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -162,7 +158,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
c.DataFromReader(200, file.Size, file.Mime, object, nil)
|
||||
})
|
||||
|
||||
api.GET("/list", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
api.GET("/list", token.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue