storage

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RestoreOriginalFileName

func RestoreOriginalFileName(uniqueName string, withExt ...bool) string

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
	SharedFolder       string `json:"shared_folder,omitempty" yaml:"shared_folder,omitempty"`               // Synology
	OtpCode            string `json:"otp_code,omitempty" yaml:"otp_code,omitempty"`                         // Synology 2FA
	Debug              bool   `json:"debug,omitempty" yaml:"debug,omitempty"`                               // Synology
}

Config storage configuration

func GetConfig

func GetConfig(v *viper.Viper) *Config

GetConfig gets storage config from viper

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the 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

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

func GetFileType(ext string) FileType

GetFileType determines file type based on extension

type GoogleCloudConfig

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

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 NewAliyun

func NewAliyun(c *Config) Interface

NewAliyun creates new aliyun oss client

func NewAzure

func NewAzure(c *Config) Interface

NewAzure creates new azure blob storage client

func NewGoogleCloud

func NewGoogleCloud(c *Config) (Interface, error)

NewGoogleCloud creates new google cloud storage client

func NewMinio

func NewMinio(c *Config) (Interface, error)

NewMinio creates new minio client

func NewOSSAdapter

func NewOSSAdapter(client oss.StorageInterface) Interface

NewOSSAdapter creates a new OSS adapter

func NewQiniu

func NewQiniu(c *Config) (Interface, error)

NewQiniu creates new qiniu cloud storage client

func NewS3

func NewS3(c *Config) Interface

NewS3 creates new aws s3 client

func NewStorage

func NewStorage(c *Config) (Interface, error)

NewStorage creates a new storage instance

func NewSynology

func NewSynology(c *Config) Interface

NewSynology creates new synology NAS storage client

func NewTencentCloud

func NewTencentCloud(c *Config) Interface

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

func (*LocalFileSystem) List

func (fs *LocalFileSystem) List(p string) ([]*Object, error)

List lists files

func (*LocalFileSystem) Put

func (fs *LocalFileSystem) Put(p string, r io.Reader) (*Object, error)

Put stores the reader into the given path

type OSSAdapter

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

OSSAdapter adapts casdoor oss.StorageInterface to our Interface

func (*OSSAdapter) Delete

func (a *OSSAdapter) Delete(path string) error

Delete deletes file

func (*OSSAdapter) Get

func (a *OSSAdapter) Get(path string) (*os.File, error)

Get receives file with given path

func (*OSSAdapter) GetEndpoint

func (a *OSSAdapter) GetEndpoint() string

GetEndpoint gets endpoint

func (*OSSAdapter) GetStream

func (a *OSSAdapter) GetStream(path string) (io.ReadCloser, error)

GetStream gets file as stream

func (*OSSAdapter) GetURL

func (a *OSSAdapter) GetURL(path string) (string, error)

GetURL gets public accessible URL

func (*OSSAdapter) List

func (a *OSSAdapter) List(path string) ([]*Object, error)

List lists all objects under current path

func (*OSSAdapter) Put

func (a *OSSAdapter) Put(path string, reader io.Reader) (*Object, error)

Put stores reader into given path

type Object

type Object struct {
	Path             string
	Name             string
	LastModified     *time.Time
	Size             int64
	StorageInterface Interface
}

Object represents a storage object

func (Object) Get

func (object Object) Get() (*os.File, error)

Get retrieves object's content

type ThumbnailConfig

type ThumbnailConfig struct {
	Path      string `json:"path"`
	MaxWidth  int64  `json:"max_width"`
	MaxHeight int64  `json:"max_height"`
}

ThumbnailConfig thumbnail generation configuration

Jump to

Keyboard shortcuts

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