media

package module
v0.0.0-...-a990035 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: MIT Imports: 35 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

View Source
const (
	FIELD_TAG_NAME = "media"
	OPT_STORAGE    = FIELD_TAG_NAME + ".storage"
)

Variables

View Source
var (
	PKG       = path_helpers.GetCalledDir()
	I18NGROUP = i18nmod.PkgToGroup(PKG)
)
View Source
var DB_DELETE_IGNORE = PKG + ".delete.ignore"
View Source
var E_DELETE = PKG + ":delete"
View Source
var (
	// URLTemplate default URL template
	URLTemplate = "/system/{{class}}/{{primary_key_path}}/{{column}}/{{filename_slug}}"
)

Functions

func GetImageFormat

func GetImageFormat(url string) (*imaging.Format, error)

func Handle

func Handle(media Media, cb func(name string, handle MediaHandler) error) (err error)

func IgnoreCallback

func IgnoreCallback(db *aorm.DB) *aorm.DB

func IsIgnoreCallback

func IsIgnoreCallback(v interface{}) bool

func IsImageFormat

func IsImageFormat(name string) bool

IsImageFormat check filename is image or not

func IsSVGFormat

func IsSVGFormat(name string) bool

func IsVideoFormat

func IsVideoFormat(name string) bool

IsVideoFormat check filename is video or not

func MediaHandlers

func MediaHandlers() map[string]MediaHandler

func MediaStyleURL

func MediaStyleURL(url, style string) string

func MediaURL

func MediaURL(base string, parts ...string) string

func RegisterCallbacks

func RegisterCallbacks(db *aorm.DB)

RegisterCallbacks register callback into GORM DB

func RegisterMediaHandler

func RegisterMediaHandler(name string, handler MediaHandler)

RegisterMediaHandler register Media library handler

func VideoFormats

func VideoFormats() []string

Types

type AcceptExts

type AcceptExts interface {
	FileExts() []string
}

type AcceptTypes

type AcceptTypes interface {
	FileTypes() []string
}

type Base

type Base struct {
	FileName   string
	Url        string
	FileSize   int64
	Delete     bool       `json:"-"`
	FileHeader FileHeader `json:"-"`
	Reader     io.Reader  `json:"-"`
	// contains filtered or unexported fields
}

Base defined a base struct for storages

func (*Base) AfterScan

func (b *Base) AfterScan(db *aorm.DB, field *aorm.Field)

gorm/scope.scan()

func (*Base) AllNames

func (b *Base) AllNames(m Media) []string

func (Base) AormDataType

func (Base) AormDataType(dialect aorm.Dialector) string

func (Base) ConfigureQorMetaBeforeInitialize

func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor)

ConfigureQorMetaBeforeInitialize configure this field for Qor Admin

func (*Base) ContextScan

func (b *Base) ContextScan(ctx *core.Context, data interface{}) (err error)

func (Base) DBValue

func (b Base) DBValue(media Media) (driver.Value, error)

func (Base) Deletable

func (b Base) Deletable() bool

func (Base) Ext

func (b Base) Ext() string

func (*Base) FieldOption

func (b *Base) FieldOption() *Option

func (Base) FullURL

func (b Base) FullURL(ctx *core.Context, styles ...string) (url string)

func (Base) FullURLU

func (b Base) FullURLU(ctx *core.Context, styles ...string) (url string)

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) GetOrSetFieldOption

func (b *Base) GetOrSetFieldOption() *Option

func (Base) GetURL

func (b Base) GetURL(scope *aorm.Scope, field *aorm.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) HasFile

func (b Base) HasFile() bool

func (*Base) Init

func (b *Base) Init(site *core.Site, field *aorm.Field)

func (Base) IsImage

func (b Base) IsImage() bool

IsImage return if it is an image

func (Base) IsSVG

func (b Base) IsSVG() bool

func (Base) IsVideo

func (b Base) IsVideo() bool

func (Base) IsZero

func (b Base) IsZero() bool

func (*Base) MediaScan

func (b *Base) MediaScan(ctx *Context, data interface{}) (err error)

func (*Base) Names

func (b *Base) Names() (names []string)

func (*Base) OlderURL

func (b *Base) OlderURL() []string

func (*Base) Remove

func (b *Base) Remove(url string) (found bool, err error)

func (*Base) RemoveAll

func (b *Base) RemoveAll(media Media) (found bool, err error)

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)

func (*Base) ScanBytes

func (b *Base) ScanBytes(ctx *Context, data []byte) (err error)

