From 6e34203afde3c710b895785a1f1489f5aaf5de44 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:44:19 +0100 Subject: [PATCH] =?UTF-8?q?no=20more=20base=2064=20=F0=9F=98=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/routes/files.go | 18 ++++-------------- internal/types/types.go | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/internal/api/routes/files.go b/internal/api/routes/files.go index 28accb4..db70537 100644 --- a/internal/api/routes/files.go +++ b/internal/api/routes/files.go @@ -1,7 +1,6 @@ package routes import ( - "encoding/base64" "os" "path/filepath" "strings" @@ -42,8 +41,9 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { return } - b64, err := convertToBase64(filePath) - if err != nil { + if file.Size <= 0 { + c.JSON(400, gin.H{"error": "file size must be greater than zero"}) + return } fileMeta := types.File{ @@ -51,7 +51,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { Path: filePath, Owner: uid, CreatedAt: time.Now(), - Base64: b64, + Size: file.Size, } if err := cfg.Database.Create(&fileMeta).Error; err != nil { @@ -142,13 +142,3 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) { c.JSON(200, files) }) } - -func convertToBase64(filePath string) (string, error) { - file, err := os.ReadFile(filePath) - if err != nil { - return "", err - } - - b64 := base64.StdEncoding.EncodeToString(file) - return b64, nil -} diff --git a/internal/types/types.go b/internal/types/types.go index 6120f08..99e5186 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -26,6 +26,6 @@ type File struct { ID string `gorm:"primaryKey"` Path string `gorm:"not null;index"` Owner string `gorm:"not null;index"` + Size int64 `gorm:"not null;type:bigint"` CreatedAt time.Time `gorm:"autoCreateTime"` - Base64 string `gorm:"type:text"` }