apis

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFolderNotFound = errors.New("Folder not found")

ErrFolderNotFound means that a folder could not be found

View Source
var ErrInvalidArgs = errors.New("Invalid arguments")

ErrInvalidArgs ia generic error for invalid argument values

View Source
var ErrInvalidFolderPath = errors.New("Invalid folder path")

ErrInvalidFolderPath means invalid path

View Source
var ErrInvalidID = errors.New("Invalid id")

ErrInvalidID is an error if the provided id is invalid

View Source
var ErrInvalidListParams = errors.New("Invalid list params")

ErrInvalidListParams indicates that the list parameters were invalid

View Source
var ErrNoVisibilityTokens = errors.New("No visibility tokens provided")

ErrNoVisibilityTokens is an error if there are no visibility tokens provided

View Source
var ErrPhotoInvalidResizeMaxLength = errors.New("Invalid resize max length")

ErrPhotoInvalidResizeMaxLength signifies an invalid resize max length

View Source
var ErrSessionNotFound = errors.New("No session found")

ErrSessionNotFound means that there was no session

View Source
var ErrUserExisting = errors.New("There is already at least one existing user")

ErrUserExisting means that no new users can be added because at least one user already exists

View Source
var ErrUserInvalidPassword = errors.New("Invalid password")

ErrUserInvalidPassword represents invalid password error

Functions

func FilterByVisibilityTokens

func FilterByVisibilityTokens(filter bson.M, tokens []string) error

FilterByVisibilityTokens adds to a filter for the given array of visibility tokens There must be at least token in the tokens array.

Assumes the field name is "visTokens".

Types

type APIs

type APIs struct {
	Categories Categories
	Dates      Dates
	Folders    Folders
	Keywords   Keywords
	Locations  Locations
	Photos     Photos
	Users      Users
	Visibility Visibility
}

APIs is the combination of all APIs

type Categories

type Categories interface {
	Collection() *mongo.Collection
	Create(ctx context.Context, catValue string) (string, error)
	Get(ctx context.Context, id string, projKeys []string, tokens []string) (*docs.CategoryEntry, error)
	GetMulti(ctx context.Context, ids []string, projKeys []string, tokens []string) ([]docs.CategoryEntry, error)
	GetOrCreate(ctx context.Context, catValue string, projKeys []string) (*docs.CategoryEntry, error)
	ListChildren(ctx context.Context, params *GroupListParams) ([]docs.CategoryEntry, error)
	DiffAndUpdate(ctx context.Context, oldIDs []string, newIDs []string, oldTokens []string, newTokens []string, count int) error
	Update(ctx context.Context, id string, update *GroupUpdate) error
}

Categories API

type Dates

type Dates interface {
	Collection() *mongo.Collection
	Create(ctx context.Context, date string) (string, error)
	Get(ctx context.Context, id string, projKeys []string, tokens []string) (*docs.Date, error)
	GetOrCreate(ctx context.Context, date string, projKeys []string) (*docs.Date, error)
	ListChildren(ctx context.Context, params *GroupListParams) ([]docs.Date, error)
	DiffAndUpdate(ctx context.Context, oldID *string, newID *string, oldTokens []string, newTokens []string, count int) error
}

Dates API

type FolderVisibilityTokenTarget

type FolderVisibilityTokenTarget int

FolderVisibilityTokenTarget determines what to target for visibility tokens

const (
	// FolderTarget targets just the folder itself
	FolderTarget FolderVisibilityTokenTarget = iota

	// FolderTargetPhotos targets the folder and photos directly in it
	FolderTargetPhotos

	// FolderTargetFullTree targets the folder, photos and sub-folders in its full tree
	FolderTargetFullTree
)

func (FolderVisibilityTokenTarget) Validate

func (target FolderVisibilityTokenTarget) Validate() error

Validate target

type Folders

