imageprocessor

package
v0.0.0-...-4a6608b Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: AGPL-3.0 Imports: 31 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  = 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

View Source
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

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 BuildImagePaths

func BuildImagePaths(imageModel *models.Image) map[string]string

BuildImagePaths builds all possible image paths for an image

func DeleteImageAndVariants

func DeleteImageAndVariants(imageModel *models.Image) error

DeleteImageAndVariants removes all physical files and database records for an image

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 GetBestPreviewURL

func GetBestPreviewURL(imageModel *models.Image) string

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

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

GetImageAbsoluteURL returns an absolute URL for the requested variant based on the image's storage pool

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 GetImageURL

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

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

func GetPublicBaseURLForImage(imageModel *models.Image) string

GetPublicBaseURLForImage returns the preferred public base URL for serving an image Priority: image.StoragePool.PublicBaseURL -> env PUBLIC_DOMAIN -> empty string

func GetVariantPath

func GetVariantPath(imageID uint, variantType string) string

GetVariantPath returns the full path for a specific variant type

func HasVariantType

func HasVariantType(imageID uint, variantType string) bool

HasVariantType checks if a specific variant type exists for an image

func IsImageProcessingComplete

func IsImageProcessingComplete(imageUUID string) bool

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

func IsImageProcessingFailed

func IsImageProcessingFailed(imageUUID string) bool

IsImageProcessingFailed checks whether image processing is currently marked as failed in cache.

func MakeAbsoluteForImage

func MakeAbsoluteForImage(imageModel *models.Image, webPath string) string

MakeAbsoluteForImage prefixes a relative web path with the image's public base URL

func MakeAbsoluteURL

func MakeAbsoluteURL(baseURL, webPath string) string

MakeAbsoluteURL joins base URL and a web path ("/uploads/...") safely

func ProcessImage

func ProcessImage(image *models.Image) error

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

func ProcessImageSync(imageModel *models.Image) error

ProcessImageSync processes an image synchronously without using the queue This is used by the unified job queue system

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 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) 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)

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

Jump to

Keyboard shortcuts

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