catalog

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFoundError = errors.New("Album hasn't been found")
	NotEmptyError = errors.New("Album is not empty")
)

Functions

func Create

func Create(createRequest CreateAlbum) error

Create creates a new album

func DeleteAlbum

func DeleteAlbum(folderNameToDelete string, emptyOnly bool) error

DeleteAlbum delete an album, medias it contains are dispatched to other albums.

func InsertMedias

func InsertMedias(medias []CreateMediaRequest) error

InsertMedias stores metadata and location of photo and videos

func RelocateMovedMedias

func RelocateMovedMedias(operator MoveMediaOperator, transactionId string) (int, error)

RelocateMovedMedias drives the physical re-location of all medias that have been flagged.

func RenameAlbum

func RenameAlbum(folderName, newName string, renameFolder bool) error

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.

func UpdateAlbum

func UpdateAlbum(folderName string, start, end time.Time) error

UpdateAlbum updates the dates of an album, medias will be re-assign between albums accordingly

Types

type Album

type Album struct {
	Name       string
	FolderName string // unique and immutable
	Start      time.Time
	End        time.Time
}

Album defines how medias are physically stored.

func FindAlbum

func FindAlbum(folderName string) (*Album, error)

FindAlbum get an album by its business key (its folder name), or returns NotFoundError

func FindAllAlbums

func FindAllAlbums() ([]*Album, error)

FindAllAlbums find all albums owned by root user

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 AlbumStat

type AlbumStat struct {
	Album Album
	// contains filtered or unexported fields
}

AlbumStat has the counts of media on the album ; it's currently limited to total number because of the database.

func FindAllAlbumsWithStats

func FindAllAlbumsWithStats() ([]*AlbumStat, error)

FindAllAlbumsWithStats returns the list of albums, with statistics for each

func (*AlbumStat) TotalCount

func (s *AlbumStat) TotalCount() int

TotalCount return the number of medias, no matter their type, in the album.

type CreateAlbum

type CreateAlbum struct {
	Name             string
	Start            time.Time
	End              time.Time
	ForcedFolderName string
}

func (*CreateAlbum) String

func (c *CreateAlbum) String() string

type CreateMediaRequest

type CreateMediaRequest struct {
	Location  MediaLocation
	Type      MediaType
	Details   MediaDetails
	Signature MediaSignature
}

type FindMediaFilter

type FindMediaFilter struct {
	PageRequest PageRequest // PageRequest size will use a default if too high or not set (0)
	TimeRange   TimeRange   // TimeRange is optional
}

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

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')
}

type MediaLocation

type MediaLocation struct {
	FolderName string
	Filename   string
}

type MediaMeta

type MediaMeta struct {
	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
}

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(folderName string, request PageRequest) (*MediaPage, error)

ListMedias return a page of medias within an album

type MediaSignature

type MediaSignature struct {
	SignatureSha256 string
	SignatureSize   int
}

func FindSignatures

func FindSignatures(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 MediaSignatureAndLocation

type MediaSignatureAndLocation struct {
	Location  MediaLocation
	Signature MediaSignature
}

type MediaType

type MediaType string

type MoveMediaOperator

type MoveMediaOperator interface {
	// Move must perform the physical move of the file to a different directory ; return the final name if it has been changed
	Move(source, dest MediaLocation) (string, error)

	// UpdateStatus informs of the global status of the move operation
	UpdateStatus(done, total int) error
	// Continue requests if the operation should continue or be interrupted
	Continue() bool
}

type MoveTransaction

type MoveTransaction struct {
	TransactionId string
	Count         int // Number of medias to be moved as part of this transaction
}

func FindMoveTransactions

func FindMoveTransactions() ([]*MoveTransaction, error)

FindMoveTransactions lists transactions of media requiring to be physically moved.

type MovedMedia

type MovedMedia struct {
	Signature        MediaSignature
	SourceFolderName string
	SourceFilename   string
	TargetFolderName string
	TargetFilename   string
}

type PageRequest

type PageRequest struct {
	Size     int64  // defaulted to 50 if not defined
	NextPage string // empty for the first page
}

type PrioritySegment

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

type RepositoryPort

type RepositoryPort interface {
	FindAllAlbums() ([]*Album, error)
	InsertAlbum(album Album) error
	DeleteEmptyAlbum(folderName string) error
	// FindAlbum returns (nil, NotFoundError) when not found
	FindAlbum(folderName string) (*Album, error)
	// UpdateAlbum updates data of matching Album.FolderName
	UpdateAlbum(album Album) error
	// CountMedias counts number of media within the album
	CountMedias(folderName string) (int, error)

	// InsertMedias bulks insert medias
	InsertMedias(media []CreateMediaRequest) error
	// FindMedias is a paginated search of medias within an album, and optionally within a time range
	FindMedias(folderName string, filter FindMediaFilter) (*MediaPage, error)
	// FindExistingSignatures returns the signatures that are already known
	FindExistingSignatures(signatures []*MediaSignature) ([]*MediaSignature, error)
	// UpdateMedias updates metadata and mark the media to be moved, the AlbumFolderName is never updated (part of the primary key)
	UpdateMedias(filter *UpdateMediaFilter, newFolderName string) (string, int, error)

	FindReadyMoveTransactions() ([]*MoveTransaction, error)
	FindFilesToMove(transactionId, pageToken string) ([]*MovedMedia, string, error)
	UpdateMediasLocation(transactionId string, moves []*MovedMedia) error
	DeleteEmptyMoveTransaction(transactionId string) error
}
var (
	Repository RepositoryPort
)

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(albums []*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 do not matter).

func (*Timeline) AppendAlbum

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

AppendAlbum generates a new timeline from memory

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) FindBetween

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

func (*Timeline) FindForAlbum

func (t *Timeline) FindForAlbum(folderName string) (segments []PrioritySegment)

type UpdateMediaFilter

type UpdateMediaFilter struct {
	AlbumFolderNames map[string]interface{} // AlbumFolderNames is a set of folder names (map value is nil)
	Ranges           []TimeRange            // empty = no restriction
}

UpdateMediaFilter is used internally to update a range of folders

func NewUpdateFilter

func NewUpdateFilter() *UpdateMediaFilter

func (*UpdateMediaFilter) String

func (m *UpdateMediaFilter) String() string

func (*UpdateMediaFilter) WithAlbum

func (m *UpdateMediaFilter) WithAlbum(folderNames ...string) *UpdateMediaFilter

func (*UpdateMediaFilter) WithinRange

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

Directories

Path Synopsis
dynamo
Package dynamodb package store all the data in a single multi-tenant table: - OWNER > Album X meta > Album Y meta - MEDIA (OWNER#SIGNATURE) > #META > LOCATION > MOVE LOCATION > MOVE LOCATION - MOVE TRANSACTION (...#uniqueID)
Package dynamodb package store all the data in a single multi-tenant table: - OWNER > Album X meta > Album Y meta - MEDIA (OWNER#SIGNATURE) > #META > LOCATION > MOVE LOCATION > MOVE LOCATION - MOVE TRANSACTION (...#uniqueID)

Jump to

Keyboard shortcuts

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