2020-02-05 16:14:21 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2020-11-25 23:06:47 +01:00
|
|
|
"crypto/md5"
|
|
|
|
"encoding/hex"
|
|
|
|
|
2020-11-23 19:59:01 +01:00
|
|
|
"gorm.io/gorm"
|
2020-02-05 16:14:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Album struct {
|
2020-11-28 21:29:31 +01:00
|
|
|
Model
|
2020-11-28 21:49:33 +01:00
|
|
|
Title string `gorm:"not null"`
|
2020-11-28 21:29:31 +01:00
|
|
|
ParentAlbumID *int
|
2020-11-25 23:06:47 +01:00
|
|
|
ParentAlbum *Album
|
2020-11-28 21:49:33 +01:00
|
|
|
OwnerID int `gorm:"not null"`
|
2020-11-25 23:06:47 +01:00
|
|
|
Owner User
|
2020-11-28 21:49:33 +01:00
|
|
|
Path string `gorm:"not null"`
|
2020-11-25 23:06:47 +01:00
|
|
|
PathHash string `gorm:"unique"`
|
2020-02-05 16:14:21 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 16:19:27 +01:00
|
|
|
func (a *Album) FilePath() string {
|
|
|
|
return a.Path
|
|
|
|
}
|
2020-11-25 23:06:47 +01:00
|
|
|
|
|
|
|
func (a *Album) BeforeSave(tx *gorm.DB) (err error) {
|
|
|
|
hash := md5.Sum([]byte(a.Path))
|
|
|
|
a.PathHash = hex.EncodeToString(hash[:])
|
|
|
|
return nil
|
|
|
|
}
|