catalog

package
v1.9.79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 16 Imported by: 9

Documentation

Overview

Package state provides tools to maintain an index of all medias that have been backed up.

Index

Constants

View Source
const MaxCoversPerAlbum = 4

Variables

View Source
var (
	AlbumNameMandatoryErr            = errors.New("Album name is mandatory")
	AlbumStartAndEndDateMandatoryErr = errors.New("Start and End times are mandatory")
	AlbumEndDateMustBeAfterStartErr  = errors.New("Album end must be strictly after its start")
	AlbumFolderNameAlreadyTakenErr   = errors.New("Album folder name is already taken")
)
View Source
var (
	AlbumNotFoundErr = errors.New("album hasn't been found")

	EmptyFolderNameError = errors.New("folderName is mandatory and must be not empty")
)
View Source
var (
	DuplicatedAlbumError = errors.New("Timeline cannot contains duplicated albums")
)
View Source
var (
	MediaNotFoundError = fmt.Errorf("media not found")
)
View Source
var (
	NoAlbumLookedUpError = errors.New("no album matching")
)
View Source
var (
	OrphanedMediasErr = errors.New("albums cannot be deleted or amended if it orphans medias.")
)
View Source
var (
	TooManyCoversErr = errors.Errorf("an album cannot have more than %d covers", MaxCoversPerAlbum)
)

Functions

func Init

func Init(repositoryAdapter RepositoryAdapter)

Init must be called before using this package.

Types

type Album

type Album struct {
	AlbumId
	Name  string    // Name for displaying purpose, not unique
	Start time.Time // Start is datetime inclusive
	End   time.Time // End is the datetime exclusive
}

Album is a logical grouping of medias ; also used to physically store media next to each others.

func (Album) IsEqual

func (a Album) IsEqual(other *Album) bool

IsEqual uses unique identifier to compare both albums

func (Album) String

func (a Album) String() string

type AlbumAutoCreateLookupStrategy added in v1.5.58

type AlbumAutoCreateLookupStrategy struct {
	BulkCreateAlbum *BulkCreateAlbum
}

AlbumAutoCreateLookupStrategy delegates to the BulkCreateAlbum use case to create a quarterly album covering mediaTime, reusing the timeline held by StatefulAlbumReferencer so subsequent lookups see the newly created album without a second load from the repository.

func (*AlbumAutoCreateLookupStrategy) LookupAlbum added in v1.5.58

func (a *AlbumAutoCreateLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)

type AlbumCoversRandomised added in v1.9.63

type AlbumCoversRandomised struct {
	AlbumId AlbumId
	Covers  []Cover
}

type AlbumCoversRandomisedObserver added in v1.9.63

type AlbumCoversRandomisedObserver interface {
	OnAlbumCoversRandomised(ctx context.Context, event AlbumCoversRandomised) error
}

type AlbumCoversRandomisedObserverFunc added in v1.9.63

type AlbumCoversRandomisedObserverFunc func(ctx context.Context, event AlbumCoversRandomised) error

func (AlbumCoversRandomisedObserverFunc) OnAlbumCoversRandomised added in v1.9.63

func (f AlbumCoversRandomisedObserverFunc) OnAlbumCoversRandomised(ctx context.Context, event AlbumCoversRandomised) error

type AlbumCreated added in v1.9.52

type AlbumCreated struct {
	CreatedAlbum      Album
	TransferredMedias TransferredMedias
	Covers            map[AlbumId][]Cover
}

AlbumCreated is fired after a new album has been persisted and its overlapping medias have been transferred: it carries the newly created album, the medias that were actually moved into it (if any), and the cover sets of every album whose covers were updated by the creation. Albums whose cover set did not change are omitted from Covers; a missing album means "no cover update required".

type AlbumCreatedAsTimelineMutation added in v1.9.52

type AlbumCreatedAsTimelineMutation struct {
	TimelineMutationObserver TimelineMutationObserver
}

func (*AlbumCreatedAsTimelineMutation) OnAlbumCreated added in v1.9.52

func (a *AlbumCreatedAsTimelineMutation) OnAlbumCreated(ctx context.Context, event AlbumCreated) error

type AlbumCreatedObserver added in v1.9.52

type AlbumCreatedObserver interface {
	OnAlbumCreated(ctx context.Context, event AlbumCreated) error
}

type AlbumCreatedObserverFunc added in v1.9.52

type AlbumCreatedObserverFunc func(ctx context.Context, event AlbumCreated) error

func (AlbumCreatedObserverFunc) OnAlbumCreated added in v1.9.52

func (f AlbumCreatedObserverFunc) OnAlbumCreated(ctx context.Context, event AlbumCreated) error

type AlbumDatesAmended added in v1.9.52

type AlbumDatesAmended struct {
	DatesUpdate       DatesUpdate
	TransferredMedias TransferredMedias
	Covers            map[AlbumId][]Cover
}

AlbumDatesAmended is fired after an album's dates have been persisted and the medias affected by the change have been transferred to their new albums. Covers carries the resulting cover sets of every album whose covers were updated as a consequence of the transfer; albums whose cover set did not change are omitted.

type AlbumDatesAmendedAsTimelineMutation added in v1.9.52

type AlbumDatesAmendedAsTimelineMutation struct {
	TimelineMutationObserver TimelineMutationObserver
}

AlbumDatesAmendedAsTimelineMutation adapts an AlbumDatesAmendedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumDatesAmended event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).

func (*AlbumDatesAmendedAsTimelineMutation) OnAlbumDatesAmended added in v1.9.52

func (a *AlbumDatesAmendedAsTimelineMutation) OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error

type AlbumDatesAmendedObserver added in v1.5.58

type AlbumDatesAmendedObserver interface {
	OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error
}

type AlbumDatesAmendedObserverFunc added in v1.5.58

type AlbumDatesAmendedObserverFunc func(ctx context.Context, event AlbumDatesAmended) error

func (AlbumDatesAmendedObserverFunc) OnAlbumDatesAmended added in v1.5.58

func (f AlbumDatesAmendedObserverFunc) OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error

type AlbumDatesUpdated added in v1.9.52

type AlbumDatesUpdated struct {
	DatesUpdate   DatesUpdate
	MediaTransfer MediaTransferRecords
	Orphaned      []MediaSelector
}

AlbumDatesUpdated carries the outcome of an album date amendment as computed by the TimelineAggregate: the DatesUpdate (with the previous start/end preserved so the caller can detect a no-op via DatesUpdate.DatesNotChanged()), the media transfer records needed to reallocate medias to their new album, and any selectors that would be left orphan.

type AlbumDeleted added in v1.9.52

type AlbumDeleted struct {
	DeletedAlbumId    AlbumId
	TransferredMedias TransferredMedias
	Covers            map[AlbumId][]Cover
}

AlbumDeleted is fired after an album has been deleted and its medias transferred to the surrounding albums: it carries the id of the album that has been removed, the medias that were actually moved to another album, and the per-album cover sets that changed as a side-effect (deleted album maps to nil, destinations map to their new cover list). Albums whose cover set did not change are omitted from Covers.

type AlbumDeletedAsTimelineMutation added in v1.9.52

type AlbumDeletedAsTimelineMutation struct {
	TimelineMutationObserver TimelineMutationObserver
}

AlbumDeletedAsTimelineMutation adapts an AlbumDeletedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumDeleted event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).

func (*AlbumDeletedAsTimelineMutation) OnAlbumDeleted added in v1.9.52

func (a *AlbumDeletedAsTimelineMutation) OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error

type AlbumDeletedObserver added in v1.9.52

type AlbumDeletedObserver interface {
	OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error
}

type AlbumDeletedObserverFunc added in v1.9.52

type AlbumDeletedObserverFunc func(ctx context.Context, event AlbumDeleted) error

func (AlbumDeletedObserverFunc) OnAlbumDeleted added in v1.9.52

func (f AlbumDeletedObserverFunc) OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error

type AlbumId

type AlbumId struct {
	Owner      ownermodel.Owner
	FolderName FolderName
}

func NewAlbumIdFromStrings added in v1.5.33

func NewAlbumIdFromStrings(owner, folderName string) AlbumId

NewAlbumIdFromStrings creates an AlbumId from 2 strings ; it doesn't guaranty its validity, use AlbumId.IsValid to check if any error.

func (AlbumId) IsEqual added in v1.5.33

func (a AlbumId) IsEqual(other AlbumId) bool

IsEqual uses unique identifier to compare both albums

func (AlbumId) IsValid added in v1.5.33

func (a AlbumId) IsValid() error

func (AlbumId) String

func (a AlbumId) String() string

type AlbumLookupStrategy added in v1.5.58

type AlbumLookupStrategy interface {
	// LookupAlbum returns the AlbumReference for the given mediaTime, or NoAlbumLookedUpError if it can't find any (or a technical error)
	LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)
}

type AlbumNameUpdated added in v1.9.52

type AlbumNameUpdated struct {
	ExistingAlbum Album
	RenamedAlbum  Album
	MediaTransfer MediaTransferRecords
}

AlbumNameUpdated carries the outcome of a folder-name-changing rename as computed by the TimelineAggregate: the existing album to remove, the new album to insert, and the media transfer that moves the existing album's medias into the new one.

type AlbumQueries added in v1.5.49

type AlbumQueries struct {
	Repository RepositoryAdapter
}

func (*AlbumQueries) CountMedia added in v1.5.50

func (a *AlbumQueries) CountMedia(ctx context.Context, album ...AlbumId) (map[AlbumId]int, error)

func (*AlbumQueries) FindAlbum added in v1.6.4

func (a *AlbumQueries) FindAlbum(ctx context.Context, albumId AlbumId) (*Album, error)

func (*AlbumQueries) FindAlbumsById added in v1.5.49

func (a *AlbumQueries) FindAlbumsById(ctx context.Context, ids []AlbumId) ([]*Album, error)

func (*AlbumQueries) FindAlbumsByOwner added in v1.5.49

func (a *AlbumQueries) FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)

type AlbumReference added in v1.5.54

type AlbumReference struct {
	AlbumId          *AlbumId // AlbumId if no album fit the time and the implementation doesn't support creation.
	AlbumJustCreated bool     // AlbumJustCreated is true if the album was created during the reference process (depending on the implementation capability).
}

type AlbumRenamed added in v1.9.52

type AlbumRenamed struct {
	ExistingAlbum     Album
	RenamedAlbum      Album
	TransferredMedias TransferredMedias
}

type AlbumRenamedAsTimelineMutation added in v1.9.52

type AlbumRenamedAsTimelineMutation struct {
	TimelineMutationObserver TimelineMutationObserver
}

AlbumRenamedAsTimelineMutation adapts an AlbumRenamedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumRenamed event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).

func (*AlbumRenamedAsTimelineMutation) OnAlbumRenamed added in v1.9.52

func (a *AlbumRenamedAsTimelineMutation) OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error

type AlbumRenamedObserver added in v1.9.52

type AlbumRenamedObserver interface {
	OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error
}

type AlbumRenamedObserverFunc added in v1.9.52

type AlbumRenamedObserverFunc func(ctx context.Context, event AlbumRenamed) error

func (AlbumRenamedObserverFunc) OnAlbumRenamed added in v1.9.52

func (f AlbumRenamedObserverFunc) OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error

type AmendAlbumDates added in v1.5.45

type AmendAlbumDates struct {
	TimelineRepository         TimelineRepository
	CountMediasBySelectorsPort CountMediasBySelectorsPort
	TransferMediasService      TransferMediasService
	CoverService               CoverServicePort
	AlbumDatesAmendedObservers []AlbumDatesAmendedObserver
}

AmendAlbumDates changes the start/end dates of an album, transfers medias affected by the date change to their new album, then fires an AlbumDatesAmended event. When some medias would be left orphan (no album covers them anymore) the operation is aborted and OrphanedMediasErr is returned before any change is persisted.

func NewAmendAlbumDates added in v1.5.45

func NewAmendAlbumDates(
	timelineRepository TimelineRepository,
	countMediasBySelectors CountMediasBySelectorsPort,
	transferMedias TransferMediasService,
	coverService CoverServicePort,
	observers ...AlbumDatesAmendedObserver,
) *AmendAlbumDates

NewAmendAlbumDates creates the service to amend the dates of an album.

func (*AmendAlbumDates) AmendAlbumDates added in v1.5.45

func (a *AmendAlbumDates) AmendAlbumDates(ctx context.Context, albumId AlbumId, start, end time.Time) error

type BackfillCovers added in v1.9.63

type BackfillCovers struct {
	FindAlbumByOwnerPort FindAlbumByOwnerPort
	CoverService         CoverServicePort
	Observers            []CoverBackfillObserver
}

BackfillCovers is a utility to reconcile the covers of each album of an owner.

func (*BackfillCovers) BackfillForOwner added in v1.9.63

func (b *BackfillCovers) BackfillForOwner(ctx context.Context, owner ownermodel.Owner) (map[AlbumId][]Cover, error)

type BulkCreateAlbum added in v1.9.52

type BulkCreateAlbum struct {
	TimelineRepository    TimelineRepository
	TransferMediasService TransferMediasService
	CoverService          CoverServicePort
	AlbumCreatedObservers []AlbumCreatedObserver
}

func (*BulkCreateAlbum) Create added in v1.9.52

func (c *BulkCreateAlbum) Create(ctx context.Context, timeline *TimelineAggregate, request CreateAlbumRequest) (*AlbumId, error)

type CountMediasBySelectorsFunc added in v1.5.41

type CountMediasBySelectorsFunc func(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)

func (CountMediasBySelectorsFunc) CountMediasBySelectors added in v1.5.41

func (f CountMediasBySelectorsFunc) CountMediasBySelectors(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)

type CountMediasBySelectorsPort added in v1.5.41

type CountMediasBySelectorsPort interface {
	CountMediasBySelectors(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)
}

type Cover added in v1.9.63

type Cover struct {
	MediaId  MediaId
	Filename string
	Origin   CoverOrigin
}

type CoverBackfillObserver added in v1.9.63

type CoverBackfillObserver interface {
	OnCoverBackfilled(ctx context.Context, coversByAlbumId map[AlbumId][]Cover) error
}

type CoverOrigin added in v1.9.63

type CoverOrigin string
const (
	CoverOriginRandom       CoverOrigin = "RANDOM"
	CoverOriginCherryPicked CoverOrigin = "CHERRY_PICKED"
)

type CoverRepository added in v1.9.63

type CoverRepository interface {
	FindCoversByAlbum(ctx context.Context, albumId AlbumId) ([]Cover, error)
	FindCoversByAlbums(ctx context.Context, albumIds ...AlbumId) (map[AlbumId][]Cover, error)
	SaveCovers(ctx context.Context, albumId AlbumId, covers []Cover) error
	MoveCovers(ctx context.Context, from, to AlbumId) error
}

CoverRepository persists an album's cover set as a single record.

type CoverService added in v1.9.63

type CoverService struct {
	CoverRepository     CoverRepository
	MediaReadRepository MediaReadRepository
	Randomiser          Randomiser
}

func NewCoverService added in v1.9.63

func NewCoverService(coverRepository CoverRepository, mediaReadRepository MediaReadRepository) *CoverService

func (*CoverService) ApplyTransfer added in v1.9.63

func (c *CoverService) ApplyTransfer(ctx context.Context, transferred TransferredMedias, deletedAlbumIds ...AlbumId) (map[AlbumId][]Cover, error)

ApplyTransfer processes every album affected by `transferred`, plus every album listed in `deletedAlbumIds` whose canonical cover record must be erased even when no media was moved out of it (e.g. empty album deleted):

  • For each source album, covers whose media has moved away are stripped.
  • CHERRY_PICKED covers that moved to a destination album are inherited by the destination (as CHERRY_PICKED), displacing the oldest RANDOM cover when needed. Destinations already full of CHERRY_PICKED covers silently ignore the incoming one.
  • Every affected album has its empty slots backfilled from its full image set.
  • Every album in `deletedAlbumIds` has its canonical cover record erased unconditionally.

Returns one entry per album whose cover set actually changed; deleted albums map to nil. Returns a nil map when no album changed.

func (*CoverService) ForcedRandomise added in v1.9.63

func (c *CoverService) ForcedRandomise(ctx context.Context, albumIds ...AlbumId) (map[AlbumId][]Cover, error)

ForcedRandomise refreshes the cover set of every requested album by stripping covers whose media is no longer in the album, dropping every RANDOM cover so that newly-added medias get a chance to appear as a cover, and filling the empty slots at random from the album's full image set. CHERRY_PICKED covers whose media is still in the album are always kept. The returned map carries one entry per album whose cover set actually changed; unchanged albums are omitted. Returns a nil map when nothing changed.

func (*CoverService) StableRandomise added in v1.9.63

func (c *CoverService) StableRandomise(ctx context.Context, albumIds ...AlbumId) (map[AlbumId][]Cover, error)

StableRandomise refreshes the cover set of every requested album by stripping covers whose media is no longer in the album and filling the empty slots at random from the album's full image set. Every cover whose media is still in the album is kept untouched. The returned map carries one entry per album whose cover set actually changed; unchanged albums are omitted. Returns a nil map when nothing changed.

type CoverServicePort added in v1.9.63

type CoverServicePort interface {
	ForcedRandomise(ctx context.Context, albumIds ...AlbumId) (map[AlbumId][]Cover, error)
	StableRandomise(ctx context.Context, albumIds ...AlbumId) (map[AlbumId][]Cover, error)
	ApplyTransfer(ctx context.Context, transferred TransferredMedias, deletedAlbumIds ...AlbumId) (map[AlbumId][]Cover, error)
}

type CreateAlbum

type CreateAlbum struct {
	TimelineRepository TimelineRepository
	BulkCreateAlbum    *BulkCreateAlbum
}

CreateAlbum inserts a new album and, if it overlaps with existing albums, transfers the overlapping medias into it. On success, an AlbumCreated event is fired to every observer.

func NewAlbumCreate added in v1.5.42

func NewAlbumCreate(
	TimelineRepository TimelineRepository,
	TransferMedias TransferMediasService,
	CoverService CoverServicePort,
	AlbumCreatedObservers ...AlbumCreatedObserver,
) *CreateAlbum

NewAlbumCreate creates the service to create a new album, including the transfer of medias.

func (*CreateAlbum) Create added in v1.5.33

func (c *CreateAlbum) Create(ctx context.Context, request CreateAlbumRequest) (*AlbumId, error)

type CreateAlbumRequest added in v1.5.33

type CreateAlbumRequest struct {
	Owner            ownermodel.Owner
	Name             string
	Start            time.Time
	End              time.Time
	ForcedFolderName string
}

CreateAlbumRequest is a request to create a new album

func (*CreateAlbumRequest) IsValid added in v1.5.33

func (c *CreateAlbumRequest) IsValid() error

func (*CreateAlbumRequest) String added in v1.5.33

func (c *CreateAlbumRequest) String() string

type CreateMediaRequest

type CreateMediaRequest struct {
	Id         MediaId        // Id is generated from its signature with GenerateMediaId(MediaSignature)
	Signature  MediaSignature // Signature is the business key of a media
	FolderName FolderName     // FolderName is the name of the album the media is in
	Filename   string         // Filename is a user-friendly name that have the right extension.
	Type       MediaType
	Details    MediaDetails
}

CreateMediaRequest is the request to add a new media to an album belonging to the same Owner

type DatesUpdate added in v1.5.58

type DatesUpdate struct {
	UpdatedAlbum  Album
	PreviousStart time.Time
	PreviousEnd   time.Time
}

func (*DatesUpdate) DatesNotChanged added in v1.5.58

func (a *DatesUpdate) DatesNotChanged() bool

type DeleteAlbum

type DeleteAlbum struct {
	TimelineRepository     TimelineRepository
	CountMediasBySelectors CountMediasBySelectorsPort
	TransferMediasService  TransferMediasService
	CoverService           CoverServicePort
	AlbumDeletedObservers  []AlbumDeletedObserver
}

DeleteAlbum removes an album from the catalog: any media it currently holds is moved to the surrounding albums (as computed by the TimelineAggregate), and an AlbumDeleted event is fired once the row has been removed.

func NewDeleteAlbum added in v1.5.41

func NewDeleteAlbum(
	TimelineRepository TimelineRepository,
	CountMediasBySelectors CountMediasBySelectorsPort,
	TransferMedias TransferMediasService,
	CoverService CoverServicePort,
	AlbumDeletedObservers ...AlbumDeletedObserver,
) *DeleteAlbum

NewDeleteAlbum creates the service to delete an album, transferring its medias to the surrounding albums when possible.

func (*DeleteAlbum) DeleteAlbum added in v1.5.41

func (d *DeleteAlbum) DeleteAlbum(ctx context.Context, albumId AlbumId) error

type DryRunLookupStrategy added in v1.5.58

type DryRunLookupStrategy struct{}

func (*DryRunLookupStrategy) LookupAlbum added in v1.5.58

func (d *DryRunLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)

type FindAlbumByOwnerPort added in v1.9.63

type FindAlbumByOwnerPort interface {
	FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
}

type FindCoversByAlbumPort added in v1.9.63

type FindCoversByAlbumPort interface {
	FindCoversByAlbum(ctx context.Context, albumId AlbumId) ([]Cover, error)
}

type FindExistingSignaturePort added in v1.5.54

type FindExistingSignaturePort interface {
	FindSignatures(ctx context.Context, owner ownermodel.Owner, signatures []MediaSignature) (map[MediaSignature]MediaId, error)
}

type FindMediaRequest

type FindMediaRequest struct {
	Owner            ownermodel.Owner
	AlbumFolderNames map[FolderName]interface{} // AlbumFolderNames is a set of folder names (map value is nil)
	Ranges           []TimeRange                // Ranges is optional, if empty no restriction will be applied
}

FindMediaRequest is a filter that is applied to find medias within a time range.

func NewFindMediaRequest

func NewFindMediaRequest(owner ownermodel.Owner) *FindMediaRequest

func (*FindMediaRequest) String

func (m *FindMediaRequest) String() string

func (*FindMediaRequest) WithAlbum

func (m *FindMediaRequest) WithAlbum(folderNames ...FolderName) *FindMediaRequest

func (*FindMediaRequest) WithinRange

func (m *FindMediaRequest) WithinRange(start, end time.Time) *FindMediaRequest

type FolderName added in v1.5.33

type FolderName string

FolderName is a normalised ID unique per Owner

func NewFolderName added in v1.5.33

func NewFolderName(name string) FolderName

NewFolderName creates a FolderName with a normalised value ; it can still be invalid (empty)

func (FolderName) IsValid added in v1.5.33

func (n FolderName) IsValid() error

func (FolderName) String added in v1.5.33

func (n FolderName) String() string

type InMemoryMedia added in v1.6.4

type InMemoryMedia struct {
	MediaMeta
	AlbumId AlbumId
}

func NewInMemoryMedia added in v1.6.4

func NewInMemoryMedia(id MediaId, albumId AlbumId) InMemoryMedia

type InsertMedias

type InsertMedias struct {
	InsertMediasRepository InsertMediasRepositoryPort
	CoverService           CoverServicePort
	InsertMediasObservers  []InsertMediasObserver
}

InsertMedias is a use case to pre-generate ids and store media metadata.

func NewInsertMedias added in v1.5.47

func NewInsertMedias(
	InsertMediasRepository InsertMediasRepositoryPort,
	CoverService CoverServicePort,
	InsertMediasObservers ...InsertMediasObserver,
) *InsertMedias

func (*InsertMedias) Insert added in v1.5.47

func (i *InsertMedias) Insert(ctx context.Context, owner ownermodel.Owner, medias []CreateMediaRequest) error

type InsertMediasObserver added in v1.5.47

type InsertMediasObserver interface {
	OnMediasInserted(ctx context.Context, event MediasInserted) error
}

type InsertMediasObserverFunc added in v1.9.63

type InsertMediasObserverFunc func(ctx context.Context, event MediasInserted) error

func (InsertMediasObserverFunc) OnMediasInserted added in v1.9.63

func (f InsertMediasObserverFunc) OnMediasInserted(ctx context.Context, event MediasInserted) error

type InsertMediasRepositoryPort added in v1.5.47

type InsertMediasRepositoryPort interface {
	// InsertMedias bulks insert medias
	InsertMedias(ctx context.Context, owner ownermodel.Owner, media []CreateMediaRequest) error
}

type MediaDetails

type MediaDetails struct {
	Width, Height             int
	DateTime                  time.Time
	Orientation               MediaOrientation
	Make                      string
	Model                     string
	GPSLatitude, GPSLongitude float64
	Duration                  int64  // Duration is the length, in milliseconds, of a video
	VideoEncoding             string // VideoEncoding is the codec used to encode the video (ex: 'H264')
}

MediaDetails are extracted from the metadata within photos and videos and stored as it.

type MediaFutureReference added in v1.5.54

type MediaFutureReference struct {
	Signature          MediaSignature
	ProvisionalMediaId MediaId
	AlreadyExists      bool
}

MediaFutureReference is the response of a simulation of inserting the media: the unique ID (if the media already exists) or a unique ID the media can use.

type MediaId added in v1.5.33

type MediaId string

func GenerateMediaId

func GenerateMediaId(signature MediaSignature) (MediaId, error)

GenerateMediaId generate a unique ID for a media.

func (MediaId) Value added in v1.5.47

func (m MediaId) Value() string

type MediaMeta

type MediaMeta struct {
	Id        MediaId        // Id is the unique identifier to use across all domains
	Signature MediaSignature // Signature is the key used to get the image (or its location)
	Filename  string         // Filename original filename when image was uploaded
	Type      MediaType
	Details   MediaDetails
}

MediaMeta is an entry (read) of a media in the state

type MediaOrientation

type MediaOrientation string

type MediaPage

type MediaPage struct {
	NextPage string // NextPage is empty if no other pages
	Content  []*MediaMeta
}

MediaPage is the current page MediaMeta, and the token of the next page

type MediaQueries added in v1.6.4

type MediaQueries struct {
	MediaReadRepository MediaReadRepository
}

func (*MediaQueries) FindMediaOwnership added in v1.6.4

func (q *MediaQueries) FindMediaOwnership(ctx context.Context, owner ownermodel.Owner, mediaId MediaId) (*AlbumId, error)

FindMediaOwnership returns the folderName containing the media, or AlbumNotFoundErr.

func (*MediaQueries) ListMedias added in v1.6.4

func (q *MediaQueries) ListMedias(ctx context.Context, albumId AlbumId) ([]*MediaMeta, error)

type MediaQueriesInMemory added in v1.6.4

type MediaQueriesInMemory struct {
	Medias []InMemoryMedia
}

MediaQueriesInMemory is a copy of MediaQueries with an in-memory implementation

func (*MediaQueriesInMemory) FindMediaOwnership added in v1.6.4

func (q *MediaQueriesInMemory) FindMediaOwnership(ctx context.Context, owner ownermodel.Owner, mediaId MediaId) (*AlbumId, error)

FindMediaOwnership returns the folderName containing the media, or AlbumNotFoundErr.

func (*MediaQueriesInMemory) ListMedias added in v1.6.4

func (q *MediaQueriesInMemory) ListMedias(ctx context.Context, albumId AlbumId) ([]*MediaMeta, error)

type MediaReadRepository added in v1.6.4

type MediaReadRepository interface {
	FindMedias(ctx context.Context, request *FindMediaRequest) (medias []*MediaMeta, err error)
	FindMediaCurrentAlbum(ctx context.Context, owner ownermodel.Owner, mediaId MediaId) (id *AlbumId, err error)
}

type MediaSelector added in v1.5.33