type Folders interface {
	Collection() *mongo.Collection
	Exists(ctx context.Context, id string) bool
	Create(ctx context.Context, path string) (string, error)
	Get(ctx context.Context, id string, projKeys []string, tokens []string) (*docs.Folder, error)
	GetOrCreate(ctx context.Context, path string, projKeys []string) (*docs.Folder, error)
	ListChildren(ctx context.Context, params *GroupListParams) ([]docs.Folder, error)
	DiffAndUpdate(ctx context.Context, oldID *string, newID *string, oldTokens []string, newTokens []string, count int) error
	Update(ctx context.Context, id string, update *GroupUpdate) error

	// Visibility tokens
	AddVisibilityToken(ctx context.Context, id string, target FolderVisibilityTokenTarget, token string) error
	DeleteVisibilityToken(ctx context.Context, id string, target FolderVisibilityTokenTarget, token string) error
}

Folders API

type GroupListParams added in v1.0.0

type GroupListParams struct {
	Limit          int64            `json:"limit,omitempty"`
	RefID          string           `json:"refId,omitempty"`
	RefOp          list.RefOperator `json:"refOp,omitempty"` // defaults to list.OpGt
	ProjectionKeys []string         `json:"projKeys,omitempty"`
	ID             string           `json:"id,omitempty"`

	// Visibility tokens. Must have at least one token.
	VisibilityTokens []string `json:"visibilityTokens,omitempty"`
}

GroupListParams contains parameters for listing group children

func (*GroupListParams) AssignDefaults added in v1.0.0

func (params *GroupListParams) AssignDefaults()

AssignDefaults to parameters

func (*GroupListParams) Validate added in v1.0.0

func (params *GroupListParams) Validate() error

Validate parameters

type GroupUpdate added in v1.4.0

type GroupUpdate struct {
	Display   *string `json:"display,omitempty"`
	SortOrder *int    `json:"sortOrder,omitempty"` // a value of zero will remove the sort order value
}

GroupUpdate describes the fields that can be updated

func NewGroupUpdate added in v1.4.0

func NewGroupUpdate() *GroupUpdate

NewGroupUpdate creates a new update struct

func (*GroupUpdate) SetDisplay added in v1.4.0

func (gu *GroupUpdate) SetDisplay(d string) *GroupUpdate

SetDisplay sets the display

func (*GroupUpdate) SetSortOrder added in v1.4.0

func (gu *GroupUpdate) SetSortOrder(o int) *GroupUpdate

SetSortOrder sets the sort order

type Keywords

type Keywords interface {
	Collection() *mongo.Collection
	Create(ctx context.Context, name string) (string, error)
	Get(ctx context.Context, id string, projKeys []string, tokens []string) (*docs.Keyword, error)
	GetMulti(ctx context.Context, ids []string, projKeys []string, tokens []string) ([]docs.Keyword, error)
	GetOrCreate(ctx context.Context, name string, projKeys []string) (*docs.Keyword, error)
	ListChildren(ctx context.Context, params *GroupListParams) ([]docs.Keyword, error)
	DiffAndUpdate(ctx context.Context, oldIDs []string, newIDs []string, oldTokens []string, newTokens []string, count int) error
	Update(ctx context.Context, id string, update *GroupUpdate) error
}

Keywords API

type Locations

type Locations interface {
	Collection() *mongo.Collection
	Create(ctx context.Context, loc string) (string, error)
	Get(ctx context.Context, id string, projKeys []string, tokens []string) (*docs.Location, error)
	GetOrCreate(ctx context.Context, loc string, projKeys []string) (*docs.Location, error)
	ListChildren(ctx context.Context, params *GroupListParams) ([]docs.Location, error)
	DiffAndUpdate(ctx context.Context, oldID *string, newID *string, oldTokens []string, newTokens []string, count int) error
	Update(ctx context.Context, id string, update *GroupUpdate) error
}

Locations API

type PhotoListFilterAspectRatio added in v0.11.0

type PhotoListFilterAspectRatio struct {
	Value float32                 `json:"value"`
	CmpOp list.ComparisonOperator `json:"cmpOp"`
}

PhotoListFilterAspectRatio filters by aspect ratio (photo width/height)

func (PhotoListFilterAspectRatio) Validate added in v0.11.0

