auth-uploads #5
1 changed files with 12 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -63,7 +64,17 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
|
|
||||||
api.GET("/:name", func(c *gin.Context) {
|
api.GET("/:name", func(c *gin.Context) {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
path := filepath.Join(cfg.ImagePath, name)
|
parts := strings.SplitN(name, "_", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
c.JSON(400, gin.H{"error": "invalid file name"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uid, filename := parts[0], parts[1]
|
||||||
|
path := filepath.Join(cfg.ImagePath, uid, filename)
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
c.JSON(404, gin.H{"error": "file not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
c.File(path)
|
c.File(path)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue