31 lines
675 B
Go
31 lines
675 B
Go
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
|
|
}
|
|
})
|
|
|
|
api.GET("/:name", func(c *gin.Context) {
|
|
name := c.Param("name")
|
|
path := filepath.Join(cfg.ImagePath, name)
|
|
|
|
c.File(path)
|
|
})
|
|
}
|