2019-06-17 06:04:29 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
2019-12-06 10:26:57 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/util"
|
2019-06-17 06:04:29 +02:00
|
|
|
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Shared photos and/or albums
|
|
|
|
type Share struct {
|
|
|
|
ShareUUID string `gorm:"primary_key;auto_increment:false"`
|
2019-12-06 10:26:57 +01:00
|
|
|
PhotoUUID string
|
|
|
|
AlbumUUID string
|
2019-06-17 06:43:59 +02:00
|
|
|
ShareViews uint
|
2019-12-06 10:26:57 +01:00
|
|
|
ShareUrl string `gorm:"type:varchar(64);"`
|
|
|
|
ShareToken string `gorm:"type:varchar(64);"`
|
|
|
|
SharePassword string `gorm:"type:varchar(128);"`
|
2019-06-17 06:04:29 +02:00
|
|
|
ShareExpires time.Time
|
|
|
|
Photo *Photo
|
|
|
|
Album *Album
|
2019-06-17 07:19:44 +02:00
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
DeletedAt *time.Time `sql:"index"`
|
2019-06-17 06:04:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (Share) TableName() string {
|
|
|
|
return "shares"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Share) BeforeCreate(scope *gorm.Scope) error {
|
2019-12-06 10:26:57 +01:00
|
|
|
if err := scope.SetColumn("ShareUUID", uuid.NewV4().String()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scope.SetColumn("ShareToken", util.RandomToken(4)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-06-17 06:04:29 +02:00
|
|
|
}
|