handlers

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatAVIF     = "avif"
	FormatWebP     = "webp"
	FormatOriginal = "original"
)

Image format constants

Variables

This section is empty.

Functions

func ConfigHandler

func ConfigHandler(cfg *config.Config) http.HandlerFunc

ConfigHandler returns a handler function that exposes selected configuration values to clients

func DebugTagsHandler

func DebugTagsHandler(cfg *config.Config) http.HandlerFunc

DebugTagsHandler returns a handler for debugging tag issues

func DeleteImageHandler

func DeleteImageHandler(cfg *config.Config) http.HandlerFunc

DeleteImageHandler returns a handler for deleting images

func ListImagesHandler

func ListImagesHandler(cfg *config.Config) http.HandlerFunc

ListImagesHandler returns a handler for listing images

func LocalRandomImageHandler

func LocalRandomImageHandler() http.HandlerFunc

LocalRandomImageHandler serves random images from local storage

func RandomImage

func RandomImage(cfg *config.Config) http.HandlerFunc

RandomImage handles random image requests in a unified way, working with both local and S3 storage based on the configured storage type.

This handler: 1. Checks the storage type configuration (local or S3) 2. Delegates to the appropriate specialized handler 3. Returns a random image with proper format detection, including special handling for PNG

Benefits: - Provides a single entry point for random image functionality - Maintains proper content type detection for all image formats - Handles PNG transparency properly with special cases - Ensures consistent headers and caching behavior

func RandomImageHandler

func RandomImageHandler(s3Client *s3.Client) http.HandlerFunc

RandomImageHandler serves random images from S3 storage

func RequireAPIKey

func RequireAPIKey(cfg *config.Config, next http.HandlerFunc) http.HandlerFunc

RequireAPIKey middleware to validate API key before processing requests

func TagsHandler

func TagsHandler(cfg *config.Config) http.HandlerFunc

TagsHandler returns a handler for retrieving all unique tags

func UploadHandler

func UploadHandler(cfg *config.Config) http.HandlerFunc

UploadHandler handles image uploads, converting them to multiple formats

func ValidateAPIKey

func ValidateAPIKey(cfg *config.Config) http.HandlerFunc

ValidateAPIKey provides an endpoint to validate API keys

Types

type AuthResponse

type AuthResponse struct {
	Valid bool   `json:"valid"`           // Whether the API key is valid
	Error string `json:"error,omitempty"` // Error message if validation fails
}

AuthResponse represents the response for API key validation

type ClientConfig

type ClientConfig struct {
	MaxUploadCount    int  `json:"maxUploadCount"`    // Maximum number of images allowed per upload
	ImageQuality      int  `json:"imageQuality"`      // Image conversion quality (1-100)
	CompressionEffort int  `json:"compressionEffort"` // Compression effort level (0-10)
	ForceLossless     bool `json:"forceLossless"`     // Whether to force lossless conversion
}

ClientConfig represents the configuration exposed to clients

type DebugTagsResponse

type DebugTagsResponse struct {
	Tag    string   `json:"tag"`
	Images []string `json:"images"`
}

DebugTagsResponse represents the response for the debug tags API

type DeleteRequest

type DeleteRequest struct {
	ID string `json:"id"` // Image ID (filename without extension)
}

DeleteRequest represents the request body for deleting an image

type DeleteResponse

type DeleteResponse struct {
	Success bool   `json:"success"` // Whether the operation was successful
	Message string `json:"message"` // Description of the result
}

DeleteResponse represents the response after deleting an image

type ImageInfo

type ImageInfo struct {
	ID          string            `json:"id"`          // Filename without extension
	FileName    string            `json:"filename"`    // Full filename with extension
	URL         string            `json:"url"`         // URL to access the image
	URLs        map[string]string `json:"urls"`        // URLs for all available formats
	Orientation string            `json:"orientation"` // landscape or portrait
	Format      string            `json:"format"`      // original, webp, avif
	Size        int64             `json:"size"`        // File size in bytes
	Path        string            `json:"path"`        // Path relative to storage root
	StorageType string            `json:"storageType"` // "local" or "s3"
	Tags        []string          `json:"tags"`        // Image tags for categorization
}

ImageInfo represents information about an image

type PaginatedResponse

type PaginatedResponse struct {
	Success    bool        `json:"success"`    // Whether the request was successful
	Images     []ImageInfo `json:"images"`     // Images for current page
	Page       int         `json:"page"`       // Current page number
	Limit      int         `json:"limit"`      // Number of items per page
	TotalPages int         `json:"totalPages"` // Total number of pages
	Total      int         `json:"total"`      // Total number of images
}

PaginatedResponse represents a paginated response with images

type TagsResponse

type TagsResponse struct {
	Tags []string `json:"tags"`
}

TagsResponse represents the response for the tags API

type UploadResult

type UploadResult struct {
	Filename    string            `json:"filename"`
	Status      string            `json:"status"`
	Message     string            `json:"message"`
	Orientation string            `json:"orientation,omitempty"`
	Format      string            `json:"format,omitempty"`
	URLs        map[string]string `json:"urls,omitempty"`
	ExpiryTime  string            `json:"expiryTime,omitempty"`
	Tags        []string          `json:"tags,omitempty"`
}

UploadResult represents the result of an image upload

Jump to

Keyboard shortcuts

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