imageprocessor

package
v0.0.0-...-36f2d6d Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SmallThumbnailSize  = 200
	MediumThumbnailSize = 500
)

Thumbnail sizes

View Source
const (
	ImageStatusKeyFormat          = "image:status:%s"           // Format: image:status:<uuid>
	ImageStatusTimestampKeyFormat = "image:status:timestamp:%s" // Format: image:status:timestamp:<uuid>
)

Cache key format for image processing status

View Source
const (
	STATUS_PENDING    = "pending"    // Image is queued for processing
	STATUS_PROCESSING = "processing" // Image is currently being processed
	STATUS_COMPLETED  = "completed"  // Image processing is complete
	STATUS_FAILED     = "failed"     // Image processing failed
)

Status constants for image processing

View Source
const (
	PENDING_TTL    = 30 * time.Minute // Längere Zeit für unverarbeitete Bilder
	PROCESSING_TTL = 30 * time.Minute // Längere Zeit für Bilder in Verarbeitung
	COMPLETED_TTL  = 5 * time.Minute  // Kurze Zeit für erfolgreich verarbeitete Bilder
	FAILED_TTL     = 1 * time.Hour    // Längere Zeit für fehlgeschlagene Bilder (für Fehleranalyse)
)

TTL für verschiedene Status

Variables

View Source
var (
	// Processing limits to avoid overloading the server
	MaxWorkers = 3
	Throttler  = make(chan struct{}, MaxWorkers)

	// Image quality settings for WebP conversion - can be adjusted via config
	WebPQuality     = 90 // Default quality for WebP conversion (1-100)
	SmallThumbSize  = 200
	MediumThumbSize = 500

	// Directory Paths
	OriginalDir = "uploads/original"
	VariantsDir = "uploads/variants"

	// Tool availability flags
	IsPNGQuantAvailable  = false
	IsJPEGOptimAvailable = false
	IsFFmpegAvailable    = false

	// Function for database updates - can be mocked for testing
	UpdateImageRecordFunc = updateImageRecord
)

Directory paths and worker settings

View Source
var (
	SetCacheImplementation    SetCacheFunc    = cache.Set
	GetCacheImplementation    GetCacheFunc    = cache.Get
	GetIntCacheImplementation GetIntCacheFunc = cache.GetInt
	DeleteCacheImplementation DeleteCacheFunc = cache.Delete
)

Default implementations that use the actual cache package

Functions

func DeleteImageStatus

func DeleteImageStatus(imageUUID string) error

DeleteImageStatus deletes all status entries for an image from the cache

func ExtractMetadata

func ExtractMetadata(image *models.Image, filePath string) error

ExtractMetadata extracts EXIF metadata from an image file

func GetImagePath

func GetImagePath(imageModel *models.Image, format string, size string) string

GetImagePath returns the path to a specific image variant based on format and size.

func GetImageStatus

func GetImageStatus(imageUUID string) (string, error)

GetImageStatus retrieves the processing status of an image from the cache

func GetImageStatusTimestamp

func GetImageStatusTimestamp(imageUUID string) (time.Time, error)

GetImageStatusTimestamp gets the timestamp when the status was set

func IsImageProcessingComplete

func IsImageProcessingComplete(imageUUID string) bool

IsImageProcessingComplete checks if image processing is complete using cache and DB fallback.

func ProcessImage

func ProcessImage(image *models.Image) error

ProcessImage queues an image for processing (convenience function)

func SetImageStatus

func SetImageStatus(imageUUID string, status string) error

SetImageStatus sets the processing status of an image in the cache

func SetImageStatusTimestamp

func SetImageStatusTimestamp(imageUUID string, timestamp time.Time, currentStatus string) error

SetImageStatusTimestamp sets the timestamp when the status was set, using TTL appropriate for the *current* status being set.

Types

type DeleteCacheFunc

type DeleteCacheFunc func(key string) error

Function types for cache operations (for dependency injection in tests)

type GetCacheFunc

type GetCacheFunc func(key string) (string, error)

Function types for cache operations (for dependency injection in tests)

type GetIntCacheFunc

type GetIntCacheFunc func(key string) (int, error)

Function types for cache operations (for dependency injection in tests)

type ImageProcessor

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

ImageProcessor handles image processing with a worker pool

func GetProcessor

func GetProcessor() *ImageProcessor

GetProcessor returns the singleton image processor instance

func (*ImageProcessor) EnqueueImage

func (p *ImageProcessor) EnqueueImage(image *models.Image) error

EnqueueImage adds an image to the processing queue

func (*ImageProcessor) Start

func (p *ImageProcessor) Start()

Start initializes the worker pool

func (*ImageProcessor) Stop

func (p *ImageProcessor) Stop()

Stop gracefully shuts down the worker pool

type ProcessJob

type ProcessJob struct {
	Image *models.Image
}

ProcessJob represents a single image processing job

type SetCacheFunc

type SetCacheFunc func(key string, value interface{}, expiration time.Duration) error

Function types for cache operations (for dependency injection in tests)

Jump to

Keyboard shortcuts

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