126 lines
3.5 KiB
Go
126 lines
3.5 KiB
Go
package galleries
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const (
|
|
StatusDraft = "draft"
|
|
StatusPublished = "published"
|
|
StatusArchived = "archived"
|
|
)
|
|
|
|
type GalleryRecord struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
ClientName string
|
|
Description string
|
|
Status string
|
|
PasswordHash string
|
|
DownloadsEnabled bool
|
|
FavoritesEnabled bool
|
|
DownloadAllEnabled bool
|
|
WatermarkEnabled bool
|
|
ExpiresAt string
|
|
CoverMediaID string
|
|
ThemeConfig json.RawMessage
|
|
BrandingConfig json.RawMessage
|
|
CreatedAt string
|
|
UpdatedAt string
|
|
PublishedAt string
|
|
}
|
|
|
|
type Summary struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Slug string `json:"slug"`
|
|
Title string `json:"title"`
|
|
ClientName string `json:"clientName"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status"`
|
|
DownloadsEnabled bool `json:"downloadsEnabled"`
|
|
FavoritesEnabled bool `json:"favoritesEnabled"`
|
|
DownloadAllEnabled bool `json:"downloadAllEnabled"`
|
|
WatermarkEnabled bool `json:"watermarkEnabled"`
|
|
ExpiresAt string `json:"expiresAt,omitempty"`
|
|
CoverMediaID string `json:"coverMediaId,omitempty"`
|
|
CoverURL string `json:"coverUrl,omitempty"`
|
|
ThemeConfig json.RawMessage `json:"themeConfig"`
|
|
BrandingConfig json.RawMessage `json:"brandingConfig"`
|
|
CreatedAt string `json:"createdAt"`
|
|
PublishedAt string `json:"publishedAt,omitempty"`
|
|
PhotoCount int `json:"photoCount"`
|
|
VideoCount int `json:"videoCount"`
|
|
TotalBytes int64 `json:"totalBytes"`
|
|
}
|
|
|
|
type UpdateInput struct {
|
|
Title string
|
|
ClientName string
|
|
Description string
|
|
PasswordHash *string
|
|
ClearPassword bool
|
|
DownloadsEnabled bool
|
|
FavoritesEnabled bool
|
|
DownloadAllEnabled bool
|
|
WatermarkEnabled bool
|
|
ExpiresAt *string
|
|
CoverMediaID *string
|
|
ThemeConfig json.RawMessage
|
|
BrandingConfig json.RawMessage
|
|
}
|
|
|
|
func (g GalleryRecord) IsExpired() bool {
|
|
if strings.TrimSpace(g.ExpiresAt) == "" {
|
|
return false
|
|
}
|
|
value := strings.TrimSpace(g.ExpiresAt)
|
|
layouts := []string{
|
|
time.RFC3339Nano,
|
|
"2006-01-02 15:04:05-07:00",
|
|
"2006-01-02 15:04:05-07",
|
|
"2006-01-02 15:04:05",
|
|
}
|
|
var parsed time.Time
|
|
var err error
|
|
for _, layout := range layouts {
|
|
parsed, err = time.Parse(layout, value)
|
|
if err == nil {
|
|
break
|
|
}
|
|
}
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return !time.Now().Before(parsed)
|
|
}
|
|
|
|
func (g GalleryRecord) ToSummary(photoCount, videoCount int, totalBytes int64) Summary {
|
|
return Summary{
|
|
ID: g.ID,
|
|
Slug: g.Slug,
|
|
Title: g.Title,
|
|
ClientName: g.ClientName,
|
|
Description: g.Description,
|
|
Status: g.Status,
|
|
DownloadsEnabled: g.DownloadsEnabled,
|
|
FavoritesEnabled: g.FavoritesEnabled,
|
|
DownloadAllEnabled: g.DownloadAllEnabled,
|
|
WatermarkEnabled: g.WatermarkEnabled,
|
|
ExpiresAt: g.ExpiresAt,
|
|
CoverMediaID: g.CoverMediaID,
|
|
ThemeConfig: g.ThemeConfig,
|
|
BrandingConfig: g.BrandingConfig,
|
|
CreatedAt: g.CreatedAt,
|
|
PublishedAt: g.PublishedAt,
|
|
PhotoCount: photoCount,
|
|
VideoCount: videoCount,
|
|
TotalBytes: totalBytes,
|
|
}
|
|
}
|