Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeImage(data []byte) (image.Image, error)
- func DeleteInventoryItemImage(c *gin.Context)
- func DeleteMyBannerImage(c *gin.Context)
- func DeleteMyProfileImage(c *gin.Context)
- func DeletePackImage(c *gin.Context)
- func EncodeToJPEG(img image.Image) ([]byte, error)
- func EncodeToJPEGWithQuality(img image.Image, quality int) ([]byte, error)
- func GetBannerImage(c *gin.Context)
- func GetInventoryItemImage(c *gin.Context)
- func GetPackImage(c *gin.Context)
- func GetPackItemImage(c *gin.Context)
- func GetProfileImage(c *gin.Context)
- func ResizeBannerImage(img image.Image) image.Image
- func ResizeImage(img image.Image) image.Image
- func ResizeImageWithMax(img image.Image, maxDim int) image.Image
- func UploadInventoryItemImage(c *gin.Context)
- func UploadMyBannerImage(c *gin.Context)
- func UploadMyProfileImage(c *gin.Context)
- func UploadPackImage(c *gin.Context)
- func ValidateImageFormat(data []byte) (string, error)
- type AccountImageStorage
- type BannerImageStorage
- type DBStorage
- func (s *DBStorage) Delete(ctx context.Context, id uint) error
- func (s *DBStorage) Exists(ctx context.Context, id uint) (bool, error)
- func (s *DBStorage) Get(ctx context.Context, id uint) (*Image, error)
- func (s *DBStorage) Save(ctx context.Context, id uint, data []byte, metadata ImageMetadata) error
- type Image
- type ImageMetadata
- type ImageStorage
- type InventoryImageStorage
- type ProcessedImage
- func ProcessBannerImage(data []byte) (*ProcessedImage, error)
- func ProcessBannerImageFromReader(reader io.Reader) (*ProcessedImage, error)
- func ProcessImage(data []byte) (*ProcessedImage, error)
- func ProcessImageFromReader(reader io.Reader) (*ProcessedImage, error)
- func ProcessInventoryItemImage(data []byte) (*ProcessedImage, error)
- func ProcessInventoryItemImageFromReader(reader io.Reader) (*ProcessedImage, error)
- func ProcessProfileImage(data []byte) (*ProcessedImage, error)
- func ProcessProfileImageFromReader(reader io.Reader) (*ProcessedImage, error)
Constants ¶
const ( // MaxUploadSize is the maximum file size for uploads (5 MB) MaxUploadSize = 5 * 1024 * 1024 // MaxProcessedSize is the maximum size after processing (5 MB) MaxProcessedSize = 5 * 1024 * 1024 // MaxDimension is the maximum width or height for processed images MaxDimension = 1920 // MaxProfilePicDimension is the maximum width or height for profile pictures MaxProfilePicDimension = 512 // MaxInventoryItemDimension is the maximum width or height for inventory item pictures MaxInventoryItemDimension = 400 // JPEGQuality is the quality setting for JPEG encoding (0-100) JPEGQuality = 85 // InventoryItemJPEGQuality is the quality setting for inventory item images (0-100) InventoryItemJPEGQuality = 70 // BannerJPEGQuality is the quality setting for banner images (0-100) BannerJPEGQuality = 95 // MaxBannerWidth is the maximum width for banner images MaxBannerWidth = 1920 // MaxBannerHeight is the maximum height for banner images MaxBannerHeight = 600 // MimeTypeJPEG is the MIME type for JPEG images MimeTypeJPEG = "image/jpeg" // MimeTypePNG is the MIME type for PNG images MimeTypePNG = "image/png" // MimeTypeWebP is the MIME type for WebP images MimeTypeWebP = "image/webp" )
const (
// ErrMsgNoImageProvided is the error message when no image file is provided
ErrMsgNoImageProvided = "no image file provided"
)
Variables ¶
var ( // ErrNotFound is returned when an image is not found ErrNotFound = errors.New("image not found") // ErrInvalidFormat is returned when the image format is not supported ErrInvalidFormat = errors.New("invalid image format") // ErrTooLarge is returned when the image exceeds size limits ErrTooLarge = errors.New("image too large") // ErrCorrupted is returned when the image is corrupted ErrCorrupted = errors.New("image corrupted") )
Functions ¶
func DecodeImage ¶
DecodeImage decodes an image from bytes
func DeleteInventoryItemImage ¶ added in v1.3.0
DeleteInventoryItemImage deletes an image for an inventory item @Summary Delete inventory item image @Description Delete the image for an inventory item. Only the item owner can delete images. @Security Bearer @Tags Inventory Images @Produce json @Param id path int true "Inventory Item ID" @Success 200 {object} map[string]interface{} "Image deleted successfully" @Failure 400 {object} map[string]string "Invalid item ID" @Failure 401 {object} map[string]string "Unauthorized" @Failure 403 {object} map[string]string "Item does not belong to user" @Failure 404 {object} map[string]string "Item not found" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/myinventory/{id}/image [delete]
func DeleteMyBannerImage ¶ added in v1.6.0
DeleteMyBannerImage deletes the banner image for the current user @Summary Delete banner image @Description Delete the banner/hero image for the currently logged-in user @Security Bearer @Tags Account Images @Produce json @Success 200 {object} map[string]interface{} "Banner image deleted successfully" @Failure 401 {object} map[string]string "Unauthorized" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/myaccount/banner [delete]
func DeleteMyProfileImage ¶ added in v1.2.0
DeleteMyProfileImage deletes the profile image for the current user @Summary Delete profile image @Description Delete the profile image for the currently logged-in user @Security Bearer @Tags Account Images @Produce json @Success 200 {object} map[string]interface{} "Image deleted successfully" @Failure 401 {object} map[string]string "Unauthorized" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/myaccount/image [delete]
func DeletePackImage ¶
DeletePackImage deletes an image for a pack @Summary Delete pack image @Description Delete the image for a pack. Only the pack owner can delete images. @Security Bearer @Tags Pack Images @Produce json @Param id path int true "Pack ID" @Success 200 {object} map[string]interface{} "Image deleted successfully" @Failure 400 {object} map[string]string "Invalid pack ID" @Failure 401 {object} map[string]string "Unauthorized" @Failure 403 {object} map[string]string "Pack does not belong to user" @Failure 404 {object} map[string]string "Pack not found" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/mypack/{id}/image [delete]
func EncodeToJPEG ¶
EncodeToJPEG encodes an image to JPEG format with default quality (JPEGQuality)
func EncodeToJPEGWithQuality ¶ added in v1.6.0
EncodeToJPEGWithQuality encodes an image to JPEG format with the given quality (1-100) Values outside the range are clamped. This also effectively strips EXIF data.
func GetBannerImage ¶ added in v1.6.0
GetBannerImage retrieves the banner image for a given account @Summary Get banner image @Description Get the banner/hero image for a user account @Tags Account Images @Produce image/jpeg @Param id path int true "Account ID" @Success 200 {file} image/jpeg "Banner image" @Failure 400 {string} string "Invalid account ID" @Failure 404 {string} string "No banner image found" @Failure 500 {string} string "Internal server error" @Router /v1/accounts/{id}/banner [get]
func GetInventoryItemImage ¶ added in v1.3.0
GetInventoryItemImage retrieves an image for an inventory item @Summary Get inventory item image @Description Get the image for an inventory item. Only the item owner can view the image. @Security Bearer @Tags Inventory Images @Produce image/jpeg @Param id path int true "Inventory Item ID" @Success 200 {file} image/jpeg "Inventory item image" @Failure 400 {string} string "Invalid item ID" @Failure 401 {string} string "Unauthorized" @Failure 403 {string} string "Forbidden" @Failure 404 {string} string "Item not found or has no image" @Failure 500 {string} string "Internal server error" @Router /v1/myinventory/{id}/image [get]
func GetPackImage ¶
GetPackImage retrieves an image for a pack @Summary Get pack image @Description Get the image for a pack. Public packs are accessible without authentication. @Tags Pack Images @Produce image/jpeg @Param id path int true "Pack ID" @Success 200 {file} image/jpeg "Pack image" @Failure 400 {string} string "Invalid pack ID" @Failure 401 {string} string "Unauthorized (for private packs)" @Failure 403 {string} string "Forbidden (for private packs not owned by user)" @Failure 404 {string} string "Pack not found or has no image" @Failure 500 {string} string "Internal server error" @Router /v1/packs/{id}/image [get]
func GetPackItemImage ¶ added in v1.7.0
GetPackItemImage retrieves an image for an item within a pack @Summary Get pack item image @Description Get the image for an inventory item within a pack. Public packs are accessible without authentication. @Tags Pack Images @Produce image/jpeg @Param id path int true "Pack ID" @Param itemId path int true "Item (Inventory) ID" @Success 200 {file} image/jpeg "Item image" @Failure 400 {string} string "Invalid pack ID or item ID" @Failure 404 {string} string "Pack not found, item not in pack, or has no image" @Failure 500 {string} string "Internal server error" @Router /v1/packs/{id}/items/{itemId}/image [get]
func GetProfileImage ¶ added in v1.2.0
GetProfileImage retrieves the profile image for a given account @Summary Get profile image @Description Get the profile image for a user account @Tags Account Images @Produce image/jpeg @Param id path int true "Account ID" @Success 200 {file} image/jpeg "Profile image" @Failure 400 {string} string "Invalid account ID" @Failure 404 {string} string "No profile image found" @Failure 500 {string} string "Internal server error" @Router /v1/accounts/{id}/image [get]
func ResizeBannerImage ¶ added in v1.6.0
ResizeBannerImage scales and center-crops an image to exactly MaxBannerWidth x MaxBannerHeight
func ResizeImage ¶
ResizeImage resizes an image if it exceeds MaxDimension, maintaining aspect ratio
func ResizeImageWithMax ¶ added in v1.2.0
ResizeImageWithMax resizes an image if it exceeds maxDim, maintaining aspect ratio
func UploadInventoryItemImage ¶ added in v1.3.0
UploadInventoryItemImage uploads or updates an image for an inventory item @Summary Upload or update inventory item image @Description Upload or update an image for an inventory item. Only the item owner can upload images. @Security Bearer @Tags Inventory Images @Accept multipart/form-data @Produce json @Param id path int true "Inventory Item ID" @Param image formData file true "Image file (JPEG, PNG, or WebP, max 5MB)" @Success 200 {object} map[string]interface{} "Image uploaded successfully" @Failure 400 {object} map[string]string "Invalid request or image" @Failure 401 {object} map[string]string "Unauthorized" @Failure 403 {object} map[string]string "Item does not belong to user" @Failure 404 {object} map[string]string "Item not found" @Failure 413 {object} map[string]string "Payload too large" @Failure 500 {object} map[string]string "Internal server error" @Failure 503 {object} map[string]string "Feature disabled" @Router /v1/myinventory/{id}/image [post]
func UploadMyBannerImage ¶ added in v1.6.0
UploadMyBannerImage uploads or updates the banner image for the current user @Summary Upload or update banner image @Description Upload or update the banner/hero image for the currently logged-in user @Security Bearer @Tags Account Images @Accept multipart/form-data @Produce json @Param image formData file true "Image file (JPEG, PNG, or WebP, max 5MB)" @Success 200 {object} map[string]interface{} "Banner image uploaded successfully" @Failure 400 {object} map[string]string "Invalid request or image" @Failure 401 {object} map[string]string "Unauthorized" @Failure 413 {object} map[string]string "Payload too large" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/myaccount/banner [post]
func UploadMyProfileImage ¶ added in v1.2.0
UploadMyProfileImage uploads or updates the profile image for the current user @Summary Upload or update profile image @Description Upload or update the profile image for the currently logged-in user @Security Bearer @Tags Account Images @Accept multipart/form-data @Produce json @Param image formData file true "Image file (JPEG, PNG, or WebP, max 5MB)" @Success 200 {object} map[string]interface{} "Image uploaded successfully" @Failure 400 {object} map[string]string "Invalid request or image" @Failure 401 {object} map[string]string "Unauthorized" @Failure 413 {object} map[string]string "Payload too large" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/myaccount/image [post]
func UploadPackImage ¶
UploadPackImage uploads or updates an image for a pack @Summary Upload or update pack image @Description Upload or update an image for a pack. Only the pack owner can upload images. @Security Bearer @Tags Pack Images @Accept multipart/form-data @Produce json @Param id path int true "Pack ID" @Param image formData file true "Image file (JPEG, PNG, or WebP, max 5MB)" @Success 200 {object} map[string]interface{} "Image uploaded successfully" @Failure 400 {object} map[string]string "Invalid request or image" @Failure 401 {object} map[string]string "Unauthorized" @Failure 403 {object} map[string]string "Pack does not belong to user" @Failure 404 {object} map[string]string "Pack not found" @Failure 413 {object} map[string]string "Payload too large" @Failure 500 {object} map[string]string "Internal server error" @Router /v1/mypack/{id}/image [post]
func ValidateImageFormat ¶
ValidateImageFormat checks if the image format is supported by examining magic bytes
Types ¶
type AccountImageStorage ¶ added in v1.2.0
type AccountImageStorage interface {
// Save stores a profile image for an account
Save(ctx context.Context, accountID uint, data []byte, metadata ImageMetadata) error
// Get retrieves a profile image for an account
// Returns ErrNotFound if the image doesn't exist
Get(ctx context.Context, accountID uint) (*Image, error)
// Delete removes a profile image for an account
// Returns nil if the image doesn't exist (idempotent)
Delete(ctx context.Context, accountID uint) error
// Exists checks if a profile image exists for an account
Exists(ctx context.Context, accountID uint) (bool, error)
}
AccountImageStorage defines the interface for account profile image storage operations
type BannerImageStorage ¶ added in v1.6.0
type BannerImageStorage interface {
// Save stores a banner image for an account
Save(ctx context.Context, accountID uint, data []byte, metadata ImageMetadata) error
// Get retrieves a banner image for an account
// Returns ErrNotFound if the image doesn't exist
Get(ctx context.Context, accountID uint) (*Image, error)
// Delete removes a banner image for an account
// Returns nil if the image doesn't exist (idempotent)
Delete(ctx context.Context, accountID uint) error
// Exists checks if a banner image exists for an account
Exists(ctx context.Context, accountID uint) (bool, error)
}
BannerImageStorage defines the interface for account banner image storage operations
type DBStorage ¶ added in v1.3.0
type DBStorage struct {
// contains filtered or unexported fields
}
DBStorage wraps dbImageStore with exported methods, implementing ImageStorage, AccountImageStorage, and InventoryImageStorage interfaces. Use the specific constructor functions to create instances for each table.
func NewDBAccountImageStorage ¶ added in v1.2.0
func NewDBAccountImageStorage() *DBStorage
NewDBAccountImageStorage creates a new database account image storage instance
func NewDBBannerImageStorage ¶ added in v1.6.0
func NewDBBannerImageStorage() *DBStorage
NewDBBannerImageStorage creates a new database banner image storage instance
func NewDBImageStorage ¶
func NewDBImageStorage() *DBStorage
NewDBImageStorage creates a new database image storage instance for packs
func NewDBInventoryImageStorage ¶ added in v1.3.0
func NewDBInventoryImageStorage() *DBStorage
NewDBInventoryImageStorage creates a new database inventory image storage instance
type Image ¶
type Image struct {
Data []byte
Metadata ImageMetadata
}
Image represents an image with its data and metadata
type ImageMetadata ¶
ImageMetadata contains metadata about a processed image
type ImageStorage ¶
type ImageStorage interface {
// Save stores an image for a pack
Save(ctx context.Context, packID uint, data []byte, metadata ImageMetadata) error
// Get retrieves an image for a pack
// Returns ErrNotFound if the image doesn't exist
Get(ctx context.Context, packID uint) (*Image, error)
// Delete removes an image for a pack
// Returns nil if the image doesn't exist (idempotent)
Delete(ctx context.Context, packID uint) error
// Exists checks if an image exists for a pack
Exists(ctx context.Context, packID uint) (bool, error)
}
ImageStorage defines the interface for image storage operations This allows for different storage backends (database, S3, etc.)
type InventoryImageStorage ¶ added in v1.3.0
type InventoryImageStorage interface {
// Save stores an image for an inventory item
Save(ctx context.Context, itemID uint, data []byte, metadata ImageMetadata) error
// Get retrieves an image for an inventory item
// Returns ErrNotFound if the image doesn't exist
Get(ctx context.Context, itemID uint) (*Image, error)
// Delete removes an image for an inventory item
// Returns nil if the image doesn't exist (idempotent)
Delete(ctx context.Context, itemID uint) error
// Exists checks if an image exists for an inventory item
Exists(ctx context.Context, itemID uint) (bool, error)
}
InventoryImageStorage defines the interface for inventory item image storage operations
type ProcessedImage ¶
type ProcessedImage struct {
Data []byte
Metadata ImageMetadata
}
ProcessedImage contains the processed image data and metadata
func ProcessBannerImage ¶ added in v1.6.0
func ProcessBannerImage(data []byte) (*ProcessedImage, error)
ProcessBannerImage validates and processes an uploaded banner image
func ProcessBannerImageFromReader ¶ added in v1.6.0
func ProcessBannerImageFromReader(reader io.Reader) (*ProcessedImage, error)
ProcessBannerImageFromReader processes a banner image from an io.Reader
func ProcessImage ¶
func ProcessImage(data []byte) (*ProcessedImage, error)
ProcessImage validates and processes an uploaded image Returns the processed image data and metadata
func ProcessImageFromReader ¶
func ProcessImageFromReader(reader io.Reader) (*ProcessedImage, error)
ProcessImageFromReader processes an image from an io.Reader
func ProcessInventoryItemImage ¶ added in v1.6.0
func ProcessInventoryItemImage(data []byte) (*ProcessedImage, error)
ProcessInventoryItemImage validates and processes an uploaded inventory item picture Uses MaxInventoryItemDimension (400px) and InventoryItemJPEGQuality (70%)
func ProcessInventoryItemImageFromReader ¶ added in v1.6.0
func ProcessInventoryItemImageFromReader(reader io.Reader) (*ProcessedImage, error)
ProcessInventoryItemImageFromReader processes an inventory item image from an io.Reader
func ProcessProfileImage ¶ added in v1.2.0
func ProcessProfileImage(data []byte) (*ProcessedImage, error)
ProcessProfileImage validates and processes an uploaded profile picture Uses MaxProfilePicDimension (512px) instead of MaxDimension (1920px)
func ProcessProfileImageFromReader ¶ added in v1.2.0
func ProcessProfileImageFromReader(reader io.Reader) (*ProcessedImage, error)
ProcessProfileImageFromReader processes a profile image from an io.Reader