upload

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StagedPrefix = "staged"
	TrashPrefix  = "trash"
)

Variables

View Source
var (
	ErrTooLarge     = errors.New("coyote/upload: file is larger than the limit")
	ErrTypeNotAllow = errors.New("coyote/upload: file type is not allowed")
	ErrTypeMismatch = errors.New("coyote/upload: declared type does not match the content")
	ErrEmptyFile    = errors.New("coyote/upload: file is empty")
	ErrTooManyPixel = errors.New("coyote/upload: image dimensions are too large")
)
View Source
var (
	ErrNoFile       = errors.New("coyote/upload: no file in the request")
	ErrNotConfigued = errors.New("coyote/upload: no storage configured")
)

Functions

func CleanPath

func CleanPath(prefix string) string

func ContentTypeFor

func ContentTypeFor(key string) string

func ExtensionFor

func ExtensionFor(kind string) string

func SafeName

func SafeName(name string) string

func Sign

func Sign(secret, key string, expires time.Time) string

func Sniff

func Sniff(head []byte) string

func ValidSignature

func ValidSignature(secret, key, expires, signature string, maxAge time.Duration) bool

Types

type File

type File struct {
	Ref      Ref
	Name     string
	Type     string
	Size     int64
	Digest   string
	Uploaded time.Time
}

type HandlerOptions

type HandlerOptions struct {
	Prefix  string
	Private bool
	Secret  string
	MaxAge  time.Duration
}

type Options

type Options struct {
	Storage  storage.Storage
	Rules    Rules
	Path     string
	TrashTTL time.Duration
	StageTTL time.Duration
}

type Ref

type Ref string

func (Ref) Committed

func (r Ref) Committed() bool

func (Ref) Digest

func (r Ref) Digest() string

func (Ref) Empty

func (r Ref) Empty() bool

func (Ref) Extension

func (r Ref) Extension() string

func (Ref) GormDataType

func (Ref) GormDataType() string

func (Ref) IsFile

func (Ref) IsFile() bool

func (*Ref) Scan

func (r *Ref) Scan(value any) error

func (Ref) Staged

func (r Ref) Staged() bool

func (Ref) String

func (r Ref) String() string

func (Ref) Trashed

func (r Ref) Trashed() bool

func (Ref) Value

func (r Ref) Value() (driver.Value, error)

type Rules

type Rules struct {
	MaxSize   int64
	Allowed   []string
	MaxPixels int
}

func (Rules) Check

func (r Rules) Check(head []byte, declared string) (string, error)

func (Rules) CheckPixels

func (r Rules) CheckPixels(whole io.Reader, sniffed string) error

type Service

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

func New

func New(opts Options) *Service

func (*Service) Accept

func (s *Service) Accept(r *http.Request, field string) (File, error)

func (*Service) AcceptTo

func (s *Service) AcceptTo(r *http.Request, field, path string) (File, error)

func (*Service) Commit

func (s *Service) Commit(ctx context.Context, refs ...*Ref) error

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, ref Ref) error

func (*Service) Each

func (s *Service) Each(r *http.Request, fn func(part *multipart.Part) error) error

func (*Service) Handler

func (s *Service) Handler(opts HandlerOptions) http.Handler

func (*Service) Open

func (s *Service) Open(ctx context.Context, ref Ref) (io.ReadSeekCloser, error)

func (*Service) Path

func (s *Service) Path() string

func (*Service) PathFor

func (s *Service) PathFor(field string) string

func (*Service) Rules

func (s *Service) Rules() Rules

func (*Service) SignedURL

func (s *Service) SignedURL(prefix, secret string, ref Ref, lifetime time.Duration) string

func (*Service) Storage

func (s *Service) Storage() storage.Storage

func (*Service) Store

func (s *Service) Store(ctx context.Context, r io.Reader, name, declared string, size int64) (File, error)

func (*Service) StoreTo

func (s *Service) StoreTo(ctx context.Context, r io.Reader, name, declared string, size int64, path string) (File, error)

func (*Service) Sweep

func (s *Service) Sweep(ctx context.Context) (staged int, trashed int, err error)

func (*Service) URL

func (s *Service) URL(prefix string, ref Ref) string

Jump to

Keyboard shortcuts

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