Documentation
¶
Overview ¶
Package imagestorage provides image storage management for cdev.
Package imagestorage provides image storage management for cdev. It handles storing, retrieving, and cleaning up uploaded images with configurable limits, TTL, and security validations.
Index ¶
- Constants
- type Manager
- type Storage
- func (s *Storage) CanAcceptUpload(sizeBytes int64) (bool, string)
- func (s *Storage) Cleanup()
- func (s *Storage) Clear() error
- func (s *Storage) Close()
- func (s *Storage) Delete(id string) error
- func (s *Storage) Get(id string) (*StoredImage, error)
- func (s *Storage) GetLocalPath(id string) (string, error)
- func (s *Storage) GetStats() StorageStats
- func (s *Storage) List() []*StoredImage
- func (s *Storage) Store(reader io.Reader, mimeType string) (*StoredImage, error)
- func (s *Storage) ValidatePath(path string) error
- type StorageStats
- type StoredImage
- type WorkspacePathResolver
Constants ¶
const ( MaxImagesCount = 50 // Max images in folder MaxTotalSizeMB = 100 // Max total size in MB MaxSingleImageMB = 10 // Max single image in MB ImageTTL = 1 * time.Hour // Auto-cleanup after 1 hour CleanupInterval = 5 * time.Minute // Check every 5 minutes CdevImagesDir = ".cdev/images" // Relative path within workspace )
Storage limits and configuration constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages per-workspace image storage instances. It creates storage on demand when a workspace is first accessed.
func NewManager ¶
func NewManager(resolver WorkspacePathResolver) *Manager
NewManager creates a new ImageStorageManager.
func (*Manager) CloseWorkspace ¶
CloseWorkspace closes and removes the storage for a specific workspace. Use this when a workspace is removed.
func (*Manager) GetStorage ¶
GetStorage returns the image storage for a workspace. Creates the storage on demand if it doesn't exist.
func (*Manager) ListWorkspaces ¶
ListWorkspaces returns the IDs of workspaces that have active storage.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage manages image storage with limits and cleanup.
func New ¶
New creates a new ImageStorage instance for a workspace. The workspacePath is the root path of the workspace - images will be stored in {workspacePath}/.cdev/images/
func (*Storage) CanAcceptUpload ¶
CanAcceptUpload checks if the storage can accept an upload of the given size.
func (*Storage) Close ¶
func (s *Storage) Close()
Close stops the storage and cleanup goroutine. Safe to call multiple times.
func (*Storage) Get ¶
func (s *Storage) Get(id string) (*StoredImage, error)
Get retrieves an image by ID.
func (*Storage) GetLocalPath ¶
GetLocalPath returns the local path for an image ID. This is the path that can be passed to Claude CLI.
func (*Storage) GetStats ¶
func (s *Storage) GetStats() StorageStats
GetStats returns current storage statistics.
func (*Storage) List ¶
func (s *Storage) List() []*StoredImage
List returns all stored images sorted by creation time (newest first).
func (*Storage) Store ¶
Store saves an image from a reader and returns the stored image info. It validates the content, checks limits, and handles deduplication.
func (*Storage) ValidatePath ¶
ValidatePath checks if a path is valid and within the images directory. This prevents path traversal attacks using multiple techniques: 1. Clean the path to resolve "..", ".", and redundant separators 2. Verify the cleaned path is still under the images directory 3. Check the path doesn't escape via symlinks
type StorageStats ¶
type StorageStats struct {
ImageCount int `json:"image_count"`
TotalSizeBytes int64 `json:"total_size_bytes"`
OldestImage time.Time `json:"oldest_image"`
NewestImage time.Time `json:"newest_image"`
}
StorageStats contains current storage statistics.
type StoredImage ¶
type StoredImage struct {
ID string `json:"id"`
LocalPath string `json:"local_path"` // Relative path: .cdev/images/xxx.jpg (for Claude in workspace)
FullPath string `json:"-"` // Absolute path (internal use)
MimeType string `json:"mime_type"`
Size int64 `json:"size"`
ContentHash string `json:"content_hash"` // SHA256 hash for deduplication
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
StoredImage represents a stored image with metadata.
type WorkspacePathResolver ¶
type WorkspacePathResolver interface {
// GetWorkspacePath returns the absolute path for a workspace ID.
// Returns an error if the workspace is not found.
GetWorkspacePath(workspaceID string) (string, error)
}
WorkspacePathResolver is an interface for looking up workspace paths by ID. This decouples the ImageStorageManager from the workspace package.