blaze

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHandle = errors.New("invalid handle")

ErrInvalidHandle is returned if the provided handle is invalid.

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

ErrNotFound is returned if there is no blob for the provided handle.

View Source
var ErrUsedHandle = errors.New("used handle")

ErrUsedHandle is returned if the provided handle has already been used.

Functions

func AddFileIndexes added in v0.26.0

func AddFileIndexes(catalog *coal.Catalog)

AddFileIndexes will add files indexes to the specified catalog.

Types

type Blob added in v0.26.0

type Blob struct {
	Type  string `json:"type"`
	Bytes []byte `json:"bytes"`
}

Blob may be used instead of a bytes slice for inline storage if the type needs be stored as well.

type ClaimKey added in v0.26.0

type ClaimKey struct {
	heat.Base `json:"-" heat:"fire/blaze.claim,1h"`

	// The uploaded file.
	File coal.ID
}

ClaimKey is used to authorize file claims.

func (*ClaimKey) Validate added in v0.26.0

func (k *ClaimKey) Validate() error

Validate implements the heat.Key interface.

type CleanupJob added in v0.28.0

type CleanupJob struct {
	axe.Base `json:"-" axe:"fire/blaze.cleanup"`
	stick.NoValidation
}

CleanupJob is the periodic job enqueued to cleanup a storage.

type File added in v0.26.0

type File struct {
	coal.Base `json:"-" bson:",inline" coal:"files"`

	// The current state of the file e.g. "uploading".
	State State `json:"state"`

	// The last time the file was updated.
	Updated time.Time `json:"updated-at" bson:"updated_at"`

	// The MIME type of the file e.g. "image/png".
	Type string `json:"type"`

	// The total length of the file.
	Length int64 `json:"length"`

	// The service specific blob handle.
	Handle Handle `json:"handle"`
}

File tracks uploaded files and their state.

func (*File) Validate added in v0.28.0

func (f *File) Validate() error

Validate will validate the model.

type GridFS added in v0.26.0

type GridFS struct {
	// contains filtered or unexported fields
}

GridFS stores blobs in a GridFs bucket.

func NewGridFS added in v0.26.0

func NewGridFS(store *coal.Store, chunkSize int64) *GridFS

NewGridFS creates a new GridFS service.

func (*GridFS) Cleanup added in v0.26.0

func (g *GridFS) Cleanup(_ context.Context) error

Cleanup implements the Service interface.

func (*GridFS) Delete added in v0.26.0

func (g *GridFS) Delete(ctx context.Context, handle Handle) (bool, error)

Delete implements the Service interface.

func (*GridFS) Download added in v0.26.0

func (g *GridFS) Download(ctx context.Context, handle Handle, w io.Writer) error

Download implements the Service interface.

func (*GridFS) Prepare added in v0.26.0

func (g *GridFS) Prepare(_ context.Context) (Handle, error)

Prepare implements the Service interface.

func (*GridFS) Upload added in v0.26.0

func (g *GridFS) Upload(ctx context.Context, handle Handle, _ string, r io.Reader) (int64, error)

Upload implements the Service interface.

type Handle added in v0.26.0

type Handle map[string]interface{}

Handle is a reference to a blob stored in a service.

type Link struct {
	// The type of the linked file.
	Type string `json:"type"`

	// The length of the linked file.
	Length int64 `json:"length"`

	// The key for claiming the linked file.
	ClaimKey string `json:"claim-key" bson:"-"`

	// The key for viewing the linked file.
	ViewKey string `json:"view-key" bson:"-"`

	// The reference to the linked file.
	File *coal.ID `json:"-" bson:"file_id"`
}

Link is used to link a file to a model.

type Memory added in v0.26.0

type Memory struct {
	// The stored blobs.
	Blobs map[string]Blob

	// The next id.
	Next int
}

Memory is a service for testing purposes that stores blobs in memory.

func NewMemory added in v0.26.0

func NewMemory() *Memory

NewMemory will create a new memory service.

