storage

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetadataKeyOriginalFilename is the metadata key for storing the original filename
	// Note: MinIO canonicalizes metadata keys to Title-Case format (HTTP header standard).
	MetadataKeyOriginalFilename = "Original-Filename"

	// TempPrefix is the prefix for temporary object storage.
	// Files uploaded to temp/ should be promoted to permanent storage after business logic commits.
	TempPrefix = "temp/"
)
View Source
const (
	// EventTypeFilePromoted is published when a file is promoted from temp to permanent storage.
	EventTypeFilePromoted = "vef.storage.file.promoted"
	// EventTypeFileDeleted is published when a file is deleted from storage.
	EventTypeFileDeleted = "vef.storage.file.deleted"
)

Variables

View Source
var (
	// ErrBucketNotFound indicates the specified bucket does not exist.
	ErrBucketNotFound = errors.New("bucket not found")
	// ErrObjectNotFound indicates the specified object does not exist.
	ErrObjectNotFound = errors.New("object not found")
	// ErrInvalidBucketName indicates the bucket name is invalid.
	ErrInvalidBucketName = errors.New("invalid bucket name")
	// ErrInvalidObjectKey indicates the object key is invalid.
	ErrInvalidObjectKey = errors.New("invalid object key")
	// ErrAccessDenied indicates permission is denied for the operation.
	ErrAccessDenied = errors.New("access denied")
	// ErrProviderNotConfigured indicates no storage provider is configured.
	ErrProviderNotConfigured = errors.New("storage provider not configured")
)

Functions

This section is empty.

Types

type CopyObjectOptions

type CopyObjectOptions struct {
	// SourceKey is the identifier of the source object
	SourceKey string
	// DestKey is the identifier for the copied object
	DestKey string
}

CopyObjectOptions contains parameters for copying an object.

type DeleteObjectOptions

type DeleteObjectOptions struct {
	// Key is the unique identifier of the object to delete
	Key string
}

DeleteObjectOptions contains parameters for deleting a single object.

type DeleteObjectsOptions

type DeleteObjectsOptions struct {
	// Keys is the list of object identifiers to delete
	Keys []string
}

DeleteObjectsOptions contains parameters for batch deleting objects.

type FileEvent added in v0.11.0

type FileEvent struct {
	event.BaseEvent

	// The operation type (promote/delete)
	Operation FileOperation `json:"operation"`
	// The meta type (uploaded_file/richtext/markdown)
	MetaType MetaType `json:"metaType"`
	// The file key (promoted key for promote, original key for delete)
	FileKey string `json:"fileKey"`
	// Parsed attributes from the meta tag
	Attrs map[string]string `json:"attrs,omitempty"`
}

FileEvent represents a file operation event in the storage system. Published when files are promoted or deleted during Promoter operations.

func NewFileDeletedEvent added in v0.11.0

func NewFileDeletedEvent(metaType MetaType, fileKey string, attrs map[string]string) *FileEvent

NewFileDeletedEvent creates a new file deleted event.

func NewFilePromotedEvent added in v0.11.0

func NewFilePromotedEvent(metaType MetaType, fileKey string, attrs map[string]string) *FileEvent

NewFilePromotedEvent creates a new file promoted event. FileKey is the NEW key after promotion.

type FileOperation added in v0.11.0

type FileOperation string

FileOperation represents the type of file operation.

const (
	// OperationPromote indicates a file promotion operation.
	OperationPromote FileOperation = "promote"
	// OperationDelete indicates a file deletion operation.
	OperationDelete FileOperation = "delete"
)

type GetObjectOptions

type GetObjectOptions struct {
	// Key is the unique identifier of the object
	Key string
}

GetObjectOptions contains parameters for retrieving an object.

type ListObjectsOptions

type ListObjectsOptions struct {
	// Prefix filters objects by key prefix
	Prefix string
	// Recursive determines whether to list objects recursively
	Recursive bool
	// MaxKeys limits the maximum number of objects to return
	MaxKeys int
}

ListObjectsOptions contains parameters for listing objects.

type MetaType added in v0.11.0

type MetaType string

MetaType defines the type of meta information field.

const (
	// MetaTypeUploadedFile indicates a direct file field (string or []string).
	MetaTypeUploadedFile MetaType = "uploaded_file"
	// MetaTypeRichText indicates a rich text field containing HTML with resource references.
	MetaTypeRichText MetaType = "richtext"
	// MetaTypeMarkdown indicates a Markdown field containing resource references.
	MetaTypeMarkdown MetaType = "markdown"
)

type MoveObjectOptions

type MoveObjectOptions struct {
	CopyObjectOptions
}

MoveObjectOptions contains parameters for moving an object.

type ObjectInfo

