drivers

package
v0.0.0-...-3d43258 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMime = "application/octet-stream"

DefaultMime is the fallback MIME type when none is provided.

View Source
const DefaultPresignTTL = 15 * time.Minute

DefaultPresignTTL is the default time-to-live for presigned upload and download URLs.

Variables

View Source
var ErrInvalidPath = errors.New("invalid path: traversal or invalid key not allowed")

ErrInvalidPath is returned when a key or resolved path is invalid (e.g. path traversal). Callers can use errors.Is(err, drivers.ErrInvalidPath) to detect validation failures.

Functions

func GenerateDownloadToken

func GenerateDownloadToken(key, secret string, expiresAt int64) string

GenerateDownloadToken creates an HMAC-SHA256 token specifically for download links (only signs key and expiration).

func GenerateToken

func GenerateToken(key, secret string, expiresAt int64, contentType string, maxSizeBytes int64) string

GenerateToken creates an HMAC-SHA256 token signing multiple constraints.

func VerifyDownloadToken

func VerifyDownloadToken(key, token, secret string, expiresAt int64) bool

VerifyDownloadToken checks if a provided download token matches the expected signature.

func VerifyToken

func VerifyToken(key, token, secret string, expiresAt int64, contentType string, maxSizeBytes int64) bool

VerifyToken checks if a provided token matches the expected signature for given constraints.

Types

type LocalFSDriver

type LocalFSDriver struct {
	BaseDir   string
	PublicURL string
	// contains filtered or unexported fields
}

LocalFSDriver implements StorageDriver for local disk with directory hashing

func NewLocalFSDriver

func NewLocalFSDriver(baseDir, publicURL, secretKey string, presignTTL time.Duration) (*LocalFSDriver, error)

NewLocalFSDriver creates a new LocalFSDriver. baseDir is where files will be stored. publicURL is the base URL used to generate public links (e.g., /api/storage). secretKey is the secret used for HMAC signing of local-put upload URLs. presignTTL is the default time-to-live for presigned URLs.

func (*LocalFSDriver) Delete

func (d *LocalFSDriver) Delete(ctx context.Context, key string) error

func (*LocalFSDriver) Get

func (*LocalFSDriver) GetDownloadURL

func (d *LocalFSDriver) GetDownloadURL(_ context.Context, key string) (string, error)

func (*LocalFSDriver) GetUploadURL

func (d *LocalFSDriver) GetUploadURL(_ context.Context, key string, contentType string, maxSizeBytes int64) (string, error)

GetUploadURL returns a presigned URL pointing to a local PUT handler. Note: This method does NOT create the file on disk. It only signs the security constraints (key, expiration, size limit). The actual resource allocation (file creation) happens in Save() when the PUT request is eventually processed, matching S3's deferred behavior.

func (*LocalFSDriver) Save

func (d *LocalFSDriver) Save(ctx context.Context, key string, body io.Reader, contentType string) error

func (*LocalFSDriver) VerifyDownloadToken

func (d *LocalFSDriver) VerifyDownloadToken(key, token string, expiresAt int64) bool

VerifyDownloadToken checks if a provided download token is valid and not expired.

func (*LocalFSDriver) VerifyToken

func (d *LocalFSDriver) VerifyToken(key, token string, expiresAt int64, contentType string, maxSizeBytes int64) bool

VerifyToken checks if a token is valid for a given key and constraints using the driver's secret.

type S3Driver

type S3Driver struct {
	Client        *s3.Client
	PresignClient *s3.PresignClient
	Bucket        string
	PublicURL     string // Optional: Base URL if files are public
	// contains filtered or unexported fields
}

S3Driver implements StorageDriver for S3-compatible storage. Save streams via PutObject (request body is capped at 32MB by the HTTP handler).

func NewS3Driver

func NewS3Driver(client *s3.Client, bucket string, publicURL string, presignTTL time.Duration) *S3Driver

func (*S3Driver) Delete

func (d *S3Driver) Delete(ctx context.Context, key string) error

func (*S3Driver) Get

func (d *S3Driver) Get(ctx context.Context, key string) (io.ReadCloser, string, error)

func (*S3Driver) GetDownloadURL

func (d *S3Driver) GetDownloadURL(ctx context.Context, key string) (string, error)

func (*S3Driver) GetUploadURL

func (d *S3Driver) GetUploadURL(ctx context.Context, key string, contentType string, maxSizeBytes int64) (string, error)

func (*S3Driver) Save

func (d *S3Driver) Save(ctx context.Context, key string, content io.Reader, contentType string) error

Jump to

Keyboard shortcuts

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