Documentation
¶
Index ¶
- Constants
- Variables
- func BuildImagePaths(imageModel *models.Image) map[string]string
- func DeleteImageAndVariants(imageModel *models.Image) error
- func DeleteImageStatus(imageUUID string) error
- func ExtractMetadata(image *models.Image, filePath string) error
- func GetBestPreviewURL(imageModel *models.Image) string
- func GetImageAbsoluteURL(imageModel *models.Image, format string, size string) string
- func GetImagePath(imageModel *models.Image, format string, size string) string
- func GetImageStatus(imageUUID string) (string, error)
- func GetImageStatusTimestamp(imageUUID string) (time.Time, error)
- func GetImageURL(imageModel *models.Image, format string, size string) string
- func GetOptimalImagePath(imageModel *models.Image, preferredFormats []string, preferredSize string) string
- func GetPublicBaseURLForImage(imageModel *models.Image) string
- func GetVariantPath(imageID uint, variantType string) string
- func HasVariantType(imageID uint, variantType string) bool
- func IsImageProcessingComplete(imageUUID string) bool
- func IsImageProcessingFailed(imageUUID string) bool
- func MakeAbsoluteForImage(imageModel *models.Image, webPath string) string
- func MakeAbsoluteURL(baseURL, webPath string) string
- func ProcessImage(image *models.Image) error
- func ProcessImageSync(imageModel *models.Image) error
- func SetImageStatus(imageUUID string, status string) error
- func SetImageStatusTimestamp(imageUUID string, timestamp time.Time, currentStatus string) error
- type DeleteCacheFunc
- type GetCacheFunc
- type GetIntCacheFunc
- type ImageProcessor
- type ProcessJob
- type SetCacheFunc
- type VariantInfo
Constants ¶
const ( SmallThumbnailSize = 200 MediumThumbnailSize = 500 )
Thumbnail sizes
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
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
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 = 1 * 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 ¶
var ( // DEPRECATED: MaxWorkers - old in-memory queue used unified job queue now MaxWorkers = 3 // DEPRECATED: Old quality settings - now handled in functions directly WebPQuality = 90 // DEPRECATED: Default quality for WebP conversion (1-100) SmallThumbSize = 200 // DEPRECATED: Use SmallThumbnailSize constant instead MediumThumbSize = 500 // DEPRECATED: Use MediumThumbnailSize constant instead // 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
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 BuildImagePaths ¶
BuildImagePaths builds all possible image paths for an image
func DeleteImageAndVariants ¶
DeleteImageAndVariants removes all physical files and database records for an image
func DeleteImageStatus ¶
DeleteImageStatus deletes all status entries for an image from the cache
func ExtractMetadata ¶
ExtractMetadata extracts EXIF metadata from an image file
func GetBestPreviewURL ¶
GetBestPreviewURL returns an absolute URL for a suitable preview image. Preference order: medium (AVIF -> WebP -> Original), then small (AVIF -> WebP -> Original), and finally falls back to the original image URL.
func GetImageAbsoluteURL ¶
GetImageAbsoluteURL returns an absolute URL for the requested variant based on the image's storage pool
func GetImagePath ¶
GetImagePath returns the path to a specific image variant based on format and size.
func GetImageStatus ¶
GetImageStatus retrieves the processing status of an image from the cache
func GetImageStatusTimestamp ¶
GetImageStatusTimestamp gets the timestamp when the status was set
func GetImageURL ¶
GetImageURL returns the web-accessible URL path for a specific image variant This function strips storage pool base paths to generate proper web URLs
func GetOptimalImagePath ¶
func GetOptimalImagePath(imageModel *models.Image, preferredFormats []string, preferredSize string) string
GetOptimalImagePath returns the best available image path based on preferences
func GetPublicBaseURLForImage ¶
GetPublicBaseURLForImage returns the preferred public base URL for serving an image Priority: image.StoragePool.PublicBaseURL -> env PUBLIC_DOMAIN -> empty string
func GetVariantPath ¶
GetVariantPath returns the full path for a specific variant type
func HasVariantType ¶
HasVariantType checks if a specific variant type exists for an image
func IsImageProcessingComplete ¶
IsImageProcessingComplete checks if image processing is complete using cache and DB fallback.
func IsImageProcessingFailed ¶
IsImageProcessingFailed checks whether image processing is currently marked as failed in cache.
func MakeAbsoluteForImage ¶
MakeAbsoluteForImage prefixes a relative web path with the image's public base URL
func MakeAbsoluteURL ¶
MakeAbsoluteURL joins base URL and a web path ("/uploads/...") safely
func ProcessImage ¶
ProcessImage is DEPRECATED - use jobqueue.ProcessImageUnified instead This function still works but uses the old in-memory queue system The new unified Redis-based queue is preferred for better reliability and features
func ProcessImageSync ¶
ProcessImageSync processes an image synchronously without using the queue This is used by the unified job queue system
func SetImageStatus ¶
SetImageStatus sets the processing status of an image in the cache
Types ¶
type DeleteCacheFunc ¶
Function types for cache operations (for dependency injection in tests)
type GetCacheFunc ¶
Function types for cache operations (for dependency injection in tests)
type GetIntCacheFunc ¶
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 DEPRECATED: Use jobqueue.ProcessImageUnified instead of the old in-memory queue
func (*ImageProcessor) EnqueueImage ¶
func (p *ImageProcessor) EnqueueImage(image *models.Image) error
EnqueueImage adds an image to the processing queue
func (*ImageProcessor) Stop ¶
func (p *ImageProcessor) Stop()
Stop gracefully shuts down the worker pool
type ProcessJob ¶
ProcessJob represents a single image processing job
type SetCacheFunc ¶
Function types for cache operations (for dependency injection in tests)
type VariantInfo ¶
type VariantInfo struct {
HasWebP bool
HasAVIF bool
HasThumbnailSmall bool
HasThumbnailMedium bool
AvailableVariants []models.ImageVariant
}
VariantInfo holds information about available variants for an image
func GetImageVariantInfo ¶
func GetImageVariantInfo(imageID uint) (*VariantInfo, error)
GetImageVariantInfo returns information about available variants for an image