From ea86ebc6a3972b9a0d302b0a986149a879de4f25 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Sun, 8 Jun 2025 15:10:51 +0100 Subject: [PATCH] fix file retrieval --- internal/api/routes/files.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/api/routes/files.go b/internal/api/routes/files.go index e5a1216..ee1d295 100644 --- a/internal/api/routes/files.go +++ b/internal/api/routes/files.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "os" "path/filepath" + "strings" "time" "github.com/gin-gonic/gin" @@ -63,7 +64,17 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { api.GET("/:name", func(c *gin.Context) { 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) })