type ObjectInfo struct {
	// Bucket is the name of the storage bucket
	Bucket string `json:"bucket"`
	// Key is the unique identifier of the object within the bucket
	Key string `json:"key"`
	// ETag is the entity tag, typically an MD5 hash used for versioning and cache validation
	ETag string `json:"eTag"`
	// Size is the object size in bytes
	Size int64 `json:"size"`
	// ContentType is the MIME type of the object
	ContentType string `json:"contentType"`
	// LastModified is the timestamp when the object was last modified
	LastModified time.Time `json:"lastModified"`
	// Metadata contains custom key-value pairs associated with the object
	Metadata map[string]string `json:"metadata,omitempty"`
}

ObjectInfo represents metadata information about a stored object.

type PresignedURLOptions

type PresignedURLOptions struct {
	// Key is the unique identifier of the object
	Key string
	// Expires specifies how long the presigned URL remains valid
	Expires time.Duration
	// Method specifies the HTTP method (GET for download, PUT for upload)
	Method string
}

PresignedURLOptions contains parameters for generating presigned URLs.

type Promoter added in v0.11.0

type Promoter[T any] interface {
	// Promote handles file promotion and cleanup based on the scenario:
	// - newModel != nil && oldModel == nil: Create (promote new files)
	// - newModel != nil && oldModel != nil: Update (promote new files + cleanup replaced files)
	// - newModel == nil && oldModel != nil: Delete (cleanup all files)
	Promote(ctx context.Context, newModel, oldModel *T) error
}

Promoter defines the interface for automatic file field promotion and cleanup. It supports three types of meta information fields: - uploaded_file: Direct file fields (string, *string, null.String, []string) - richtext: Rich text fields (string, *string, null.String), automatically extracts and processes resource references in HTML - markdown: Markdown fields (string, *string, null.String), automatically extracts and processes resource references in Markdown.

func NewPromoter added in v0.11.0

func NewPromoter[T any](service Service, publisher ...event.Publisher) Promoter[T]

NewPromoter creates a new Promoter for type T. The publisher parameter is optional; if omitted, no events will be published.

type PutObjectOptions

type PutObjectOptions struct {
	// Key is the unique identifier for the object
	Key string
	// Reader provides the object data to upload
	Reader io.Reader
	// Size is the size of the data in bytes (-1 if unknown)
	Size int64
	// ContentType specifies the MIME type of the object
	ContentType string
	// Metadata contains custom key-value pairs to store with the object
	Metadata map[string]string
}

PutObjectOptions contains parameters for uploading an object.

type Service added in v0.8.0

type Service interface {
	// PutObject uploads an object to storage
	PutObject(ctx context.Context, opts PutObjectOptions) (*ObjectInfo, error)
	// GetObject retrieves an object from storage
	GetObject(ctx context.Context, opts GetObjectOptions) (io.ReadCloser, error)
	// DeleteObject deletes a single object from storage
	DeleteObject(ctx context.Context, opts DeleteObjectOptions) error
	// DeleteObjects deletes multiple objects from storage in a batch operation
	DeleteObjects(ctx context.Context, opts DeleteObjectsOptions) error
	// ListObjects lists objects in a bucket with optional filtering
	ListObjects(ctx context.Context, opts ListObjectsOptions) ([]ObjectInfo, error)
	// GetPresignedUrl generates a presigned Url for temporary access to an object
	GetPresignedUrl(ctx context.Context, opts PresignedURLOptions) (string, error)
	// CopyObject copies an object from source to destination
	CopyObject(ctx context.Context, opts CopyObjectOptions) (*ObjectInfo, error)
	// MoveObject moves an object from source to destination (implemented as Copy + Delete)
	MoveObject(ctx context.Context, opts MoveObjectOptions) (*ObjectInfo, error)
	// StatObject retrieves metadata information about an object
	StatObject(ctx context.Context, opts StatObjectOptions) (*ObjectInfo, error)

	// PromoteObject moves an object from temporary storage (temp/ prefix) to permanent storage.
	// It removes the "temp/" prefix from the object key, effectively promoting a temporary upload
	// to a permanent file.
	// This is useful for handling multistep upload workflows where files
	// are initially uploaded to temp/ and only moved to permanent storage after business logic commits.
	// If the key does not start with "temp/", this method does nothing and returns nil.
	PromoteObject(ctx context.Context, tempKey string) (*ObjectInfo, error)
}

Service defines the core interface for object storage operations. Implementations should support various cloud storage services like MinIO, S3, Aliyun OSS, Tencent COS, etc.

type StatObjectOptions

type StatObjectOptions struct {
	// Key is the unique identifier of the object
	Key string
}

StatObjectOptions contains parameters for retrieving object metadata.

Jump to

Keyboard shortcuts

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