Documentation
¶
Index ¶
- func CleanupPlutoCache(imageId int) (int, error)
- func CleanupPlutoImage(imageFileName string) (bool, error)
- func CropWithFocus(img image.Image, targetRatio float32, focusX, focusY float32, ...) image.Image
- func CropWithFocusWithoutAlpha(img image.Image, targetRatio float32, focusX, focusY float32, ...) image.Image
- func DecodeFloat32FromPath(s string) (float32, error)
- func DeleteCacheTx(ctx context.Context, tx pgx.Tx, imageID int) (deletedFilesCount int64, err error)
- func DeleteFilesWithPrefix(dir string, prefix string) (int, error)
- func DeleteImageTx(ctx context.Context, tx pgx.Tx, imageId int) (deletedFileName string, cacheRows int64, err error)
- func EncodeFloat32ForPath(f float32) string
- func FloatPtrEqual(a, b *float64) bool
- func GenerateImageFilename(originalName string) (string, error)
- func GetImageFocusTx(ctx context.Context, tx pgx.Tx, imageID int) (focusX *float64, focusY *float64, err error)
- func GetImageIdByByContext(gc *gin.Context, context string, contextId int, identifier string) (int, bool)
- func GetQueryBoolDefault(gc *gin.Context, key string, def bool) (bool, bool)
- func GetQueryInt(gc *gin.Context, key string) (int, bool)
- func GetQueryIntDefault(gc *gin.Context, key string, def int) (int, bool)
- func ParamInt(gc *gin.Context, key string) (int, bool)
- func ParseAspectRatio(s string) (float32, error)
- func RemoveFile(path string) error
- func ResizeToWidth(img image.Image, width int, ratio string) image.Image
- type ApiTxError
- func ApiErrForbidden(msg string, args ...any) *ApiTxError
- func ApiErrInternal(msg string, args ...any) *ApiTxError
- func ApiErrNotFound(msg string, args ...any) *ApiTxError
- func NewApiTxError(code int, msg string, args ...any) *ApiTxError
- func WithTransaction(ctx context.Context, db *pgxpool.Pool, fn func(tx pgx.Tx) *ApiTxError) *ApiTxError
- type CacheEntry
- type Config
- type DeleteImageResult
- type ImageCleanupResult
- type ImageMeta
- type Pluto
- type TxFunc
- type UpsertImageResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupPlutoCache ¶ added in v0.2.0
Delete cache files
func CleanupPlutoImage ¶ added in v0.2.0
Delete original image file
func CropWithFocus ¶ added in v0.1.8
func CropWithFocus( img image.Image, targetRatio float32, focusX, focusY float32, targetW, targetH int, ) image.Image
CropWithFocus crops an image to a target aspect ratio and optionally resizes, centered on the focus point, while preserving alpha transparency.
func CropWithFocusWithoutAlpha ¶ added in v0.3.0
func DecodeFloat32FromPath ¶ added in v0.1.8
DecodeFloat32FromPath reverses the encoding back to float32.
func DeleteCacheTx ¶ added in v0.2.0
func DeleteCacheTx( ctx context.Context, tx pgx.Tx, imageID int, ) (deletedFilesCount int64, err error)
Deletes cache DB entries, return number of affected rows
func DeleteFilesWithPrefix ¶ added in v0.2.0
DeleteFilesWithPrefix deletes all files in a directory that start with the given prefix. Returns the number of deleted files and an error (if any).
func DeleteImageTx ¶ added in v0.2.0
func DeleteImageTx( ctx context.Context, tx pgx.Tx, imageId int, ) (deletedFileName string, cacheRows int64, err error)
Deletes image + cache DB entries, returns filename to delete from disk
func EncodeFloat32ForPath ¶ added in v0.1.8
EncodeFloat32ForPath converts a float32 into a safe ASCII filename string. Output contains only [0-9a-f] and is exactly 8 characters long.
func FloatPtrEqual ¶ added in v0.2.0
func GenerateImageFilename ¶
GenerateImageFilename returns a securely generated random filename that preserves the original file's extension.
It creates a 128-bit (16-byte) cryptographically secure random identifier, encodes it as a 32-character hexadecimal string, and appends the original file extension (e.g. ".jpg", ".png") from the input filename.
This function is suitable for generating unique, unpredictable image filenames for uploaded files.
Example:
"cat.jpg" => "f3ab7c54c8a44f01bd1182d4a57c121a.jpg"
Parameters:
originalName - the original filename, from which the extension will be preserved.
Returns:
- A string containing the generated filename (randomHex + original extension).
- An error if the secure random number generation fails.
func GetImageFocusTx ¶ added in v0.2.0
func GetImageFocusTx( ctx context.Context, tx pgx.Tx, imageID int, ) (focusX *float64, focusY *float64, err error)
GetImageFocus returns focus_x and focus_y for an image
func GetImageIdByByContext ¶ added in v0.3.0
func GetQueryBoolDefault ¶ added in v0.3.0
func GetQueryIntDefault ¶ added in v0.1.8
func ParseAspectRatio ¶
func RemoveFile ¶ added in v0.2.0
RemoveFile deletes a file at the given path. Returns an error if the file cannot be deleted.
Types ¶
type ApiTxError ¶ added in v0.3.0
func ApiErrForbidden ¶ added in v0.3.0
func ApiErrForbidden(msg string, args ...any) *ApiTxError
Specialized helpers
func ApiErrInternal ¶ added in v0.3.0
func ApiErrInternal(msg string, args ...any) *ApiTxError
func ApiErrNotFound ¶ added in v0.3.0
func ApiErrNotFound(msg string, args ...any) *ApiTxError
func NewApiTxError ¶ added in v0.3.0
func NewApiTxError(code int, msg string, args ...any) *ApiTxError
func WithTransaction ¶ added in v0.3.0
func WithTransaction(ctx context.Context, db *pgxpool.Pool, fn func(tx pgx.Tx) *ApiTxError) *ApiTxError
func (*ApiTxError) Error ¶ added in v0.3.0
func (e *ApiTxError) Error() string
type CacheEntry ¶ added in v0.3.0
type Config ¶
type Config struct {
BaseApiUrl string `json:"base_api_url"`
DbHost string `json:"db_host"`
DbPort int `json:"db_port"`
DbUser string `json:"db_user"`
DbPassword string `json:"db_password"`
DbName string `json:"db_name"`
DbSchema string `json:"db_schema"`
SSLMode string `json:"ssl_mode"`
PlutoVerbose bool `json:"pluto_verbose"`
PlutoRoute string `json:"pluto_route"`
PlutoImageDir string `json:"pluto_image_dir"`
PlutoCacheDir string `json:"pluto_cache_dir"`
PlutoMaxImagePx int `json:"pluto_max_image_px"`
PlutoDefaultQuality int `json:"pluto_default_quality"`
PlutoDefaultImageType string `json:"pluto_default_image_type"`
}
Config holds database configuration details
func DefaultConfig ¶ added in v0.2.0
func DefaultConfig() Config
type DeleteImageResult ¶ added in v0.3.0
type DeleteImageResult struct {
HttpStatus int
Message string
FileRemovedFlag bool
CacheFilesRemoved int
ImageId int
}
DeleteImageResult mirrors UpsertImageResult
func DeleteImage ¶ added in v0.3.0
func DeleteImage( gc *gin.Context, context string, contextId int, identifier string, postCallback TxFunc, ) (DeleteImageResult, error)
DeleteImage deletes an image by context/contextId/identifier
type ImageCleanupResult ¶ added in v0.2.0
func CleanupPlutoImageFiles ¶ added in v0.2.0
func CleanupPlutoImageFiles( imageId int, fileName *string, ) (*ImageCleanupResult, error)
type ImageMeta ¶ added in v0.3.0
type ImageMeta struct {
Id *int `json:"id"`
FileName *string `json:"file_name,omitempty"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
MimeType *string `json:"mime_type,omitempty"`
Alt *string `json:"alt,omitempty"`
Description *string `json:"description,omitempty"`
License *int `json:"license,omitempty"`
Exif map[string]any `json:"exif,omitempty"`
Expiration *string `json:"expiration_date,omitempty"`
Creator *string `json:"creator,omitempty"`
Copyright *string `json:"copyright,omitempty"`
FocusX *float64 `json:"focus_x,omitempty"`
FocusY *float64 `json:"focus_y,omitempty"`
MarginLeft *int `json:"margin_left,omitempty"`
MarginRight *int `json:"margin_right,omitempty"`
MarginTop *int `json:"margin_top,omitempty"`
MarginBottom *int `json:"margin_bottom,omitempty"`
}
type Pluto ¶
var PlutoInstance *Pluto
func Initialize ¶ added in v0.1.3
New creates and initializes a new Pluto instance
func (*Pluto) RegisterRoutes ¶
func (pluto *Pluto) RegisterRoutes(rg *gin.RouterGroup, middlewares ...gin.HandlerFunc)