feat: upload route

This commit is contained in:
grngxd 2025-05-05 14:43:21 +01:00
parent f2e666874d
commit aad953f0b5
5 changed files with 79 additions and 15 deletions

View file

@ -8,5 +8,5 @@ import (
func Register(cfg *types.StereoConfig) {
api := cfg.Router.Group("/api")
routes.RegisterPingRoutes(api)
routes.RegisterUploadRoutes(cfg, api)
}

View file

@ -1,13 +0,0 @@
package routes
import (
"net/http"
"github.com/gin-gonic/gin"
)
func RegisterPingRoutes(api *gin.RouterGroup) {
api.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "Pong!")
})
}

View file

@ -0,0 +1,24 @@
package routes
import (
"path/filepath"
"github.com/gin-gonic/gin"
"stereo.cat/backend/internal/types"
)
func RegisterUploadRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
api.POST("/upload", func(c *gin.Context) {
file, err := c.FormFile("file")
if err != nil {
c.JSON(400, gin.H{"error": "file is required"})
return
}
filePath := filepath.Join(cfg.ImagePath, file.Filename)
if err := c.SaveUploadedFile(file, filePath); err != nil {
c.JSON(500, gin.H{"error": "failed to save file"})
return
}
})
}