blob

package
v0.0.0-...-7aaaf19 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired      = errors.New("token expired")
	ErrInvalidShareToken = errors.New("invalid share token")
)
View Source
var ErrException = &exception{}

Functions

func Hasher256

func Hasher256(r io.Reader) string

func NewException

func NewException(err error) *exception

Types

type Data

type Data io.ReadCloser

type Info

type Info struct {
	Bucket       string
	Filename     string
	ContentType  string
	Sum          string
	Size         int64
	LastModified time.Time
}

represent object

type Iterator

type Iterator struct {
	UserID string
	C      <-chan *Info
	// contains filtered or unexported fields
}

func (*Iterator) Err

func (li *Iterator) Err() error

func (*Iterator) Next

func (li *Iterator) Next() bool

func (*Iterator) Value

func (li *Iterator) Value() *Info

type Object

type Object struct {
	Info
	Data
}

type ObjectStorer

type ObjectStorer interface {
	Put(ctx context.Context, bucket, filename string, reader io.ReadCloser, size int64, contentType string) (*Info, error)
	Get(ctx context.Context, bucket, filename string) (*Object, error)
	Delete(ctx context.Context, bucket, filename string) error
	ObjectIterator(ctx context.Context, bucket string, limit int, lastFilename string) *Iterator
}

type OpErr

type OpErr interface {
	error
	// contains filtered or unexported methods
}

type PutParam

type PutParam struct {
	Bucket      string
	Filename    string
	Size        int64
	Body        io.ReadCloser
	ContentType string
}

type QuotaInfo

type QuotaInfo struct {
	Bucket string
	Quota  int64
	Usage  int64
}

func (*QuotaInfo) CheckAvail

func (qi *QuotaInfo) CheckAvail(size int64) bool

type RecordIsExist

type RecordIsExist struct {
	Err error
}

func (*RecordIsExist) Error

func (r *RecordIsExist) Error() string

type ShareFunc

type ShareFunc func(ctx context.Context, expiration time.Duration) (*url.URL, error)

func (ShareFunc) GetURL

func (f ShareFunc) GetURL(ctx context.Context, expiration time.Duration) (*url.URL, error)

type Storage

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

func New

func New(ctx context.Context, tokens TokenStorer, objects ObjectStorer) (*Storage, error)

func NewWithMemory

func NewWithMemory() (*Storage, error)

func (*Storage) CreateShareToken

func (o *Storage) CreateShareToken(ctx context.Context, bucket, filename string, expire time.Duration) (*Token, error)

func (*Storage) Delete

func (o *Storage) Delete(ctx context.Context, userID, filename string) error

func (*Storage) Get

func (o *Storage) Get(ctx context.Context, bucket, filename string) (*Object, error)

func (*Storage) List

func (o *Storage) List(ctx context.Context, bucket string, limit int, lastKey string) *Iterator

func (*Storage) Put

func (o *Storage) Put(ctx context.Context, param *PutParam) (*Info, error)

func (*Storage) WithShareToken

func (o *Storage) WithShareToken(ctx context.Context, tknKey string) (*Object, error)

type Token

type Token struct {
	Key      string
	Bucket   string
	Filename string
	Expire   time.Time
}

represent shareFileToken every shared file has this unique token

func NewShareToken

func NewShareToken(bucket, filename string, expire time.Duration) *Token

func (*Token) IsFilenameEqualTo

func (t *Token) IsFilenameEqualTo(filename string) bool

func (*Token) IsNotExpire

func (t *Token) IsNotExpire() bool

func (*Token) ValidUntil

func (t *Token) ValidUntil() time.Time

type TokenStorer

type TokenStorer interface {
	Put(ctx context.Context, token *Token) OpErr
	Get(ctx context.Context, tokenKey string) (*Token, bool, error)
	GetByFilename(ctx context.Context, bucket string) (*Token, bool, error)
	Delete(ctx context.Context, tokenKey string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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