upload

package
v2.0.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: AGPL-3.0 Imports: 9 Imported by: 0

README

上传设置

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultChecker = func(ctx echo.Context) (subdir string, name string, err error) {
	refid := ctx.Formx(`refid`).Uint64()
	timestamp := ctx.Formx(`time`).Int64()

	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) + `/`

	return
}
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 UploadLinkLifeTime int64 = 86400

UploadLinkLifeTime 上传链接生存时间

Functions

func BatchUpload

func BatchUpload(
	ctx echo.Context,
	fieldName string,
	dstNamer func(*multipart.FileHeader) (dst string, err error),
	uploader Uploader,
) ([]string, error)

func CheckerAll

func CheckerAll() map[string]Checker

func CheckerRegister

func CheckerRegister(typ string, checker Checker)

func CleanTempFile

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

CleanTempFile 清理临时文件

func ResponserAll

func ResponserAll() map[string]Responser

func ResponserRegister

func ResponserRegister(field string, responser Responser)

func SubdirAll

func SubdirAll() map[string]bool

func SubdirIsAllowed

func SubdirIsAllowed(subdir string) bool

func SubdirRegister

func SubdirRegister(subdir string, allow bool)

func Token

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

func UploaderAll

func UploaderAll(engine string) map[string]Constructor

func UploaderRegister

func UploaderRegister(engine string, constructor Constructor)

Types

type APIKey

type APIKey interface {
	APIKey() string
}

type Checker

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

func CheckerGet

func CheckerGet(typ string) Checker

type Constructor

type Constructor func(typ string) Uploader
var DefaultConstructor Constructor

func UploaderGet

func UploaderGet(engine string) Constructor

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 Uploader

type Uploader interface {
	Engine() string
	Put(dst string, src io.Reader, size int64) (string, error)
	Get(file string) (io.ReadCloser, error)
	Delete(file string) error
	DeleteDir(dir string) error
	PublicURL(dst string) string
	FixURL(content string, embedded ...bool) string
	FixURLWithParams(content string, values url.Values, embedded ...bool) string
}

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

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