media_library

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 28 Imported by: 0

README

Media Library

Media Library is a Golang library that supports the upload of files/images to a filesystem or cloud storage. The Plugin includes cropping and resizing features for images.

GoDoc

Documentation

https://doc.getqor.com/plugins/media-library.html

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCallbacks

func RegisterCallbacks(db *gorm.DB)

RegisterCallbacks register callback into GORM DB

func RegisterMediaHandler

func RegisterMediaHandler(name string, handler MediaHandler)

RegisterMediaHandler register Media library handler

Types

type AssetManager

type AssetManager struct {
	gorm.Model
	File FileSystem `media_library:"URL:/system/assets/{{primary_key}}/{{filename_with_hash}}"`
}

AssetManager defined a asset manager that could be used to manage assets in qor admin

func (*AssetManager) ConfigureQorResource

func (*AssetManager) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource configure qor locale for Qor Admin

type Base

type Base struct {
	FileName    string
	Url         string
	CropOptions map[string]*CropOption `json:",omitempty"`
	Delete      bool                   `json:",omitempty"`
	Crop        bool                   `json:"-"`
	FileHeader  FileHeader             `json:"-"`
	Reader      io.Reader              `json:"-"`
	// contains filtered or unexported fields
}

Base defined a base struct for storages

func (Base) ConfigureQorMetaBeforeInitialize

func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor)

ConfigureQorMetaBeforeInitialize configure this field for Qor Admin

func (*Base) Cropped

func (b *Base) Cropped(values ...bool) (result bool)

Cropped mark the image to be cropped

func (Base) Ext

func (b Base) Ext() string

func (*Base) GetCropOption

func (b *Base) GetCropOption(name string) *image.Rectangle

GetCropOption get crop options

func (Base) GetFileHeader

func (b Base) GetFileHeader() FileHeader

GetFileHeader get file's header, this value only exists when saving files

func (Base) GetFileName

func (b Base) GetFileName() string

GetFileName get file's name

func (Base) GetSizes

func (b Base) GetSizes() map[string]*Size

GetSizes get configured sizes, it will be used to crop images accordingly

func (Base) GetURL

func (b Base) GetURL(option *Option, scope *gorm.Scope, field *gorm.Field, templater URLTemplater) string

GetURL get default URL for a model based on its options

func (Base) GetURLTemplate

func (b Base) GetURLTemplate(option *Option) (path string)

GetURLTemplate get url template

func (Base) IsImage

func (b Base) IsImage() bool

IsImage return if it is an image

func (Base) IsVideo

func (b Base) IsVideo() bool

func (*Base) NeedCrop

func (b *Base) NeedCrop() bool

NeedCrop return the file needs to be cropped or not

func (Base) Retrieve

func (b Base) Retrieve(url string) (*os.File, error)

Retrieve retrieve file content with url

func (*Base) Scan

func (b *Base) Scan(data interface{}) (err error)

Scan scan files, crop options, db values into struct

func (Base) String

func (b Base) String() string

String return file's url

func (Base) URL

func (b Base) URL(styles ...string) string

URL return file's url with given style

func (Base) Value

func (b Base) Value() (driver.Value, error)

Value return struct's Value

type CropOption

type CropOption struct {
	X, Y, Width, Height int
}

CropOption includes crop options

type File

type File struct {
	ID          json.Number
	Url         string
	Description string
}

func (File) IsImage

func (file File) IsImage() bool

func (File) IsVideo

func (file File) IsVideo() bool

func (File) URL

func (file File) URL(styles ...string) string

type FileHeader

type FileHeader interface {
	Open() (multipart.File, error)
}

FileHeader is an interface, for matched values, when call its `Open` method will return `multipart.File`

type FileSystem

type FileSystem struct {
	Base
}

FileSystem defined a media library storage using file system

func (FileSystem) GetFullPath

func (f FileSystem) GetFullPath(url string, option *Option) (path string, err error)

GetFullPath return full file path from a relative file path

func (FileSystem) Retrieve

func (f FileSystem) Retrieve(url string) (*os.File, error)

Retrieve retrieve file content with url

func (FileSystem) Store

func (f FileSystem) Store(name string, option *Option, reader io.Reader) (err error)

Store save reader's context with name

type Media

type Media interface {
	Scan(value interface{}) error
	Value() (driver.Value, error)

	GetURLTemplate(*Option) string
	GetURL(option *Option, scope *gorm.Scope, field *gorm.Field, templater URLTemplater) string

	GetFileHeader() FileHeader
	GetFileName() string

	GetSizes() map[string]*Size
	NeedCrop() bool
	Cropped(values ...bool) bool
	GetCropOption(name string) *image.Rectangle

	Store(url string, option *Option, reader io.Reader) error
	Retrieve(url string) (*os.File, error)

	IsImage() bool

	URL(style ...string) string
	Ext() string
	String() string
}

MediaLibrary is an interface including methods that needs for a media library storage

type MediaBox

type MediaBox struct {
	Values string `json:"-" gorm:"size:4294967295;"`
	Files  []File `json:",omitempty"`
}

func (MediaBox) ConfigureQorMeta

func (mediaBox MediaBox) ConfigureQorMeta(metaor resource.Metaor)

func (MediaBox) Crop

func (mediaBox MediaBox) Crop(res *admin.Resource, db *gorm.DB, mediaOption MediaOption) (err error)

func (*MediaBox) Scan

func (mediaBox *MediaBox) Scan(data interface{}) (err error)

func (MediaBox) URL

func (mediaBox MediaBox) URL(styles ...string) string

func (MediaBox) Value

func (mediaBox MediaBox) Value() (driver.Value, error)

type MediaBoxConfig

type MediaBoxConfig struct {
	RemoteDataResource *admin.Resource
	Sizes              map[string]*Size
	Max                uint
	admin.SelectManyConfig
}

MediaBoxConfig configure MediaBox metas

func (*MediaBoxConfig) ConfigureQorMeta

func (*MediaBoxConfig) ConfigureQorMeta(resource.Metaor)

func (*MediaBoxConfig) GetTemplate

func (*MediaBoxConfig) GetTemplate(context *admin.Context, metaType string) ([]byte, error)

type MediaHandler

type MediaHandler interface {
	CouldHandle(media Media) bool
	Handle(media Media, file multipart.File, option *Option) error
}

MediaHandler media library handler interface, defined which files could be handled, and the handler

type MediaLibrary

type MediaLibrary struct {
	gorm.Model
	SelectedType string
	File         MediaLibraryStorage `sql:"size:4294967295;" media_library:"url:/system/{{class}}/{{primary_key}}/{{column}}.{{extension}}"`
}

func (MediaLibrary) ConfigureQorResource

func (MediaLibrary) ConfigureQorResource(res resource.Resourcer)

func (*MediaLibrary) GetMediaOption

func (mediaLibrary *MediaLibrary) GetMediaOption() MediaOption

func (*MediaLibrary) GetSelectedType

func (mediaLibrary *MediaLibrary) GetSelectedType() string

func (*MediaLibrary) ScanMediaOptions

func (mediaLibrary *MediaLibrary) ScanMediaOptions(mediaOption MediaOption) error

func (*MediaLibrary) SetSelectedType

func (mediaLibrary *MediaLibrary) SetSelectedType(typ string)

type MediaLibraryInterface

type MediaLibraryInterface interface {
	ScanMediaOptions(MediaOption) error
	SetSelectedType(string)
	GetSelectedType() string
	GetMediaOption() MediaOption
}

type MediaLibraryStorage

type MediaLibraryStorage struct {
	FileSystem
	Sizes        map[string]*Size `json:",omitempty"`
	Video        string
	SelectedType string
	Description  string
}

func (MediaLibraryStorage) ConfigureQorMeta

func (mediaLibraryStorage MediaLibraryStorage) ConfigureQorMeta(metaor resource.Metaor)

func (MediaLibraryStorage) GetSizes

func (mediaLibraryStorage MediaLibraryStorage) GetSizes() map[string]*Size

func (*MediaLibraryStorage) Scan

func (mediaLibraryStorage *MediaLibraryStorage) Scan(data interface{}) (err error)

func (MediaLibraryStorage) Value

func (mediaLibraryStorage MediaLibraryStorage) Value() (driver.Value, error)

type MediaOption

type MediaOption struct {
	Video        string                 `json:",omitempty"`
	FileName     string                 `json:",omitempty"`
	URL          string                 `json:",omitempty"`
	OriginalURL  string                 `json:",omitempty"`
	CropOptions  map[string]*CropOption `json:",omitempty"`
	Sizes        map[string]*Size       `json:",omitempty"`
	SelectedType string                 `json:",omitempty"`
	Description  string                 `json:",omitempty"`
	Crop         bool
}

type Option

type Option map[string]string

Option media library option

func (Option) Get

func (option Option) Get(key string) string

Get used to get option with name

type Size

type Size struct {
	Width  int
	Height int
}

Size is a struct, used for `GetSizes` method, it will return a slice of Size, media library will crop images automatically based on it

type URLTemplater

type URLTemplater interface {
	GetURLTemplate(*Option) string
}

URLTemplater is a interface to return url template

Directories

Path Synopsis
handlers

Jump to

Keyboard shortcuts

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