catalog

package
v1.5.16 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: AGPL-3.0 Imports: 11 Imported by: 4

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")
)
View Source
var (
	MediaNotFoundError = fmt.Errorf("media not found")
)

Functions

func AssignIdsToNewMedias

func AssignIdsToNewMedias(owner string, 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(createRequest CreateAlbum) error

Create creates a new album

func DeleteAlbum

func DeleteAlbum(owner string, folderNameToDelete string, emptyOnly bool) error

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

func FindMediaOwnership

func FindMediaOwnership(owner, mediaId string) (string, error)

FindMediaOwnership returns the folderName containing the media, or NotFoundError.

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 string, medias []CreateMediaRequest) error

InsertMedias stores metadata and location of photo and videos

func RenameAlbum

func RenameAlbum(owner string, 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(owner string, 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 {
	Owner      string    // Owner is a PK with FolderName
	Name       string    // Name for displaying purpose, not unique
	FolderName string    // FolderName is unique with Owner, and immutable
	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 defines how medias are physically re-grouped.

func FindAlbum

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

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

func FindAlbums

func FindAlbums(keys []AlbumId) ([]*Album, error)

FindAlbums get several albums by their business keys

func FindAllAlbums

func FindAllAlbums(owner string) ([]*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 AlbumId

type AlbumId struct {
	Owner      string
	FolderName string
}

func (*AlbumId) String

func (a *AlbumId) String() string

type CArchiveAdapter

type CArchiveAdapter interface {
	MoveMedias(owner string, ids []string, name string) error
}

CArchiveAdapter forward events to archive package

type CreateAlbum

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

func (*CreateAlbum) String

func (c *CreateAlbum) String() string

type CreateMediaRequest

type CreateMediaRequest struct {
	Id         string         // Id is generated from its signature with GenerateMediaId(MediaSignature)
	Signature  MediaSignature // Signature is the business key of a media
	FolderName string         // 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 the It's within an Owner context.

type FindMediaRequest

type FindMediaRequest struct {
	Owner            string
	AlbumFolderNames map[string]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 string) *FindMediaRequest

func (*FindMediaRequest) String

func (m *FindMediaRequest) String() string

func (*FindMediaRequest) WithAlbum

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

func (*FindMediaRequest) WithinRange

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

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        string         // 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(owner string, 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 DecodeMediaId

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

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

func FindSignatures

func FindSignatures(owner string, 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 MediaType

type MediaType string

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 RepositoryAdapter

type RepositoryAdapter interface {
	FindAlbumsByOwner(owner string) ([]*Album, error)
	InsertAlbum(album Album) error
	DeleteEmptyAlbum(owner string, folderName string) 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 string, 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 []string, err error)
	// FindMediaCurrentAlbum returns the folderName the media is currently in
	FindMediaCurrentAlbum(owner, mediaId string) (folderName string, err error)
	// FindExistingSignatures returns the signatures that are already known
	FindExistingSignatures(owner string, signatures []*MediaSignature) ([]*MediaSignature, error)
	// TransferMedias to a different album, and returns list of moved media ids
	TransferMedias(owner string, mediaIds []string, newFolderName string) error
}

RepositoryAdapter brings persistence layer to catalog package

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 NewTimeRangeFromAlbum

func NewTimeRangeFromAlbum(album Album) TimeRange

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(owner, folderName string) (segments []PrioritySegment)

Jump to

Keyboard shortcuts

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