Documentation ¶
Overview ¶
Package fsmedia is a default implementation of InterfaceMediaStorage declared in "github.com/ottemo/commerce/media" package.
It using filesystem ot store media files in, and database to store existing media to object bindings. Following media types special behaviour supposed:
ConstMediaTypeImage ("image") - files stored in filesystem as set of specified image sizes ConstMediaTypeLink ("link") - external resource - not stored in filesystem ConstMediaTypeDocument ("document"), and others - file stored in filesystem but have not and image
Files are stored within filesystem using following pattern: ConstMediaDefaultFolder/[mediaType]/[objectModelName]/[obejctID]/[mediaFileName].
"image" type media re-sizes to ConstConfigPathMediaImageSize and set of ConstConfigPathMediaImageSizes sizes - these sizes are specified by config values (stored supposedly in DB). On program first startup them are initialized to ConstDefaultImageSize and ConstDefaultImageSizes (the same behaviour for config invalid values). Image resizing happens with usage of white background if ConstResizeOnBackground is set to true.
Database record contain only "base image" record other sizes are named wit a following pattern:
baseImage: [fileName].[fileExtension] sizedImage: [fileName]_[sizeName].[fileExtension]
Image sizes is a config value like "small: 75x75, thumb: 260x300, big: 560x650", where key means [sizeName] and value is size [maxWidth]x[maxHeight] definition. If [sizeName] is not specified iw will equal to value (i.e. "75x75, thumb: 50x50" equals to "75x75: 75x75, thumb: 50x50"). Image re-sizes to [maxWidth]x[maxHeight] bounding box, "0" dimension have a special meaning - it means that in this direction image can be any size ("100x0" means that image height is not limited) Image re-sizing happens with keeping of image aspect ratio.
Index ¶
- Constants
- func APIGetMediaInfo(context api.InterfaceApplicationContext) (interface{}, error)
- type FilesystemMediaStorage
- func (it *FilesystemMediaStorage) GetAllSizes(model string, objID string, mediaType string) ([]map[string]string, error)
- func (it *FilesystemMediaStorage) GetBiggestSize() string
- func (it *FilesystemMediaStorage) GetMediaPath(model string, objID string, mediaType string) (string, error)
- func (it *FilesystemMediaStorage) GetName() string
- func (it *FilesystemMediaStorage) GetResizedImage(model string, objID string, mediaName string, size string) ([]byte, error)
- func (it *FilesystemMediaStorage) GetResizedMediaName(mediaName string, size string) string
- func (it *FilesystemMediaStorage) GetSizeDimensions(size string) (int, int, error)
- func (it *FilesystemMediaStorage) GetSizes(model string, objID string, mediaType string, mediaName string) (map[string]string, error)
- func (it *FilesystemMediaStorage) ListMedia(model string, objID string, mediaType string) ([]string, error)
- func (it *FilesystemMediaStorage) ListMediaDetail(model string, objID string, mediaType string) ([]map[string]interface{}, error)
- func (it *FilesystemMediaStorage) Load(model string, objID string, mediaType string, mediaName string) ([]byte, error)
- func (it *FilesystemMediaStorage) Remove(model string, objID string, mediaType string, mediaName string) error
- func (it *FilesystemMediaStorage) ResizeAllMediaImages() error
- func (it *FilesystemMediaStorage) ResizeMediaImage(model string, objID string, mediaName string, size string) error
- func (it *FilesystemMediaStorage) Save(model string, objID string, mediaType string, mediaName string, ...) error
- func (it *FilesystemMediaStorage) UpdateBaseSize(newValue string) error
- func (it *FilesystemMediaStorage) UpdateSizeNames(newValue string) error
Constants ¶
const ( ConstMediaDBCollection = "media" // database collection name to store media assignment information into ConstMediaDefaultFolder = "./media/" // filesystem folder path to store media files in there ConstResizeOnBackground = true ConstDefaultImageSize = "1000x1000" // "800x400" ConstDefaultImageSizes = "thumb: 280x350" // "small: 75x75, thumb: 260x300, big: 560x650" ConstConfigPathMediaImageSize = "general.app.image_size" // base image size ConstConfigPathMediaImageSizes = "general.app.image_sizes" // other image sizes required ConstConfigPathMediaBaseURL = "general.app.media_base_url" ConstErrorModule = "media/fsmedia" ConstErrorLevel = env.ConstErrorLevelService )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func APIGetMediaInfo ¶
func APIGetMediaInfo(context api.InterfaceApplicationContext) (interface{}, error)
APIGetMediaInfo will resize all images if the params of the request contain 'resizeAll' with a value of true
Types ¶
type FilesystemMediaStorage ¶
type FilesystemMediaStorage struct {
// contains filtered or unexported fields
}
FilesystemMediaStorage is a filesystem based implementer of InterfaceMediaStorage
func (*FilesystemMediaStorage) GetAllSizes ¶
func (it *FilesystemMediaStorage) GetAllSizes(model string, objID string, mediaType string) ([]map[string]string, error)
GetAllSizes returns a list of all image sizes in a []map[string], included is the path and type of media.
func (*FilesystemMediaStorage) GetBiggestSize ¶
func (it *FilesystemMediaStorage) GetBiggestSize() string
GetBiggestSize returns size with a image bounds limit 0x0 or with most resolution, "" - default size
func (*FilesystemMediaStorage) GetMediaPath ¶
func (it *FilesystemMediaStorage) GetMediaPath(model string, objID string, mediaType string) (string, error)
GetMediaPath returns the path needed to access the media file
func (*FilesystemMediaStorage) GetName ¶
func (it *FilesystemMediaStorage) GetName() string
GetName returns the media storage name
func (*FilesystemMediaStorage) GetResizedImage ¶
func (it *FilesystemMediaStorage) GetResizedImage(model string, objID string, mediaName string, size string) ([]byte, error)
GetResizedImage returns re-sized image contents or error if not possible
func (*FilesystemMediaStorage) GetResizedMediaName ¶
func (it *FilesystemMediaStorage) GetResizedMediaName(mediaName string, size string) string
GetResizedMediaName returns media filename for a specified size, or error ir size is invalid
func (*FilesystemMediaStorage) GetSizeDimensions ¶
func (it *FilesystemMediaStorage) GetSizeDimensions(size string) (int, int, error)
GetSizeDimensions returns width and height for specified size or error if size is ot valid
- supposed that 32-bit integer positive part (up to 2147483647) will be enough to reflect width/height dimension
func (*FilesystemMediaStorage) GetSizes ¶
func (it *FilesystemMediaStorage) GetSizes(model string, objID string, mediaType string, mediaName string) (map[string]string, error)
GetSizes returns a list of all sizes for specificed image in a map[string], included is image path, model object and the image name.
func (*FilesystemMediaStorage) ListMedia ¶
func (it *FilesystemMediaStorage) ListMedia(model string, objID string, mediaType string) ([]string, error)
ListMedia returns the list of given type media entities for a given model object
func (*FilesystemMediaStorage) ListMediaDetail ¶
func (it *FilesystemMediaStorage) ListMediaDetail(model string, objID string, mediaType string) ([]map[string]interface{}, error)
ListMediaDetail returns the list with media details of given type media entities for a given model object mediaType could be empty, single value or list of values separated by comma
func (*FilesystemMediaStorage) Load ¶
func (it *FilesystemMediaStorage) Load(model string, objID string, mediaType string, mediaName string) ([]byte, error)
Load retrieves contents of the media entity for a given model object
func (*FilesystemMediaStorage) Remove ¶
func (it *FilesystemMediaStorage) Remove(model string, objID string, mediaType string, mediaName string) error
Remove will delete the entity for the model object from the database and remove it from the filesystem.
func (*FilesystemMediaStorage) ResizeAllMediaImages ¶
func (it *FilesystemMediaStorage) ResizeAllMediaImages() error
ResizeAllMediaImages will resize all images for currently specified sizes
func (*FilesystemMediaStorage) ResizeMediaImage ¶
func (it *FilesystemMediaStorage) ResizeMediaImage(model string, objID string, mediaName string, size string) error
ResizeMediaImage re-sizes specified media to given size, returns error if not possible
func (*FilesystemMediaStorage) Save ¶
func (it *FilesystemMediaStorage) Save(model string, objID string, mediaType string, mediaName string, mediaData []byte) error
Save adds a media entity for the model object to the database and saves it on the filesystem.
func (*FilesystemMediaStorage) UpdateBaseSize ¶
func (it *FilesystemMediaStorage) UpdateBaseSize(newValue string) error
UpdateBaseSize loads predefined sizes from config value
func (*FilesystemMediaStorage) UpdateSizeNames ¶
func (it *FilesystemMediaStorage) UpdateSizeNames(newValue string) error
UpdateSizeNames loads predefined sizes from config value