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) {
|
func Register(cfg *types.StereoConfig) {
|
||||||
api := cfg.Router.Group("/api")
|
api := cfg.Router.Group("/api")
|
||||||
routes.RegisterUploadRoutes(cfg, api)
|
routes.RegisterFileRoutes(cfg, api)
|
||||||
routes.RegisterAuthRoutes(cfg, api)
|
routes.RegisterAuthRoutes(cfg, api)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"stereo.cat/backend/internal/types"
|
"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) {
|
api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) {
|
||||||
claims := c.MustGet("claims").(jwt.MapClaims)
|
claims := c.MustGet("claims").(jwt.MapClaims)
|
||||||
user := claims["user"].(auth.User)
|
user := claims["user"].(auth.User)
|
||||||
|
@ -60,4 +60,17 @@ func RegisterUploadRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
path := filepath.Join(cfg.ImagePath, name)
|
path := filepath.Join(cfg.ImagePath, name)
|
||||||
c.File(path)
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
2
main.go
2
main.go
|
@ -86,6 +86,6 @@ func main() {
|
||||||
c.Database.AutoMigrate(&auth.User{}, &types.File{})
|
c.Database.AutoMigrate(&auth.User{}, &types.File{})
|
||||||
|
|
||||||
api.Register(&c)
|
api.Register(&c)
|
||||||
|
fmt.Printf("Running on port %s\n", getEnv("PORT", "8080"))
|
||||||
c.Router.Run()
|
c.Router.Run()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue