upload

package
v2.2.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: AGPL-3.0 Imports: 20 Imported by: 48

README

上传设置

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//BackendUploadPath 后台上传网址路径
	BackendUploadPath = `/manager/upload`
	//FrontendUploadPath 前台上传网址路径
	FrontendUploadPath = `/user/upload`
	//SetURLParamDefaultValue 设置参数默认值
	SetURLParamDefaultValue func(*url.Values)
)
View Source
var (
	// ErrExistsFile 文件不存在
	ErrExistsFile = table.ErrExistsFile

	// BatchUpload 批量上传
	BatchUpload = driver.BatchUpload

	// StorerRegister 存储引擎注册
	StorerRegister = driver.Register

	// StorerGet 获取存储引擎构造器
	StorerGet = driver.Get

	// StorerAll 存储引擎集合
	StorerAll = driver.All
)
View Source
var DefaultChecker = func(ctx echo.Context, t table.TableInfoStorer) (subdir string, name string, err error) {
	refid := ctx.Formx(`refid`).String()
	timestamp := ctx.Formx(`time`).Int64()
	if len(refid) == 0 {
		refid = `0`
	}

	if ctx.Form(`token`) != Token(`refid`, refid, `time`, timestamp) {
		err = ctx.E(`令牌错误`)
		return
	}
	if time.Now().Local().Unix()-timestamp > UploadLinkLifeTime {
		err = ctx.E(`上传网址已过期`)
		return
	}
	subdir = fmt.Sprint(refid) + `/`

	t.SetTableID(refid)
	return
}

DefaultChecker 默认Checker

View Source
var (
	DefaultDBSaver = func(fileM *modelFile.File, result *uploadClient.Result, reader io.Reader) error {
		return nil
	}
)
View Source
var DefaultResponser = func(ctx echo.Context, field string, err error, imageURLs []string) (result echo.H, embed bool) {
	return echo.H{
		`files`: imageURLs,
	}, true
}
View Source
var EmptyFieldInfo = &FieldInfo{}
View Source
var GetTableInfo = table.GetTableInfo

GetTableInfo 从上传所属内容类型获取表相关信息

View Source
var NopChecker uploadClient.Checker = func(r *uploadClient.Result) error {
	return nil
}
View Source
var UploadLinkLifeTime int64 = 86400

UploadLinkLifeTime 上传链接生存时间

Functions

func BackendURL

func BackendURL() string

BackendURL 后台网址

func BackendUploadURL

func BackendUploadURL(subdir string, values ...interface{}) string

BackendUploadURL 构建后台上传网址

func CheckerRegister

func CheckerRegister(typ string, checker Checker, fieldNames ...string)

func CleanTempFile

func CleanTempFile(prefix string, deleter func(folderPath string) error) error

CleanTempFile 清理临时文件

func ConfigChecker

func ConfigChecker(ctx echo.Context, t table.TableInfoStorer) (subdir string, name string, err error)

ConfigChecker 系统配置文件上传

func DBSaverRegister

func DBSaverRegister(key string, dbsaver DBSaver)

func DBSaverUnregister

func DBSaverUnregister(keys ...string)

func FrontendURL

func FrontendURL() string

FrontendURL 前台网址

func FrontendUploadURL

func FrontendUploadURL(subdir string, values ...interface{}) string

FrontendUploadURL 构建前台上传网址

func ResponserAll

func ResponserAll() map[string]Responser

func ResponserRegister

func ResponserRegister(field string, responser Responser)

func SubdirAll

func SubdirAll() map[string]*SubdirInfo

func SubdirIsAllowed

func SubdirIsAllowed(subdir string, defaults ...string) bool

func SubdirUnregister

func SubdirUnregister(subdirList ...string)

func Token

func Token(values ...interface{}) string

Token 生成签名

func URLParam

func URLParam(subdir string, values ...interface{}) string

URLParam URLParam(`news`,`refid`,123)

Types

type APIKey

type APIKey interface {
	APIKey() string
}

APIKey API Key

type Checker

type Checker func(echo.Context, table.TableInfoStorer) (subdir string, name string, err error)

Checker 验证并生成子文件夹名称和文件名称

func CheckerGet

func CheckerGet(typ string, defaults ...string) Checker

type Constructor

type Constructor = driver.Constructor

Constructor 存储引擎构造函数

type DBSaver

type DBSaver func(fileM *modelFile.File, result *uploadClient.Result, reader io.Reader) error

func DBSaverGet

func DBSaverGet(key string, defaults ...string) DBSaver

type FieldInfo

type FieldInfo struct {
	Key   string
	Name  string
	Thumb []ThumbSize
	// contains filtered or unexported fields
}

func (*FieldInfo) AddChecker

func (info *FieldInfo) AddChecker(checker Checker) *FieldInfo

func (*FieldInfo) IsEmpty

func (info *FieldInfo) IsEmpty() bool

func (*FieldInfo) String

func (info *FieldInfo) String() string

type PrepareData

type PrepareData struct {
	StorerInfo storer.Info
	DBSaver    DBSaver
	Checker    uploadClient.Checker
	Checkin    Checker
	TableName  string
	FieldName  string
	FileType   string
	// contains filtered or unexported fields
}

func Prepare

func Prepare(ctx echo.Context, uploadType string, fileType string, storerInfo storer.Info) (*PrepareData, error)

Prepare 上传前的环境准备

func (*PrepareData) Close

func (p *PrepareData) Close() error

func (*PrepareData) Storer

func (p *PrepareData) Storer(ctx echo.Context) (Storer, error)

type Responser

type Responser func(ctx echo.Context, field string, err error, imageURLs []string) (result echo.H, embed bool)

func ResponserGet

func ResponserGet(field string) Responser

type Sizer

type Sizer = driver.Sizer

Sizer 尺寸接口

type Storer

type Storer = driver.Storer

Storer 文件存储引擎接口

type SubdirInfo

type SubdirInfo struct {
	Allowed     bool
	Key         string
	Name        string
	NameEN      string
	Description string
	// contains filtered or unexported fields
}

SubdirInfo 子目录信息

func NewSubdirInfo

func NewSubdirInfo(key, name string, checkers ...Checker) *SubdirInfo

func SubdirGet

func SubdirGet(subdir string) *SubdirInfo

func SubdirGetByTable

func SubdirGetByTable(table string) *SubdirInfo

func SubdirRegister

func SubdirRegister(subdir interface{}, nameAndDescription ...string) *SubdirInfo

func SubdirRegisterObject

func SubdirRegisterObject(info *SubdirInfo) *SubdirInfo

func (*SubdirInfo) AddFieldName

func (i *SubdirInfo) AddFieldName(fieldName string, checkers ...Checker) *SubdirInfo

func (*SubdirInfo) Checker

func (i *SubdirInfo) Checker() Checker

func (*SubdirInfo) CopyFrom

func (i *SubdirInfo) CopyFrom(other *SubdirInfo) *SubdirInfo

func (*SubdirInfo) FieldInfos

func (i *SubdirInfo) FieldInfos() []echo.KV

func (*SubdirInfo) FieldNames

func (i *SubdirInfo) FieldNames() []string

func (*SubdirInfo) GetField

func (i *SubdirInfo) GetField(field string) *FieldInfo

func (*SubdirInfo) GetNameEN

func (i *SubdirInfo) GetNameEN() string

func (*SubdirInfo) Listen

func (i *SubdirInfo) Listen(listeners *pkgListeners.Listeners, embedded bool, seperator ...string) *SubdirInfo

func (*SubdirInfo) MustChecker

func (i *SubdirInfo) MustChecker() Checker

func (*SubdirInfo) SetAllowed

func (i *SubdirInfo) SetAllowed(allowed bool) *SubdirInfo

func (*SubdirInfo) SetChecker

func (i *SubdirInfo) SetChecker(checker Checker, fieldNames ...string) *SubdirInfo

func (*SubdirInfo) SetDescription

func (i *SubdirInfo) SetDescription(description string) *SubdirInfo

func (*SubdirInfo) SetFieldName

func (i *SubdirInfo) SetFieldName(fieldNames ...string) *SubdirInfo

func (*SubdirInfo) SetName

func (i *SubdirInfo) SetName(name string) *SubdirInfo

func (*SubdirInfo) SetNameEN

func (i *SubdirInfo) SetNameEN(nameEN string) *SubdirInfo

func (*SubdirInfo) SetTable

func (i *SubdirInfo) SetTable(tableName string, fieldNames ...string) *SubdirInfo

func (*SubdirInfo) SetTableName

func (i *SubdirInfo) SetTableName(tableName string) *SubdirInfo

func (*SubdirInfo) String

func (i *SubdirInfo) String() string

func (*SubdirInfo) TableName

func (i *SubdirInfo) TableName() string

func (*SubdirInfo) ThumbSize

func (i *SubdirInfo) ThumbSize(fieldNames ...string) []ThumbSize

func (*SubdirInfo) ValidFieldName

func (i *SubdirInfo) ValidFieldName(fieldName string) bool

type ThumbSize

type ThumbSize struct {
	Width  float64
	Height float64
}

func (ThumbSize) String

func (t ThumbSize) String() string

Directories

Path Synopsis
s3

Jump to

Keyboard shortcuts

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