func (*Memory) Cleanup added in v0.26.0

func (s *Memory) Cleanup(_ context.Context) error

Cleanup implements the Service interface.

func (*Memory) Delete added in v0.26.0

func (s *Memory) Delete(_ context.Context, handle Handle) (bool, error)

Delete implements the Service interface.

func (*Memory) Download added in v0.26.0

func (s *Memory) Download(_ context.Context, handle Handle, w io.Writer) error

Download implements the Service interface.

func (*Memory) Prepare added in v0.26.0

func (s *Memory) Prepare(_ context.Context) (Handle, error)

Prepare implements the Service interface.

func (*Memory) Upload added in v0.26.0

func (s *Memory) Upload(_ context.Context, handle Handle, contentType string, r io.Reader) (int64, error)

Upload implements the Service interface.

type Service added in v0.26.0

type Service interface {
	// Prepare should return a new handle for uploading a blob.
	Prepare(ctx context.Context) (Handle, error)

	// Upload should persist a blob with data read from the provided reader.
	Upload(ctx context.Context, handle Handle, contentType string, r io.Reader) (int64, error)

	// Download lookup the blob and stream its content to the provider writer.
	Download(ctx context.Context, handle Handle, w io.Writer) error

	// Delete should delete the blob.
	Delete(ctx context.Context, handle Handle) (bool, error)

	// Cleanup is called periodically and allows the service to cleanup its
	// storage until the context is cancelled.
	Cleanup(ctx context.Context) error
}

Service is responsible for managing blobs.

type State added in v0.26.0

type State string

State describes the current state of a file. Usually, the state of a file always moves forward by one step but it may also jump directly to "deleting".

const (
	Uploading State = "uploading"
	Uploaded  State = "uploaded"
	Claimed   State = "claimed"
	Released  State = "released"
	Deleting  State = "deleting"
)

The individual states.

func (State) Valid added in v0.28.0

func (s State) Valid() bool

Valid returns whether the state is valid.

type Storage added in v0.26.0

type Storage struct {
	// contains filtered or unexported fields
}

Storage provides file storage services.

func NewStorage added in v0.26.0

func NewStorage(store *coal.Store, notary *heat.Notary, service Service) *Storage

NewStorage creates a new storage.

func (*Storage) Cleanup added in v0.26.0

func (s *Storage) Cleanup(ctx context.Context, retention time.Duration) error

Cleanup will remove obsolete files and remove their blobs. Files in the states "uploading" or "uploaded" are removed after the specified retention which defaults to 1 hour if zero. Files in the states "released" and "deleting" are removed immediately. It will also allow the service to cleanup.

func (*Storage) CleanupTask added in v0.26.0

func (s *Storage) CleanupTask(periodicity, retention time.Duration) *axe.Task

CleanupTask will return a periodic task that can be run to periodically cleanup obsolete files.

func (*Storage) Decorator added in v0.26.0

func (s *Storage) Decorator(fields ...string) *fire.Callback

Decorator will generate view keys for all or just the specified link fields on the returned model or models.

func (*Storage) DownloadAction added in v0.26.0

func (s *Storage) DownloadAction() *fire.Action

DownloadAction returns an action that allows downloading files using view keys.

func (*Storage) UploadAction added in v0.26.0

func (s *Storage) UploadAction(limit int64) *fire.Action

UploadAction returns an action that provides and upload that service that stores blobs and returns claim keys.

func (*Storage) Validator added in v0.26.0

func (s *Storage) Validator(fields ...string) *fire.Callback

Validator will validate all or just the specified link fields of the model.

type ViewKey added in v0.26.0

type ViewKey struct {
	heat.Base `json:"-" heat:"fire/blaze.view,24h"`

	// The viewable file.
	File coal.ID
}

ViewKey is used to authorize file views.

func (*ViewKey) Validate added in v0.26.0

func (k *ViewKey) Validate() error

Validate implements the heat.Key interface.

Jump to

Keyboard shortcuts

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