Compare commits
No commits in common. "57137a08d370fbd57a28ffbc227849dbd2d378c6" and "b3057e185ca05b8b8164c1f99729ab501e8744e0" have entirely different histories.
57137a08d3
...
b3057e185c
11 changed files with 606 additions and 596 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -41,9 +42,8 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if file.Size <= 0 {
|
b64, err := convertToBase64(filePath)
|
||||||
c.JSON(400, gin.H{"error": "file size must be greater than zero"})
|
if err != nil {
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileMeta := types.File{
|
fileMeta := types.File{
|
||||||
|
|
@ -51,7 +51,7 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
Owner: uid,
|
Owner: uid,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
Size: file.Size,
|
Base64: b64,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cfg.Database.Create(&fileMeta).Error; err != nil {
|
if err := cfg.Database.Create(&fileMeta).Error; err != nil {
|
||||||
|
|
@ -142,3 +142,13 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
c.JSON(200, files)
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,6 @@ type File struct {
|
||||||
ID string `gorm:"primaryKey"`
|
ID string `gorm:"primaryKey"`
|
||||||
Path string `gorm:"not null;index"`
|
Path string `gorm:"not null;index"`
|
||||||
Owner string `gorm:"not null;index"`
|
Owner string `gorm:"not null;index"`
|
||||||
Size int64 `gorm:"not null;type:bigint"`
|
|
||||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||||
|
Base64 string `gorm:"type:text"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue