Documentation ¶
Overview ¶
Package catalog provides tools to maintain an index of all medias that have been backed up.
Index ¶
- Variables
- func AssignIdsToNewMedias(owner Owner, signatures []*MediaSignature) (map[MediaSignature]string, error)
- func Create(request CreateAlbumRequest) error
- func DeleteAlbum(albumId AlbumId, emptyOnly bool) error
- func GenerateMediaId(signature MediaSignature) (string, error)
- func Init(repositoryAdapter RepositoryAdapter, archive CArchiveAdapter)
- func InsertMedias(owner Owner, medias []CreateMediaRequest) error
- func RenameAlbum(currentId AlbumId, newName string, renameFolder bool) error
- func UpdateAlbum(albumId AlbumId, start, end time.Time) error
- type Album
- type AlbumId
- type CArchiveAdapter
- type CreateAlbum
- type CreateAlbumRequest
- type CreateMediaRequest
- type FindAlbumsByOwnerPort
- type FindAlbumsByOwnerPortFunc
- type FindMediaRequest
- type FolderName
- type InsertAlbumPort
- type InsertAlbumPortFunc
- type ListMediaIdsPort
- type MediaDetails
- type MediaId
- type MediaMeta
- type MediaOrientation
- type MediaPage
- type MediaSelector
- type MediaSignature
- type MediaTransferRecords
- type MediaType
- type MoveMediaPort
- type MoveMediaPortFunc
- type Owner
- type PageRequest
- type PrioritySegment
- type RepositoryAdapter
- type TimeRange
- type Timeline
- func (t *Timeline) AppendAlbum(album *Album) (*Timeline, error)
- func (t *Timeline) FindAllAt(date time.Time) []*Album
- func (t *Timeline) FindAt(date time.Time) (*Album, bool)
- func (t *Timeline) FindBetween(start, end time.Time) (segments []PrioritySegment, missed []PrioritySegment)
- func (t *Timeline) FindForAlbum(albumId AlbumId) (segments []PrioritySegment)
- type TimelineMutationObserver
- type TimelineMutator
- type TransferMediaListener
- type TransferMediasPort
- type TransferredMedias
Constants ¶
This section is empty.
Variables ¶
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") )
var ( NotFoundError = errors.New("album hasn't been found") NotEmptyError = errors.New("album is not empty") EmptyOwnerError = errors.New("owner is mandatory and must be not empty") EmptyFolderNameError = errors.New("folderName is mandatory and must be not empty") )
var (
MediaNotFoundError = fmt.Errorf("media not found")
)
Functions ¶
func AssignIdsToNewMedias ¶
func AssignIdsToNewMedias(owner Owner, signatures []*MediaSignature) (map[MediaSignature]string, error)
AssignIdsToNewMedias filters out signatures that are already known and compute a unique ID for the others.
func Create ¶
func Create(request CreateAlbumRequest) error
Create is a temporary plug before using UseCase classes.
func DeleteAlbum ¶
DeleteAlbum delete an album, medias it contains are dispatched to other albums.
func GenerateMediaId ¶
func GenerateMediaId(signature MediaSignature) (string, error)
GenerateMediaId generate a unique ID for a media.
func Init ¶
func Init(repositoryAdapter RepositoryAdapter, archive CArchiveAdapter)
Init must be called before using this package.
func InsertMedias ¶
func InsertMedias(owner Owner, medias []CreateMediaRequest) error
InsertMedias stores metadata and location of photo and videos
func RenameAlbum ¶
RenameAlbum updates the displayed named of the album. Optionally changes the folder in which media will be stored and flag all its media to be moved to the new one.
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 TotalCount int // TotalCount is the number of media (of any type) }
Album is a logical grouping of medias ; also used to physically store media next to each others.
func FindAlbum ¶
FindAlbum get an album by its business key (its folder name), or returns NotFoundError
func FindAlbums ¶
FindAlbums get several albums by their business keys
func FindAllAlbums ¶
FindAllAlbums find all albums owned by root user
type AlbumId ¶
type AlbumId struct { Owner Owner FolderName FolderName }
func FindMediaOwnership ¶
FindMediaOwnership returns the folderName containing the media, or NotFoundError.
func NewAlbumIdFromStrings ¶ added in v1.5.33
NewAlbumIdFromStrings creates an AlbumId from 2 strings ; it doesn't guaranty its validity, use AlbumId.IsValid to check if any error.
type CArchiveAdapter ¶
type CArchiveAdapter interface { TimelineMutationObserver MoveMedias(owner Owner, ids []MediaId, name FolderName) error }
CArchiveAdapter forward events to archive package
type CreateAlbum ¶
type CreateAlbum struct { FindAlbumsByOwnerPort FindAlbumsByOwnerPort InsertAlbumPort InsertAlbumPort TransferMediasPort TransferMediasPort TimelineMutationObservers []TimelineMutationObserver }
func (*CreateAlbum) Create ¶ added in v1.5.33
func (c *CreateAlbum) Create(ctx context.Context, request CreateAlbumRequest) error
Create creates a new album
type CreateAlbumRequest ¶ added in v1.5.33
type CreateAlbumRequest struct { Owner Owner Name string Start time.Time End time.Time ForcedFolderName string }
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 FindAlbumsByOwnerPort ¶ added in v1.5.33
type FindAlbumsByOwnerPortFunc ¶ added in v1.5.33
func (FindAlbumsByOwnerPortFunc) FindAlbumsByOwner ¶ added in v1.5.33
type FindMediaRequest ¶
type FindMediaRequest struct { Owner 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 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 InsertAlbumPort ¶ added in v1.5.33
type InsertAlbumPortFunc ¶ added in v1.5.33
func (InsertAlbumPortFunc) InsertAlbum ¶ added in v1.5.33
func (f InsertAlbumPortFunc) InsertAlbum(ctx context.Context, album Album) error
type ListMediaIdsPort ¶ added in v1.5.33
type ListMediaIdsPort interface {
ListMediaIdsFromSelector(ctx context.Context, selector []MediaSelector) ([]MediaId, 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 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 catalog
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
func ListMedias ¶
func ListMedias(albumId AlbumId, request PageRequest) (*MediaPage, error)
ListMedias return a page of medias within an album
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 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 ¶
func DecodeMediaId ¶
func DecodeMediaId(encodedId string) (*MediaSignature, error)
DecodeMediaId reverse what the GenerateMediaId has done to find original signature.
func FindSignatures ¶
func FindSignatures(owner Owner, signatures []*MediaSignature) ([]*MediaSignature, error)
FindSignatures returns a list of the medias already known ; they can't be duplicated
func (MediaSignature) String ¶
func (s MediaSignature) String() 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 MoveMediaPort ¶ added in v1.5.33
type MoveMediaPortFunc ¶ added in v1.5.33
type PageRequest ¶
type PrioritySegment ¶
type RepositoryAdapter ¶
type RepositoryAdapter interface { TransferMediasPort FindAlbumsByOwner(owner Owner) ([]*Album, error) InsertAlbum(album Album) error DeleteEmptyAlbum(id AlbumId) error // FindAlbums only returns found albums FindAlbums(ids ...AlbumId) ([]*Album, error) // UpdateAlbum updates data of matching Album.FolderName UpdateAlbum(album Album) error // InsertMedias bulks insert medias InsertMedias(owner Owner, media []CreateMediaRequest) error // FindMedias is a paginated search for media with their details FindMedias(request *FindMediaRequest) (medias []*MediaMeta, err error) // FindMediaIds is a paginated search to only get the media ids FindMediaIds(request *FindMediaRequest) (ids []MediaId, err error) // FindMediaCurrentAlbum returns the folderName the media is currently in FindMediaCurrentAlbum(owner Owner, mediaId MediaId) (id *AlbumId, err error) // FindExistingSignatures returns the signatures that are already known FindExistingSignatures(owner Owner, signatures []*MediaSignature) ([]*MediaSignature, error) // TransferMedias to a different album, and returns list of moved media ids TransferMedias(owner Owner, mediaIds []MediaId, newFolderName FolderName) error }
RepositoryAdapter brings persistence layer to catalog package
type TimeRange ¶
TimeRange is of days, start is inclusive (at the second), end is exclusive (at the second)
func NewTimeRangeFromAlbum ¶
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 ¶
NewTimeline creates a Timeline object used to compute overlaps between Album. List of albums must be sorted by Start date ASC (End sorting do not matter).
func (*Timeline) AppendAlbum ¶
AppendAlbum generates a new timeline from memory
func (*Timeline) FindBetween ¶
func (t *Timeline) FindBetween(start, end time.Time) (segments []PrioritySegment, missed []PrioritySegment)
func (*Timeline) FindForAlbum ¶
func (t *Timeline) FindForAlbum(albumId AlbumId) (segments []PrioritySegment)
type TimelineMutationObserver ¶ added in v1.5.33
type TimelineMutationObserver interface {
Observe(ctx context.Context, transfers TransferredMedias) error
}
type TimelineMutator ¶ added in v1.5.33
type TimelineMutator struct {
Current []*Album
}
TimelineMutator is used to measure the impact of a change on the timeline
func NewTimelineMutator ¶ added in v1.5.33
func NewTimelineMutator(current []*Album) *TimelineMutator
func (*TimelineMutator) AddNew ¶ added in v1.5.33
func (t *TimelineMutator) AddNew(album Album) (MediaTransferRecords, error)
type TransferMediaListener ¶ added in v1.5.33
type TransferMediaListener struct {
ListMediaIds ListMediaIdsPort
}
func (*TransferMediaListener) TransferMedia ¶ added in v1.5.33
func (t *TransferMediaListener) TransferMedia(ctx context.Context, selector []MediaSelector) error
type TransferMediasPort ¶ added in v1.5.33
type TransferMediasPort interface {
TransferMediasFromRecords(ctx context.Context, records MediaTransferRecords) (TransferredMedias, error)
}