func (*Base) Set

func (b *Base) Set(ctx *Context, data interface{}) (err error)

func (*Base) SetFieldOption

func (b *Base) SetFieldOption(option *Option)

func (*Base) SetSite

func (b *Base) SetSite(site *core.Site)

func (*Base) SetStorage

func (b *Base) SetStorage(storage oss.NamedStorageInterface)

func (*Base) Site

func (b *Base) Site() *core.Site

func (*Base) Storage

func (b *Base) Storage() oss.NamedStorageInterface

func (*Base) Store

func (b *Base) Store(url string, reader io.Reader) error

func (Base) String

func (b Base) String() string

String return file's url

func (*Base) SystemNames

func (b *Base) SystemNames() (names []string)

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 Context

type Context struct {
	Media Media
	Data  []map[interface{}]interface{}
}

func NewContext

func NewContext(media Media, data ...map[interface{}]interface{}) *Context

func (*Context) GetOk

func (c *Context) GetOk(key interface{}) (value interface{}, ok bool)

func (*Context) With

func (c *Context) With(data map[interface{}]interface{}) func()

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 FullURL

type FullURL interface {
	FullURL() string
}

type FullURLContext

type FullURLContext interface {
	FullURL(ctx *core.Context) string
}

type FullURLContextStyle

type FullURLContextStyle interface {
	FullURL(ctx *core.Context, styles ...string) string
}

type FullURLStyle

type FullURLStyle interface {
	FullURL(styles ...string) string
}

type MaxSize

type MaxSize interface {
	MaxSize() uint64
}

type Media

type Media interface {
	IsZero() bool
	HasFile() bool

	sql.Scanner

	Site() *core.Site
	SetSite(site *core.Site)
	Storage() oss.NamedStorageInterface
	SetStorage(storage oss.NamedStorageInterface)
	Init(site *core.Site, field *aorm.Field)
	FieldOption() *Option
	SetFieldOption(option *Option)

	Set(ctx *Context, data interface{}) (err error)

	Value() (driver.Value, error)
	GetURL(scope *aorm.Scope, field *aorm.Field, templater URLTemplater) string

	GetFileHeader() FileHeader
	GetFileName() string

	Store(url string, reader io.Reader) error
	Retrieve(url string) (*os.File, error)
	Remove(url string) (found bool, err error)
	RemoveAll(m Media) (found bool, err error)

	ScanBytes(ctx *Context, data []byte) error

	IsImage() bool

	GetURLTemplate(option *Option) string
	URL(style ...string) string
	FullURL(ctx *core.Context, style ...string) string
	Ext() string
	String() string

	Names() []string
	SystemNames() []string
	AllNames(m Media) []string

	MediaScan(ctx *Context, data interface{}) (err error)

	OlderURL() []string

	Deletable() bool
}

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

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 Option

type Option map[string]string

Option media library option

func ParseTagOption

func ParseTagOption(str string) *Option

func (Option) Get

func (option Option) Get(key string) string

Get used to get option with name

func (*Option) GetPrefix

func (option *Option) GetPrefix(prefix string) map[string]string

GetPrefix used to get options map by prefix

func (*Option) Merge

func (option *Option) Merge(m ...map[string]string) *Option

Merge used to merge options map

func (*Option) MergePrefix

func (option *Option) MergePrefix(prefix string, m ...map[string]string) *Option

MergePrefix used to merge options map with prefix

func (*Option) ParseFieldTag

func (option *Option) ParseFieldTag(tagName string, tag *reflect.StructTag) *Option

ParseFieldTag used to parse field tag with prefix

func (*Option) ParseTagPrefix

func (option *Option) ParseTagPrefix(prefix, tag string) *Option

ParseTagPrefix used to parse field tag with prefix

func (*Option) Set

func (option *Option) Set(key, value string) *Option

Get used to set option with name

func (*Option) SetDefault

func (option *Option) SetDefault(key, value string) *Option

SetDefault used to set default option with name

type Plugin

type Plugin struct {
	db.DBNames
	plug.EventDispatcher
}

func (*Plugin) OnRegister

func (p *Plugin) OnRegister()

type URL

type URL interface {
	URL() string
}

type URLContext

type URLContext interface {
	URL(ctx *core.Context) string
}

type URLContextStyle

type URLContextStyle interface {
	URL(ctx *core.Context, styles ...string) string
}

type URLStyle

type URLStyle interface {
	URL(styles ...string) string
}

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