func (ar PhotoListFilterAspectRatio) Validate() error

Validate aspect ratio filter

type PhotoListFilterDate

type PhotoListFilterDate struct {
	// yyyy[mm[dd]]
	Value string                  `json:"value"`
	CmpOp list.ComparisonOperator `json:"cmpOp"`
}

PhotoListFilterDate filters by date (which really filters by sortKey)

func (PhotoListFilterDate) Validate

func (date PhotoListFilterDate) Validate() error

Validate date filter

type PhotoListFilterExpr

type PhotoListFilterExpr struct {
	// Op defines the logical operation used to join all of the filter clauses
	Op list.LogicalOperator `json:"op,omitempty"` // defaults to list.LogicalAnd

	// The filter expression itself can contain nested filter expressions
	Exprs []*PhotoListFilterExpr `json:"exprs,omitempty"`

	// Property-specific filters
	Folders      []PhotoListFilterFolder      `json:"folders,omitempty"`
	Ratings      []PhotoListFilterRating      `json:"ratings,omitempty"`
	Keywords     []string                     `json:"keywords,omitempty"`   // ids
	Locations    []string                     `json:"locations,omitempty"`  // prefix ids
	Categories   []string                     `json:"categories,omitempty"` // ids
	Dates        []PhotoListFilterDate        `json:"dates,omitempty"`
	AspectRatios []PhotoListFilterAspectRatio `json:"aspectRatios,omitempty"`
}

PhotoListFilterExpr represents a filter expression

func (*PhotoListFilterExpr) AssignDefaults

func (expr *PhotoListFilterExpr) AssignDefaults()

AssignDefaults to expression

func (*PhotoListFilterExpr) Validate

func (expr *PhotoListFilterExpr) Validate() error

Validate expression

type PhotoListFilterFolder

type PhotoListFilterFolder struct {
	Path     string `json:"path"` // slug path
	FullTree bool   `json:"fullTree"`
}

PhotoListFilterFolder filters by folder path

func (PhotoListFilterFolder) Validate added in v1.0.0

func (folder PhotoListFilterFolder) Validate() error

Validate folder filter

type PhotoListFilterRating

type PhotoListFilterRating struct {
	Value int                     `json:"value"` // >= 0
	CmpOp list.ComparisonOperator `json:"cmpOp"`
}

PhotoListFilterRating filters by photo rating

func (PhotoListFilterRating) Validate

func (rating PhotoListFilterRating) Validate() error

Validate rating filter

type PhotoListKey

type PhotoListKey string

PhotoListKey is an enum for the listing key

const (
	PhotoListKeySortKey   PhotoListKey = "sortKey"
	PhotoListKeyTimestamp PhotoListKey = "timestamp"
)

List keys

func (PhotoListKey) Validate

func (key PhotoListKey) Validate() error

Validate photo list key value

type PhotoListParams

type PhotoListParams struct {
	Limit int64 `json:"limit,omitempty"` // >= 0 (0 means no limit)

	// RefKeyValue expectations for different RefKeys
	// - ListKeySortKey: RefKeyValue should be a string with the sort key
	// - ListKeyTimestamp: RefKeyValue should be a string with the timestamp value (in RFC3339 layout)
	RefKey      PhotoListKey `json:"refKey,omitempty"` // defaults to ListKeySortKey
	RefKeyValue string       `json:"refKeyValue,omitempty"`

	RefOp          list.RefOperator    `json:"refOp,omitempty"` // defaults to list.OpGt
	ProjectionKeys []string            `json:"projKeys,omitempty"`
	Filter         PhotoListFilterExpr `json:"filter"`

	// Visibility tokens. Must have at least one token.
	VisibilityTokens []string `json:"visTokens"`
}

PhotoListParams contains parameters for listing photos

func (*PhotoListParams) AssignDefaults

func (params *PhotoListParams) AssignDefaults()

AssignDefaults to list parameters

func (*PhotoListParams) Validate

func (params *PhotoListParams) Validate() error

Validate list parameters

