filesystem

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package filesystem provides high-level file upload, download, validation, image helpers, and storage driver dispatch.

Index

Constants

View Source
const (
	HookBeforeUpload        = "BeforeUpload"
	HookAfterUpload         = "AfterUpload"
	HookAfterUploadFailed   = "AfterUploadFailed"
	HookAfterValidateFailed = "AfterValidateFailed"
)
View Source
const (
	HookBeforeDownload      = "BeforeDownload"
	HookAfterDownload       = "AfterDownload"
	HookAfterDownloadFailed = "AfterDownloadFailed"
)

Variables

This section is empty.

Functions

func CropImage

func CropImage(reader io.Reader, writer io.Writer, rect CropRect, format string, quality int) error

func HookValidateFile

func HookValidateFile(ctx context.Context, fs *FileSystem, file core.FileInfo) error

func ValidateImageInfo

func ValidateImageInfo(info ImageInfo, limit ImageLimit) error

Types

type CropRect

type CropRect struct {
	X      int
	Y      int
	Width  int
	Height int
}

type FileSystem

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

func New

func New(cfg *core.Config) (*FileSystem, error)

func NewFileSystem

func NewFileSystem(policy core.StoragePolicy, opts ...Option) (*FileSystem, error)

func NewFromPolicy

func NewFromPolicy(policy core.StoragePolicy, opts ...Option) (*FileSystem, error)

func (*FileSystem) CleanHooks

func (fs *FileSystem) CleanHooks(name string)

func (*FileSystem) Close

func (fs *FileSystem) Close() error

func (*FileSystem) Config

func (fs *FileSystem) Config() core.Config

func (*FileSystem) Delete

func (fs *FileSystem) Delete(paths ...string) error

func (*FileSystem) DispatchHandler

func (fs *FileSystem) DispatchHandler() error

func (*FileSystem) Download

func (fs *FileSystem) Download(ctx context.Context, path string, writer io.Writer, progress func(downloaded, total int64)) error

func (*FileSystem) Get

func (fs *FileSystem) Get(path string) (io.ReadCloser, error)

func (*FileSystem) Handler

func (fs *FileSystem) Handler() core.Handler

func (*FileSystem) InitUpload

func (fs *FileSystem) InitUpload(ctx context.Context, req UploadInitRequest) (*core.UploadCredential, error)

func (*FileSystem) List

func (fs *FileSystem) List(path string) ([]core.Object, error)

func (*FileSystem) Put

func (fs *FileSystem) Put(file core.FileHeader) error

func (*FileSystem) Recycle

func (fs *FileSystem) Recycle()

func (*FileSystem) Source

func (fs *FileSystem) Source(path string, ttl time.Duration) (string, error)

func (*FileSystem) Token

func (fs *FileSystem) Token(info core.FileInfo, ttl time.Duration) (*core.UploadCredential, error)

func (*FileSystem) Trigger

func (fs *FileSystem) Trigger(ctx context.Context, name string, file core.FileInfo) error

func (*FileSystem) Upload

func (fs *FileSystem) Upload(ctx context.Context, file core.FileHeader) error

func (*FileSystem) UploadChunk

func (fs *FileSystem) UploadChunk(ctx context.Context, uploadID string, index int, reader io.Reader) (*UploadChunkResult, error)

func (*FileSystem) UploadCroppedImage

func (fs *FileSystem) UploadCroppedImage(ctx context.Context, reader io.Reader, info core.FileInfo, rect CropRect, format string, quality int) (core.FileInfo, error)

func (*FileSystem) UploadFromURL

func (fs *FileSystem) UploadFromURL(ctx context.Context, rawURL string, info core.FileInfo) (core.FileInfo, error)

func (*FileSystem) UploadStatus

func (fs *FileSystem) UploadStatus(uploadID string) (*UploadStatus, error)

func (*FileSystem) UploadStream

func (fs *FileSystem) UploadStream(ctx context.Context, reader io.Reader, info core.FileInfo) (core.FileInfo, error)

func (*FileSystem) Use

func (fs *FileSystem) Use(name string, hook Hook) error

func (*FileSystem) ValidateExtension

func (fs *FileSystem) ValidateExtension(name, path string) bool

func (*FileSystem) ValidateFileInfo

func (fs *FileSystem) ValidateFileInfo(file core.FileInfo) error

func (*FileSystem) ValidateFileName

func (fs *FileSystem) ValidateFileName(name, path string) bool

func (*FileSystem) ValidateFileSize

func (fs *FileSystem) ValidateFileSize(size int64) bool

type Hook

type Hook func(ctx context.Context, fs *FileSystem, file core.FileInfo) error

type ImageInfo

type ImageInfo struct {
	Width  int
	Height int
	Format string
}

func DecodeImageInfo

func DecodeImageInfo(reader io.Reader) (ImageInfo, error)

type ImageLimit

type ImageLimit struct {
	MaxWidth  int
	MaxHeight int
	MinWidth  int
	MinHeight int
}

type Option

type Option func(*core.Config)

func WithAllowedExtensions

func WithAllowedExtensions(exts ...string) Option

func WithChunkSize

func WithChunkSize(chunkSize int64) Option

func WithMaxSize

func WithMaxSize(maxSize int64) Option

func WithNameRules

func WithNameRules(dirRule, fileRule string) Option

func WithTempDir

func WithTempDir(tempDir string) Option

func WithTokenTTL

func WithTokenTTL(ttl time.Duration) Option

func WithUploadDir

func WithUploadDir(uploadDir string) Option

type UploadChunkResult

type UploadChunkResult struct {
	UploadID       string `json:"upload_id"`
	ChunkIndex     int    `json:"chunk_index"`
	Received       int    `json:"received"`
	ReceivedText   string `json:"received_text"`
	ChunkNum       int    `json:"chunk_num"`
	Done           bool   `json:"done"`
	FilePath       string `json:"file_path"`
	UploadComplete bool   `json:"upload_complete"`
}

type UploadInitRequest

type UploadInitRequest struct {
	FileName  string
	Path      string
	TotalSize int64
	MIMEType  string
	Metadata  map[string]string
}

type UploadSession

type UploadSession struct {
	UploadID  string
	FileName  string
	FilePath  string
	TotalSize int64
	MIMEType  string
	Metadata  map[string]string
	Chunks    *chunk.ChunkUpload
	// contains filtered or unexported fields
}

type UploadStatus

type UploadStatus struct {
	UploadID  string `json:"upload_id"`
	FileName  string `json:"file_name"`
	FilePath  string `json:"file_path"`
	ChunkNum  int    `json:"chunk_num"`
	Received  []int  `json:"received"`
	TotalSize int64  `json:"total_size"`
}

Directories

Path Synopsis
Package core defines shared filesystem contracts, metadata, config, and small helpers.
Package core defines shared filesystem contracts, metadata, config, and small helpers.
driver
cos
oss
s3

Jump to

Keyboard shortcuts

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