From 09d8ffa82caee41413ec5d1329965cb00fcd1ae5 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Sat, 14 Jun 2025 20:28:53 +0100 Subject: [PATCH] add name to file struct --- internal/api/routes/files.go | 4 ++-- internal/types/types.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/routes/files.go b/internal/api/routes/files.go index 3a3f48e..e827e17 100644 --- a/internal/api/routes/files.go +++ b/internal/api/routes/files.go @@ -20,7 +20,6 @@ func intoReader(buf []byte) io.Reader { return io.NopCloser(bytes.NewBuffer(buf)) } - func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { api.POST("/upload", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) { claims := c.MustGet("claims").(jwt.MapClaims) @@ -67,6 +66,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { fileMeta := types.File{ Owner: uid, + Name: file.Filename, CreatedAt: time.Now(), Size: int64(len(buf)), Mime: fileType.MIME.Value, @@ -85,7 +85,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { return } - c.JSON(200, gin.H{"message": "file uploaded successfully", "name": fileMeta.ID.String()}) + c.JSON(200, gin.H{"message": "file uploaded successfully", "id": fileMeta.ID.String()}) }) api.DELETE("/:id", auth.JwtMiddleware(cfg.JWTSecret), func(c *gin.Context) { diff --git a/internal/types/types.go b/internal/types/types.go index eeb81c2..1c77dd6 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -32,6 +32,7 @@ type StereoConfig struct { type File struct { ID uuid.UUID `gorm:"type:uuid;primaryKey"` + Name string `gorm:"not null;index"` Owner string `gorm:"not null;index"` Size int64 `gorm:"not null;type:bigint"` CreatedAt time.Time `gorm:"autoCreateTime"`