type PhotoRandomListParams added in v0.11.0

type PhotoRandomListParams struct {
	Count int64 `json:"count"` // > 0

	ProjectionKeys []string            `json:"projKeys,omitempty"`
	Filter         PhotoListFilterExpr `json:"filter"`

	// Visibility tokens. Must have at least one token.
	VisibilityTokens []string `json:"visTokens"`
}

PhotoRandomListParams contains parameters for random list photos

func (*PhotoRandomListParams) AssignDefaults added in v0.11.0

func (params *PhotoRandomListParams) AssignDefaults()

AssignDefaults to list parameters

func (*PhotoRandomListParams) Validate added in v0.11.0

func (params *PhotoRandomListParams) Validate() error

Validate list parameters

type Photos

type Photos interface {
	Collection() *mongo.Collection
	AddOrUpdate(ctx context.Context, bucketID string, objectID string, objectGenVal uint64, fileSize int, md *photomd.Metadata) (*docs.Photo, error)
	AddOrUpdateAndResize(ctx context.Context, bucketID string, objectID string, objectGenVal uint64) (*docs.Photo, error)
	Delete(ctx context.Context, bucketID string, objectID string) error
	Get(ctx context.Context, id docs.PhotoID, projKeys []string, tokens []string) (*docs.Photo, error)

	// Photo resizing
	ResizeCacheCollection() *mongo.Collection
	GetResizeCacheEntry(ctx context.Context, id docs.PhotoID, maxLength int) *docs.PhotoResizeCacheEntry
	GetResizedImage(ctx context.Context, id docs.PhotoID, maxLength int, tokens []string) (io.ReadCloser, int, bool, error)

	// Listing
	List(ctx context.Context, params *PhotoListParams) ([]docs.Photo, error)
	RandomList(ctx context.Context, params *PhotoRandomListParams) ([]docs.Photo, error)

	// Visibility tokens
	AddInheritedVisibilityToken(ctx context.Context, folderSlugPath string, fullTree bool, token string) error
	DeleteInheritedVisibilityToken(ctx context.Context, folderSlugPath string, fullTree bool, token string) error
}

Photos API

type Users

type Users interface {
	Collection() *mongo.Collection
	SessionCollection() *mongo.Collection
	GetUserCount(ctx context.Context) (int64, error)
	AddUser(ctx context.Context, id string, password string) error
	Login(ctx context.Context, id string, password string) (*docs.Session, error)
	IsAdmin(ctx context.Context, id docs.UserID) bool

	// Sessions
	GetSession(ctx context.Context, sessionID docs.SessionID) *docs.Session
	RefreshSession(ctx context.Context, sessionID docs.SessionID) error
	EndSession(ctx context.Context, sessionID docs.SessionID) error
	CleanupExpiredSessions(ctx context.Context) error
}

Users API

type Visibility

type Visibility interface {
	Collection() *mongo.Collection
	Create(ctx context.Context, name string) (string, error)
	Get(ctx context.Context, id string, projKeys []string) (*docs.VisibilityToken, error)
	GetOrCreate(ctx context.Context, name string, projKeys []string) (*docs.VisibilityToken, error)
	GetByActivationValue(ctx context.Context, actValue string, projKeys []string) (*docs.VisibilityToken, error)
	List(ctx context.Context, projKeys []string) ([]docs.VisibilityToken, error)
	DiffAndUpdate(ctx context.Context, oldIDs []string, newIDs []string, count int) error

	// Initial values only allow setting Redirect and Comment
	CreateLink(ctx context.Context, id string, initial *docs.VisibilityTokenLink) (*docs.VisibilityTokenLink, error)

	// Update only allows changing Redirect, Comment or Disabled
	UpdateLink(ctx context.Context, actValue string, toUpdate *docs.VisibilityTokenLink) error

	// Returns token with ID and the activated link (activation count is not accurate), if the activation value
	// is valid and enabled.
	ActivateLink(ctx context.Context, actValue string) (*docs.VisibilityToken, error)
}

Visibility API

Jump to

Keyboard shortcuts

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