type MediaSelector struct {
	//ExclusiveAlbum *AlbumId  // ExclusiveAlbum is the Album in which medias are NOT (optional)
	FromAlbums []AlbumId // FromAlbums is a list of potential origins of medias ; is mandatory on CreateAlbum case because media are not indexed by date, only per album.
	Start      time.Time // Start is the first date of matching medias, included
	End        time.Time // End is the last date of matching media, excluded at the second
}

func (MediaSelector) String added in v1.5.33

func (m MediaSelector) String() string

type MediaSignature

type MediaSignature struct {
	SignatureSha256 string
	SignatureSize   int
}

func DecodeMediaId

func DecodeMediaId(encodedId MediaId) (*MediaSignature, error)

DecodeMediaId reverse what the GenerateMediaId has done to find original signature.

func (MediaSignature) String

func (s MediaSignature) String() string

func (MediaSignature) Value added in v1.5.57

func (s MediaSignature) Value() string

type MediaTransferRecords added in v1.5.33

type MediaTransferRecords map[AlbumId][]MediaSelector

MediaTransferRecords is a description of all medias that needs to be moved accordingly to the Timeline change

func (MediaTransferRecords) String added in v1.5.33

func (r MediaTransferRecords) String() string

type MediaType

type MediaType string
const (
	MediaTypeImage MediaType = "IMAGE"
	MediaTypeVideo MediaType = "VIDEO"
	MediaTypeOther MediaType = "OTHER"
)

type MediasInsertSimulator added in v1.5.54

type MediasInsertSimulator struct {
	FindExistingSignaturePort FindExistingSignaturePort
}

func (*MediasInsertSimulator) SimulateInsertingMedia added in v1.5.54

func (m *MediasInsertSimulator) SimulateInsertingMedia(ctx context.Context, owner ownermodel.Owner, signatures []MediaSignature) ([]MediaFutureReference, error)

type MediasInserted added in v1.9.63

type MediasInserted struct {
	Inserted map[AlbumId][]MediaId
	Covers   map[AlbumId][]Cover
}

MediasInserted is the lifecycle event fired after medias have been persisted. It carries the inserted MediaIds per album and the resulting cover sets of the albums whose covers were updated (albums whose cover set did not change are omitted).

type PageRequest

type PageRequest struct {
	Size     int64
	NextPage string
}

type PrioritySegment

type PrioritySegment struct {
	Start  time.Time
	End    time.Time
	Albums []Album // sorted by priority
}

type Randomiser added in v1.9.63

type Randomiser interface {
	SampleIndices(upperBound, n int) []int
}

Randomiser picks n indices in [0, upperBound) uniformly at random, without replacement. The default implementation uses math/rand; tests substitute a deterministic one.

var DefaultRandomiser Randomiser = RandomiserFunc(func(upperBound, n int) []int {
	if n >= upperBound {
		indices := make([]int, upperBound)
		for i := range indices {
			indices[i] = i
		}
		return indices
	}
	return rand.Perm(upperBound)[:n]
})

DefaultRandomiser is a Randomiser backed by the global math/rand source. It returns n distinct indices in [0, upperBound), or all of them when n >= upperBound.

type RandomiserFunc added in v1.9.63

type RandomiserFunc func(upperBound, n int) []int

func (RandomiserFunc) SampleIndices added in v1.9.63

func (f RandomiserFunc) SampleIndices(upperBound, n int) []int

type RandomizeAlbumCovers added in v1.9.63

type RandomizeAlbumCovers struct {
	CoverService          CoverServicePort
	FindCoversByAlbumPort FindCoversByAlbumPort
	Observers             []AlbumCoversRandomisedObserver
}

RandomizeAlbumCovers is the owner-triggered use case to re-randomise the covers of a single album. It delegates the cover maintenance to the CoverService (non-stable variant: RANDOM covers are dropped and re-picked, CHERRY_PICKED covers are preserved, empty slots are filled up to MaxCoversPerAlbum). It fires AlbumCoversRandomised when the cover set actually changed, so view projections mirror the owner's action without doing a redundant write when the redraw happened to produce the same set.

func NewRandomizeAlbumCovers added in v1.9.63

func NewRandomizeAlbumCovers(
	coverService CoverServicePort,
	findCoversByAlbum FindCoversByAlbumPort,
	observers ...AlbumCoversRandomisedObserver,
) *RandomizeAlbumCovers

func (*RandomizeAlbumCovers) Randomize added in v1.9.63

func (r *RandomizeAlbumCovers) Randomize(ctx context.Context, albumId AlbumId) ([]Cover, error)

type RenameAlbum

type RenameAlbum struct {
	TimelineRepository    TimelineRepository
	TransferMediasService TransferMediasService
	CoverRepository       CoverRepository
	AlbumRenamedObservers []AlbumRenamedObserver
}

func NewRenameAlbum added in v1.5.43

func NewRenameAlbum(
	TimelineRepository TimelineRepository,
	TransferMedias TransferMediasService,
	CoverRepository CoverRepository,
	AlbumRenamedObservers ...AlbumRenamedObserver,
) *RenameAlbum

NewRenameAlbum creates the service to rename an album.

func (*RenameAlbum) RenameAlbum added in v1.5.43

func (r *RenameAlbum) RenameAlbum(ctx context.Context, request RenameAlbumRequest) error

type RenameAlbumRequest added in v1.5.43

type RenameAlbumRequest struct {
	CurrentId        AlbumId
	NewName          string
	RenameFolder     bool   // RenameFolder set to TRUE will create a new album with a FolderName generated from the NewName
	ForcedFolderName string // ForcedFolderName set to non-empty will create a new album with the requested FolderName (RenameFolder is ignored)
}

