Documentation
¶
Index ¶
- func RestoreOriginalFileName(uniqueName string, withExt ...bool) string
- type Config
- type FileConfig
- type FileHeader
- type FileSystem
- type FileType
- type GoogleCloudConfig
- type ImageConfig
- type Interface
- func NewAliyun(c *Config) Interface
- func NewAzure(c *Config) Interface
- func NewGoogleCloud(c *Config) (Interface, error)
- func NewMinio(c *Config) (Interface, error)
- func NewOSSAdapter(client oss.StorageInterface) Interface
- func NewQiniu(c *Config) (Interface, error)
- func NewS3(c *Config) Interface
- func NewStorage(c *Config) (Interface, error)
- func NewSynology(c *Config) Interface
- func NewTencentCloud(c *Config) Interface
- type LocalFileSystem
- func (fs *LocalFileSystem) Delete(p string) error
- func (fs *LocalFileSystem) Get(p string) (*os.File, error)
- func (fs *LocalFileSystem) GetEndpoint() string
- func (fs *LocalFileSystem) GetFullPath(p string) string
- func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
- func (fs *LocalFileSystem) GetURL(p string) (string, error)
- func (fs *LocalFileSystem) List(p string) ([]*Object, error)
- func (fs *LocalFileSystem) Put(p string, r io.Reader) (*Object, error)
- type OSSAdapter
- func (a *OSSAdapter) Delete(path string) error
- func (a *OSSAdapter) Get(path string) (*os.File, error)
- func (a *OSSAdapter) GetEndpoint() string
- func (a *OSSAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *OSSAdapter) GetURL(path string) (string, error)
- func (a *OSSAdapter) List(path string) ([]*Object, error)
- func (a *OSSAdapter) Put(path string, reader io.Reader) (*Object, error)
- type Object
- type ThumbnailConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RestoreOriginalFileName ¶
RestoreOriginalFileName extracts original filename from unique filename
Types ¶
type Config ¶
type Config struct {
Provider string `json:"provider" yaml:"provider"`
ID string `json:"id" yaml:"id"`
Secret string `json:"secret" yaml:"secret"`
Region string `json:"region" yaml:"region"`
Bucket string `json:"bucket" yaml:"bucket"`
Endpoint string `json:"endpoint" yaml:"endpoint"`
// Extended fields for specific providers
ServiceAccountJSON string `json:"service_account_json,omitempty" yaml:"service_account_json,omitempty"` // Google Cloud
OtpCode string `json:"otp_code,omitempty" yaml:"otp_code,omitempty"` // Synology 2FA
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"` // Synology
}
Config storage configuration
type FileConfig ¶
type FileConfig struct {
Path string `json:"path"`
MaxSize int64 `json:"max_size"`
AllowType []FileType `json:"allow_type"`
}
FileConfig file upload configuration
func (*FileConfig) ValidateFile ¶ added in v0.1.5
func (fc *FileConfig) ValidateFile(file *FileHeader) error
ValidateFile validates uploaded file against configuration
type FileHeader ¶
type FileHeader struct {
Name string `json:"name"`
OriginalName string `json:"original_name"`
Size int `json:"size"`
Path string `json:"path"`
Type string `json:"type"`
Ext string `json:"ext"`
Raw *multipart.FileHeader `json:"raw"`
Metadata any `json:"metadata,omitempty"`
}
FileHeader contains file metadata with improved path handling
func GetFileHeader ¶
func GetFileHeader(f *multipart.FileHeader, pathPrefix ...string) *FileHeader
GetFileHeader processes file header and generates unique file name with improved logic
type FileSystem ¶
type FileSystem interface {
GetFullPath(p string) string
Get(p string) (*os.File, error)
GetStream(p string) (io.ReadCloser, error)
Put(p string, r io.Reader) (*Object, error)
Delete(p string) error
List(p string) ([]*Object, error)
GetEndpoint() string
GetURL(p string) (string, error)
}
FileSystem represents the interface for file system storage
type FileType ¶
type FileType string
FileType represents file type enum
const ( FileTypeFile FileType = "file" FileTypeImage FileType = "image" FileTypeVideo FileType = "video" FileTypeAudio FileType = "audio" FileTypeDoc FileType = "doc" FileTypeArchive FileType = "archive" FileTypeOther FileType = "other" )
Supported file types
func GetFileType ¶ added in v0.1.5
GetFileType determines file type based on extension
type GoogleCloudConfig ¶ added in v0.1.5
type GoogleCloudConfig struct {
*Config
ServiceAccountJSON string `json:"service_account_json" yaml:"service_account_json"`
}
GoogleCloudConfig extends Config with Google Cloud specific fields
type ImageConfig ¶
type ImageConfig struct {
Path string `json:"path"`
MaxSize int64 `json:"max_size"`
Thumbnail ThumbnailConfig `json:"thumbnail"`
}
ImageConfig image-specific configuration
type Interface ¶ added in v0.1.5
type Interface interface {
Get(path string) (*os.File, error)
GetStream(path string) (io.ReadCloser, error)
Put(path string, reader io.Reader) (*Object, error)
Delete(path string) error
List(path string) ([]*Object, error)
GetURL(path string) (string, error)
GetEndpoint() string
}
Interface represents the common interface for storage
func NewGoogleCloud ¶ added in v0.1.5
NewGoogleCloud creates new google cloud storage client
func NewOSSAdapter ¶ added in v0.1.5
func NewOSSAdapter(client oss.StorageInterface) Interface
NewOSSAdapter creates a new OSS adapter
func NewStorage ¶
NewStorage creates a new storage instance
func NewSynology ¶ added in v0.1.5
NewSynology creates new synology NAS storage client
func NewTencentCloud ¶
NewTencentCloud creates new tencent cloud cos client
type LocalFileSystem ¶
type LocalFileSystem struct {
Folder string
}
LocalFileSystem implements the FileSystem interface for local file system storage
func NewFileSystem ¶
func NewFileSystem(folder string) *LocalFileSystem
NewFileSystem creates a new local file system storage
func (*LocalFileSystem) Delete ¶
func (fs *LocalFileSystem) Delete(p string) error
Delete deletes a file
func (*LocalFileSystem) Get ¶
func (fs *LocalFileSystem) Get(p string) (*os.File, error)
Get receives a file with the given path
func (*LocalFileSystem) GetEndpoint ¶
func (fs *LocalFileSystem) GetEndpoint() string
GetEndpoint gets the endpoint (for FileSystem, it's just the base path)
func (*LocalFileSystem) GetFullPath ¶
func (fs *LocalFileSystem) GetFullPath(p string) string
GetFullPath returns the full path from absolute/relative path
func (*LocalFileSystem) GetStream ¶
func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
GetStream gets a file as a stream
func (*LocalFileSystem) GetURL ¶
func (fs *LocalFileSystem) GetURL(p string) (string, error)
GetURL gets the public accessible URL
type OSSAdapter ¶ added in v0.1.5
type OSSAdapter struct {
// contains filtered or unexported fields
}
OSSAdapter adapts casdoor oss.StorageInterface to our Interface
func (*OSSAdapter) Delete ¶ added in v0.1.5
func (a *OSSAdapter) Delete(path string) error
Delete deletes file
func (*OSSAdapter) Get ¶ added in v0.1.5
func (a *OSSAdapter) Get(path string) (*os.File, error)
Get receives file with given path
func (*OSSAdapter) GetEndpoint ¶ added in v0.1.5
func (a *OSSAdapter) GetEndpoint() string
GetEndpoint gets endpoint
func (*OSSAdapter) GetStream ¶ added in v0.1.5
func (a *OSSAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream gets file as stream
func (*OSSAdapter) GetURL ¶ added in v0.1.5
func (a *OSSAdapter) GetURL(path string) (string, error)
GetURL gets public accessible URL
type Object ¶ added in v0.1.5
type Object struct {
Path string
Name string
LastModified *time.Time
Size int64
StorageInterface Interface
}
Object represents a storage object
type ThumbnailConfig ¶
type ThumbnailConfig struct {
Path string `json:"path"`
MaxWidth int64 `json:"max_width"`
MaxHeight int64 `json:"max_height"`
}
ThumbnailConfig thumbnail generation configuration