apis

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const VisTokenAll = docs.VisibilityTokenValue("*")

VisTokenAll is the placeholder token value representing "all" tokens. It should exist on all every entity.

View Source
const VisTokenPublic = docs.VisibilityTokenValue("P")

VisTokenPublic is the token value representing public access

Variables

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

ErrFolderNotFound means that a folder could not be found

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 []docs.VisibilityTokenValue) 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 "visibilityTokens".

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
	Get(ctx context.Context, slug string, projKeys []string) (*docs.CategoryEntry, error)
	DiffAndUpdate(ctx context.Context, oldCatValues []string, newCatValues []string, oldTokens []docs.VisibilityTokenValue, newTokens []docs.VisibilityTokenValue, count int) error
}

Categories API

type Dates

type Dates interface {
	Collection() *mongo.Collection
	Get(ctx context.Context, slugPath string, projKeys []string) (*docs.Date, error)
	DiffAndUpdate(ctx context.Context, oldDateStr *string, newDateStr *string, oldTokens []docs.VisibilityTokenValue, newTokens []docs.VisibilityTokenValue, count int) error
}

Dates API

type FolderListParams

type FolderListParams struct {
	Limit          int64            `json:"limit,omitempty"`
	RefSlugPath    string           `json:"refSlugPath,omitempty"`
	RefOp          list.RefOperator `json:"refOp,omitempty"` // defaults to list.OpGt
	ProjectionKeys []string         `json:"projKeys,omitempty"`
	SlugPath       string           `json:"slugPath,omitempty"`

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

FolderListParams contains parameters for listing sub folders

func (*FolderListParams) AssignDefaults

func (params *FolderListParams) AssignDefaults()

AssignDefaults to parameters

func (*FolderListParams) Validate

func (params *FolderListParams) Validate(api Folders) error

Validate parameters

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
	IsValidSlugPath(path string) bool
	Exists(ctx context.Context, slugPath string) bool
	Depth(path string) (int, error)
	CreatePath(ctx context.Context, path string) (string, error)
	Get(ctx context.Context, slugPath string, projKeys []string, tokens []docs.VisibilityTokenValue) (*docs.Folder, error)
	ListSubFolders(ctx context.Context, params *FolderListParams) ([]docs.Folder, error)
	DiffAndUpdate(ctx context.Context, oldSlug *string, newSlug *string, oldTokens []docs.VisibilityTokenValue, newTokens []docs.VisibilityTokenValue, count int) error

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

Folders API

type InvalidFolderPathError

type InvalidFolderPathError string

InvalidFolderPathError is the error type when the path string is invalid

func (InvalidFolderPathError) Error

func (err InvalidFolderPathError) Error() string

type InvalidFolderSlugPathError

type InvalidFolderSlugPathError string

InvalidFolderSlugPathError is the error type when the path string is invalid

func (InvalidFolderSlugPathError) Error

func (err InvalidFolderSlugPathError) Error() string

type Keywords

type Keywords interface {
	Collection() *mongo.Collection
	Get(ctx context.Context, kwSlug string, projKeys []string) (*docs.Keyword, error)
	DiffAndUpdate(ctx context.Context, oldKeywords []string, newKeywords []string, oldTokens []docs.VisibilityTokenValue, newTokens []docs.VisibilityTokenValue, count int) error
}

Keywords API

type Locations

type Locations interface {
	Collection() *mongo.Collection
	Get(ctx context.Context, slugPath string, projKeys []string) (*docs.Location, error)
	DiffAndUpdate(ctx context.Context, oldLoc *string, newLoc *string, oldTokens []docs.VisibilityTokenValue, newTokens []docs.VisibilityTokenValue, count int) error
}

Locations API

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"`   // slugs
	Locations  []string                `json:"locations,omitempty"`  // prefix slug paths
	Categories []string                `json:"categories,omitempty"` // either <category> or <category>/<value> slugs
	Dates      []PhotoListFilterDate   `json:"dates,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

type PhotoListFilterRating

type PhotoListFilterRating struct {
	Value int                     `json:"value"`
	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"`

	// 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 []docs.VisibilityTokenValue `json:"visibilityTokens,omitempty"`

	ResizedOnly bool `json:"resizedOnly"`
}

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 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 []docs.VisibilityTokenValue) (*docs.Photo, error)

	// Photo resizing
	ResizeCacheCollection() *mongo.Collection
	ResizeImage(oImg image.Image, maxLength uint32) image.Image
	GetResizeCacheEntry(ctx context.Context, id docs.PhotoID, maxLength uint32) *docs.PhotoResizeCacheEntry
	GetResizedImage(ctx context.Context, id docs.PhotoID, maxLength uint32, tokens []docs.VisibilityTokenValue) (io.ReadCloser, int, error)
	FillResizeCache(ctx context.Context, photo *docs.Photo, imgBytes []byte) error

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

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

Photos API

type Users

type Users interface {
	Collection() *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
	Get(ctx context.Context, id string, projKeys []string) (*docs.VisibilityToken, error)
	GetOrCreate(ctx context.Context, name string) (*docs.VisibilityToken, error)
}

Visibility API

Jump to

Keyboard shortcuts

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