2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2018-07-18 15:17:56 +02:00
|
|
|
|
|
|
|
import (
|
2019-06-18 06:37:10 +02:00
|
|
|
"strings"
|
2019-12-04 12:11:11 +01:00
|
|
|
"time"
|
2019-06-18 06:37:10 +02:00
|
|
|
|
|
|
|
"github.com/gosimple/slug"
|
2018-07-18 15:17:56 +02:00
|
|
|
"github.com/jinzhu/gorm"
|
2019-12-04 15:14:04 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/util"
|
2018-07-18 15:17:56 +02:00
|
|
|
)
|
|
|
|
|
2018-11-06 19:02:03 +01:00
|
|
|
// Photo album
|
2018-07-18 15:17:56 +02:00
|
|
|
type Album struct {
|
2019-06-04 18:26:35 +02:00
|
|
|
Model
|
2019-12-06 10:26:57 +01:00
|
|
|
CoverUUID string `gorm:"type:varchar(64);"`
|
2019-06-04 18:26:35 +02:00
|
|
|
AlbumUUID string `gorm:"unique_index;"`
|
2019-12-06 10:26:57 +01:00
|
|
|
AlbumToken string `gorm:"type:varchar(64);"`
|
2019-06-18 06:37:10 +02:00
|
|
|
AlbumSlug string `gorm:"index;"`
|
2019-12-04 15:14:04 +01:00
|
|
|
AlbumName string `gorm:"type:varchar(128);"`
|
2018-09-27 08:59:53 +02:00
|
|
|
AlbumDescription string `gorm:"type:text;"`
|
|
|
|
AlbumNotes string `gorm:"type:text;"`
|
2019-06-17 06:43:59 +02:00
|
|
|
AlbumViews uint
|
2019-06-17 21:45:06 +02:00
|
|
|
AlbumFavorite bool
|
2019-12-04 15:14:04 +01:00
|
|
|
AlbumPublic bool
|
2019-12-06 10:26:57 +01:00
|
|
|
AlbumLat float64
|
|
|
|
AlbumLong float64
|
|
|
|
AlbumRadius float64
|
|
|
|
AlbumOrder string `gorm:"type:varchar(16);"`
|
|
|
|
AlbumTemplate string `gorm:"type:varchar(128);"`
|
2018-07-18 15:17:56 +02:00
|
|
|
}
|
2019-06-04 18:26:35 +02:00
|
|
|
|
|
|
|
func (m *Album) BeforeCreate(scope *gorm.Scope) error {
|
2019-12-16 23:33:52 +01:00
|
|
|
if err := scope.SetColumn("AlbumUUID", util.UUID()); err != nil {
|
2019-12-06 10:26:57 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scope.SetColumn("AlbumToken", util.RandomToken(4)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-06-04 18:26:35 +02:00
|
|
|
}
|
2019-06-18 06:37:10 +02:00
|
|
|
|
|
|
|
func NewAlbum(albumName string) *Album {
|
|
|
|
albumName = strings.TrimSpace(albumName)
|
|
|
|
|
|
|
|
if albumName == "" {
|
2019-12-04 12:11:11 +01:00
|
|
|
albumName = time.Now().Format("January 2006")
|
2019-06-18 06:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
albumSlug := slug.Make(albumName)
|
|
|
|
|
|
|
|
result := &Album{
|
|
|
|
AlbumSlug: albumSlug,
|
|
|
|
AlbumName: albumName,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
2019-12-03 23:55:24 +01:00
|
|
|
|
|
|
|
func (m *Album) Rename(albumName string) {
|
2019-12-04 12:11:11 +01:00
|
|
|
if albumName == "" {
|
|
|
|
albumName = m.CreatedAt.Format("January 2006")
|
|
|
|
}
|
|
|
|
|
2019-12-03 23:55:24 +01:00
|
|
|
m.AlbumName = strings.TrimSpace(albumName)
|
|
|
|
m.AlbumSlug = slug.Make(m.AlbumName)
|
|
|
|
}
|