skibidi
This commit is contained in:
parent
93aec1336d
commit
e16a4eae26
3 changed files with 16 additions and 3 deletions
|
@ -7,6 +7,6 @@ import (
|
|||
|
||||
func Register(cfg *types.StereoConfig) {
|
||||
api := cfg.Router.Group("/api")
|
||||
routes.RegisterUploadRoutes(cfg, api)
|
||||
routes.RegisterFileRoutes(cfg, api)
|
||||
routes.RegisterAuthRoutes(cfg, api)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"stereo.cat/backend/internal/types"
|
||||
)
|
||||
|
||||
func RegisterUploadRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||
func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||
api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
@ -60,4 +60,17 @@ func RegisterUploadRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
path := filepath.Join(cfg.ImagePath, name)
|
||||
c.File(path)
|
||||
})
|
||||
|
||||
api.GET("/list", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||
user := claims["user"].(auth.User)
|
||||
|
||||
var files []types.File
|
||||
if err := cfg.Database.Where("owner = ?", user.ID).Find(&files).Error; err != nil {
|
||||
c.JSON(500, gin.H{"error": "failed to retrieve files"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, files)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue