add blurhash
This commit is contained in:
parent
bc42a2bb75
commit
264739fd76
4 changed files with 22 additions and 1 deletions
|
@ -24,6 +24,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"image"
|
||||
|
||||
"github.com/bbrks/go-blurhash"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
|
@ -84,12 +87,25 @@ func RegisterFileRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(bytes.NewReader(buf))
|
||||
if err != nil {
|
||||
types.ErrorInvalidFile.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
hash, err := blurhash.Encode(4, 3, img)
|
||||
if err != nil {
|
||||
types.ErrorInvalidFile.Throw(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
fileMeta := types.File{
|
||||
Owner: uid,
|
||||
Name: file.Filename,
|
||||
CreatedAt: time.Now(),
|
||||
Size: int64(len(buf)),
|
||||
Mime: fileType.MIME.Value,
|
||||
Blurhash: hash,
|
||||
}
|
||||
|
||||
if err := cfg.Database.Create(&fileMeta).Error; err != nil {
|
||||
|
|
|
@ -53,7 +53,8 @@ type File struct {
|
|||
Owner string `gorm:"not null;index"`
|
||||
Size int64 `gorm:"not null;type:bigint"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
Mime string
|
||||
Mime string ` gorm:"type:text"`
|
||||
Blurhash string `gorm:"type:text"`
|
||||
}
|
||||
|
||||
func (f *File) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue