upload

package
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: AGPL-3.0 Imports: 16 Imported by: 0

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 DefaultChecker = func(ctx echo.Context, tis 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) + `/`

	tis.SetTableID(refid)
	return
}
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 (
	ErrExistsFile = table.ErrExistsFile
)
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 BatchUpload

func BatchUpload(
	ctx echo.Context,
	fieldName string,
	dstNamer func(*uploadClient.Result) (dst string, err error),
	storer Storer,
	callback func(*uploadClient.Result, multipart.File) error,
) (results uploadClient.Results, err error)

func CheckerRegister

func CheckerRegister(typ string, checker Checker)

func CleanTempFile

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

CleanTempFile 清理临时文件

func ConfigChecker

func ConfigChecker(ctx echo.Context, tis 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 StorerAll

func StorerAll(engine string) map[string]Constructor

func StorerRegister

func StorerRegister(engine string, constructor Constructor)

func SubdirAll

func SubdirAll() map[string]*SubdirInfo

func SubdirIsAllowed

func SubdirIsAllowed(subdir 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)

func CheckerGet

func CheckerGet(typ string) Checker

type Constructor

type Constructor func(ctx context.Context, typ string) Storer
var DefaultConstructor Constructor

func StorerGet

func StorerGet(engine string) Constructor

type DBSaver

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

func DBSaverGet

func DBSaverGet(key string) DBSaver

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 interface {
	Size() int64
}

type Storer

type Storer interface {
	// 引擎名
	Name() string

	// FileDir 文件夹物理路径
	FileDir(subpath string) string

	// URLDir 文件夹网址路径
	URLDir(subpath string) string

	// Put 保存文件
	Put(dst string, src io.Reader, size int64) (savePath string, viewURL string, err error)

	// Get 获取文件
	Get(file string) (io.ReadCloser, error)

	// Exists 文件是否存在
	Exists(file string) (bool, error)

	// FileInfo 文件信息
	FileInfo(file string) (os.FileInfo, error)

	// SendFile 输出文件到浏览器
	SendFile(ctx echo.Context, file string) error

	// Delete 删除文件
	Delete(file string) error

	// DeleteDir 删除目录
	DeleteDir(dir string) error

	// PublicURL 文件网址
	PublicURL(dst string) string

	// URLToFile 网址转文件物理路径
	URLToFile(viewURL string) string

	// FixURL 修正网址
	FixURL(content string, embedded ...bool) string

	// FixURLWithParams 修正网址并增加网址参数
	FixURLWithParams(content string, values url.Values, embedded ...bool) string

	// Close 关闭连接
	Close() error
}

type SubdirInfo

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

SubdirInfo 子目录信息

func SubdirGet

func SubdirGet(subdir string) *SubdirInfo

func SubdirRegister

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

func SubdirRegisterObject

func SubdirRegisterObject(subdir string, info *SubdirInfo) *SubdirInfo

func (*SubdirInfo) Checker

func (i *SubdirInfo) Checker() Checker

func (*SubdirInfo) FieldName

func (i *SubdirInfo) FieldName() string

func (*SubdirInfo) GetNameEN

func (i *SubdirInfo) GetNameEN() string

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) *SubdirInfo

func (*SubdirInfo) SetDescription

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

func (*SubdirInfo) SetFieldName

func (i *SubdirInfo) SetFieldName(fieldName string) *SubdirInfo

func (*SubdirInfo) SetName

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

func (*SubdirInfo) SetNameEN

func (i *SubdirInfo) SetNameEN(nameEN 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

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

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