Compare commits
No commits in common. "f20ad1475b938f65a16b6d6abb3024bd83f423b0" and "e16a4eae261533e86951b400e0a9f986de0dc83f" have entirely different histories.
f20ad1475b
...
e16a4eae26
2 changed files with 0 additions and 17 deletions
|
@ -1,7 +1,6 @@
|
||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
@ -41,16 +40,11 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b64, err := convertToBase64(filePath)
|
|
||||||
if err != nil {
|
|
||||||
}
|
|
||||||
|
|
||||||
fileMeta := types.File{
|
fileMeta := types.File{
|
||||||
ID: uid + "_" + file.Filename,
|
ID: uid + "_" + file.Filename,
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
Owner: uid,
|
Owner: uid,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
Base64: b64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cfg.Database.Create(&fileMeta).Error; err != nil {
|
if err := cfg.Database.Create(&fileMeta).Error; err != nil {
|
||||||
|
@ -80,13 +74,3 @@ 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
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,5 +27,4 @@ type File struct {
|
||||||
Path string `gorm:"not null;index"`
|
Path string `gorm:"not null;index"`
|
||||||
Owner string `gorm:"not null;index"`
|
Owner string `gorm:"not null;index"`
|
||||||
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