func (RenameAlbumRequest) String added in v1.5.43

func (r RenameAlbumRequest) String() string

type RepositoryAdapter

type RepositoryAdapter interface {
	FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)

	// FindAlbumByIds only returns found albums
	FindAlbumByIds(ctx context.Context, ids ...AlbumId) ([]*Album, error)

	CountMedia(ctx context.Context, album ...AlbumId) (map[AlbumId]int, error)
}

RepositoryAdapter brings persistence layer to catalog package

type StatefulAlbumReferencer added in v1.5.58

type StatefulAlbumReferencer struct {
	Owner             ownermodel.Owner
	TimelineAggregate *TimelineAggregate
	LookupStrategies  []AlbumLookupStrategy // LookupStrategies will return the first matching album reference (not returning NoAlbumLookedUpError)
}

func (*StatefulAlbumReferencer) FindReference added in v1.5.58

func (a *StatefulAlbumReferencer) FindReference(ctx context.Context, mediaTime time.Time) (AlbumReference, error)

type ThreadSafeAlbumReferencer added in v1.6.13

type ThreadSafeAlbumReferencer struct {
	Delegate *StatefulAlbumReferencer
	// contains filtered or unexported fields
}

func NewAlbumAutoPopulateReferencer added in v1.5.54

func NewAlbumAutoPopulateReferencer(
	owner ownermodel.Owner,
	timelineRepository TimelineRepository,
	TransferMediasService TransferMediasService,
	CoverService CoverServicePort,
	AlbumCreatedObservers ...AlbumCreatedObserver,
) (*ThreadSafeAlbumReferencer, error)

NewAlbumAutoPopulateReferencer find reference of the albums that will receive the new medias, or creates a new one.

func NewAlbumDryRunReferencer added in v1.5.57

func NewAlbumDryRunReferencer(
	owner ownermodel.Owner,
	timelineRepository TimelineRepository,
) (*ThreadSafeAlbumReferencer, error)

NewAlbumDryRunReferencer find a reference of the album that wil receive the new media, or informs that a new album will be created (dry run).

func (*ThreadSafeAlbumReferencer) FindReference added in v1.6.13

func (t *ThreadSafeAlbumReferencer) FindReference(ctx context.Context, mediaTime time.Time) (AlbumReference, error)

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
}

TimeRange is of days, start is inclusive (at the second), end is exclusive (at the second)

func (TimeRange) Equals

func (t TimeRange) Equals(other TimeRange) bool

func (TimeRange) Minus

func (t TimeRange) Minus(other TimeRange) (ranges []TimeRange)

func (TimeRange) Plus

func (t TimeRange) Plus(other TimeRange) (ranges []TimeRange)

func (TimeRange) String

func (t TimeRange) String() string

type Timeline

type Timeline struct {
	// contains filtered or unexported fields
}

Timeline can be used to find to which album a media will belongs.

func NewTimeline

func NewTimeline(originalAlbums []*Album) (*Timeline, error)

NewTimeline creates a Timeline object used to compute overlaps between Album. List of albums must be sorted by Start date ASC (End sorting does not matter).

func (*Timeline) AppendAlbum

func (t *Timeline) AppendAlbum(album *Album) (*Timeline, error)

AppendAlbum generates a new timeline from memory

func (*Timeline) Debug added in v1.5.53

func (t *Timeline) Debug() string

func (*Timeline) FindAllAt

func (t *Timeline) FindAllAt(date time.Time) []*Album

func (*Timeline) FindAt

func (t *Timeline) FindAt(date time.Time) (*Album, bool)

FindAt returns nil if not found

func (*Timeline) FindForAlbum

func (t *Timeline) FindForAlbum(albumId AlbumId) (segments []PrioritySegment)

func (*Timeline) FindSegmentsBetween added in v1.5.41

func (t *Timeline) FindSegmentsBetween(start, end time.Time) (segments []PrioritySegment)

FindSegmentsBetween returns a list of segments between start and end date. Segments will cover the whole period, but might not have any album.

func (*Timeline) FindSegmentsBetweenAndFilter added in v1.5.45

func (t *Timeline) FindSegmentsBetweenAndFilter(start, end time.Time, albumId AlbumId) (segments []PrioritySegment)

FindSegmentsBetweenAndFilter returns a list of segments between start and end date, only segments lead by the given albumId will be returned.

type TimelineAggregate added in v1.5.53

type TimelineAggregate struct {
	// contains filtered or unexported fields
}

func NewTimelineAggregate added in v1.5.53

func NewTimelineAggregate(albums []*Album) (*TimelineAggregate, error)

NewTimelineAggregate builds a TimelineAggregate eagerly: the timeline is computed upfront so any inconsistency in the persisted albums (like a duplicated AlbumId) is surfaced immediately. Every mutating method on the aggregate keeps this invariant by rebuilding the timeline from the updated in-memory album list.

func (*TimelineAggregate) AmendDates added in v1.5.57

func (t *TimelineAggregate) AmendDates(albumId AlbumId, start, end time.Time) (*AlbumDatesUpdated, error)

AmendDates validates the amendment and, if the dates actually change, mutates the aggregate to reflect the new dates and computes the media transfer records plus any orphaned selectors. When the dates are unchanged, the aggregate is left untouched and the returned AlbumDatesUpdated has DatesUpdate.DatesNotChanged() == true and empty transfer records: it is up to the caller (the use case) to short-circuit on that signal.

Returns AlbumNotFoundErr if albumId is unknown to the aggregate.

func (*TimelineAggregate) CreateNewAlbum added in v1.5.54

func (t *TimelineAggregate) CreateNewAlbum(request CreateAlbumRequest) (Album, MediaTransferRecords, error)

