tss-rocks/backend/internal/storage/storage.go
2025-02-22 02:46:40 +08:00

36 lines
1.1 KiB
Go

package storage
import (
"context"
"io"
"time"
)
// FileInfo represents metadata about a stored file
type FileInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
ContentType string `json:"content_type"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
URL string `json:"url"`
}
// Storage defines the interface for file storage operations
type Storage interface {
// Save stores a file and returns its FileInfo
Save(ctx context.Context, name string, contentType string, reader io.Reader) (*FileInfo, error)
// Get retrieves a file by its ID
Get(ctx context.Context, id string) (io.ReadCloser, *FileInfo, error)
// Delete removes a file by its ID
Delete(ctx context.Context, id string) error
// List returns a list of files with optional prefix
List(ctx context.Context, prefix string, limit int, offset int) ([]*FileInfo, error)
// Exists checks if a file exists
Exists(ctx context.Context, id string) (bool, error)
}