CreateNewAlbum validates the request, appends the new album to the aggregate, rebuilds the timeline, and returns both the created Album and the MediaTransferRecords for medias that overlapping albums should hand over to it. Returns AlbumFolderNameAlreadyTakenErr if the computed folder name collides with an existing album.

func (*TimelineAggregate) FindAt added in v1.5.54

func (t *TimelineAggregate) FindAt(date time.Time) (*Album, bool)

func (*TimelineAggregate) RemoveAlbum added in v1.5.57

func (t *TimelineAggregate) RemoveAlbum(deletedAlbumId AlbumId) (MediaTransferRecords, []MediaSelector, error)

func (*TimelineAggregate) RenameAlbum added in v1.9.52

func (t *TimelineAggregate) RenameAlbum(request RenameAlbumRequest) (*AlbumNameUpdated, error)

RenameAlbum removes the existing album from the aggregate and inserts a new one carrying the new folder name / display name. It returns everything the application service needs to persist the rename and move the medias:

  • AlbumNotFoundErr if currentId is unknown to the aggregate.
  • AlbumFolderNameAlreadyTakenErr if the target folder name is used by another album.

The rename is expected to change the folder name; the caller is responsible for handling the name-only case (a simple UpdateAlbumName on the same row) before reaching this method.

type TimelineLookupStrategy added in v1.5.58

type TimelineLookupStrategy struct{}

func (TimelineLookupStrategy) LookupAlbum added in v1.5.58

func (t TimelineLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)

type TimelineMutationObserver added in v1.5.33

type TimelineMutationObserver interface {
	OnTransferredMedias(ctx context.Context, transfers TransferredMedias) error
}

TimelineMutationObserver will notify each observer that medias has been transferred to a different album.

type TimelineMutationObserverFunc added in v1.5.42

type TimelineMutationObserverFunc func(ctx context.Context, transfers TransferredMedias) error

func (TimelineMutationObserverFunc) OnTransferredMedias added in v1.6.4

func (f TimelineMutationObserverFunc) OnTransferredMedias(ctx context.Context, transfers TransferredMedias) error

type TimelinePersistencePort added in v1.9.53

type TimelinePersistencePort interface {
	FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
	InsertAlbum(ctx context.Context, album Album) error
	DeleteAlbum(ctx context.Context, albumId AlbumId) error
	UpdateAlbumName(ctx context.Context, albumId AlbumId, newName string) (Album, Album, error)
	AmendDates(ctx context.Context, albumId AlbumId, start, end time.Time) error
}

TimelinePersistencePort is the persistence surface a TimelineRepositoryAdapter needs from the outside world. It is satisfied by the DynamoDB Repository as well as by the in-memory fake used in tests.

type TimelineRepository added in v1.9.53

type TimelineRepository interface {
	LoadTimeline(ctx context.Context, owner ownermodel.Owner) (*TimelineAggregate, error)
	InsertAlbum(ctx context.Context, album Album) error
	DeleteAlbum(ctx context.Context, albumId AlbumId) error
	UpdateAlbumName(ctx context.Context, albumId AlbumId, newName string) (Album, Album, error)
	AmendDates(ctx context.Context, albumId AlbumId, start, end time.Time) error
}

TimelineRepository is the single port through which the album use cases both build the TimelineAggregate for an owner and persist mutations to individual albums. LoadTimeline returns a ready-to-use aggregate: it fails if the persisted albums cannot form a valid timeline (e.g. duplicated AlbumId).

type TimelineRepositoryAdapter added in v1.9.53

type TimelineRepositoryAdapter struct {
	TimelinePersistencePort
}

TimelineRepositoryAdapter wraps a persistence adapter (typically the DynamoDB one) to satisfy the TimelineRepository port used by the album use cases. LoadTimeline reads the owner's albums and builds a TimelineAggregate eagerly; the write methods are inherited from the embedded adapter.

func (*TimelineRepositoryAdapter) LoadTimeline added in v1.9.53

type TransferMediasFromRepository added in v1.9.52

type TransferMediasFromRepository struct {
	TransferMediasRepository TransferMediasRepositoryPort
}

TransferMediasFromRepository is the default TransferMediasService implementation: it delegates the actual move to the repository port and derives the FromAlbums list from the input records.

func (*TransferMediasFromRepository) TransferMedias added in v1.9.52

type TransferMediasFunc added in v1.5.41

type TransferMediasFunc func(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)

func (TransferMediasFunc) TransferMediasFromRecords added in v1.5.41

func (f TransferMediasFunc) TransferMediasFromRecords(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)

type TransferMediasRepositoryPort added in v1.5.45

type TransferMediasRepositoryPort interface {
	TransferMediasFromRecords(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)
}

TransferMediasRepositoryPort moves the medias matched by records to their new album and returns, per destination album, the list of MediaIds that were actually moved.

type TransferMediasService added in v1.9.52

type TransferMediasService interface {
	TransferMedias(ctx context.Context, records MediaTransferRecords) (TransferredMedias, error)
}

TransferMediasService is the internal domain service that moves medias between albums. It returns the destinations that were actually written along with the list of source albums the caller intended to pick medias from (derived from the input records).

type TransferredMedias added in v1.5.33

type TransferredMedias struct {
	Transfers  map[AlbumId][]MediaId
	FromAlbums []AlbumId // FromAlbums is a list of potential origins of medias
}

TransferredMedias is a list of all medias that has be transferred to a different album in the state.

func NewTransferredMedias added in v1.6.4

func NewTransferredMedias() TransferredMedias

func (TransferredMedias) IsEmpty added in v1.5.41

func (t TransferredMedias) IsEmpty() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL