helper

package
v3.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UploadURLPath 上传文件网址访问路径
	UploadURLPath = defaultUploadURLPath

	// UploadDir 定义上传目录(首尾必须带“/”)
	UploadDir = defaultUploadDir

	// AllowedUploadFileExtensions 被允许上传的文件的扩展名
	AllowedUploadFileExtensions = []string{
		`.jpeg`, `.jpg`, `.gif`, `.png`,
	}

	// FileTypeIcon 文件类型icon
	FileTypeIcon = upload.FileTypeIcon

	// DetectFileType 根据文件扩展名判断文件类型
	DetectFileType = upload.DetectType

	// TypeRegister 注册文件扩展名
	TypeRegister = upload.TypeRegister
)
View Source
var (
	ErrUnsupportedExtension = errors.New("不支持的文件扩展名")
	ErrIncorrectPath        = errors.New("路径不合法")
)
View Source
var IsRightUploadFile = func(ctx echo.Context, src string) error {
	src = path.Clean(src)
	ext := strings.ToLower(path.Ext(src))
	if !com.InSlice(ext, AllowedUploadFileExtensions) {
		return errors.WithMessage(ErrIncorrectPath, ext)
	}
	if !strings.HasPrefix(src, UploadURLPath) {
		return ErrIncorrectPath
	}
	return nil
}

IsRightUploadFile 是否是正确的上传文件

View Source
var ParseAnyFileName = func(s string) []string {
	files := anyFileRegexp.FindAllString(s, -1)
	return files
}

ParseAnyFileName 从文本中解析出任意上传文件名称

View Source
var ParsePersistentFileName = func(s string) []string {
	files := persistentFileRegexp.FindAllString(s, -1)
	return files
}

ParsePersistentFileName 从文本中解析出正式文件名称

View Source
var ParseTemporaryFileName = func(s string) []string {
	files := temporaryFileRegexp.FindAllString(s, -1)
	return files
}

ParseTemporaryFileName 从文本中解析出临时文件名称

View Source
var ReplaceAnyFileName = func(s string, repl func(string) string) string {
	return anyFileRegexp.ReplaceAllStringFunc(s, repl)
}

ReplaceAnyFileName 从文本中替换任意上传文件名称

View Source
var ReplacePlaceholder = func(s string, repl func(string) string) string {
	return placeholderRegexp.ReplaceAllStringFunc(s, func(find string) string {
		id := find[9 : len(find)-1]
		return repl(id)
	})
}

ReplacePlaceholder 从文本中替换占位符

Functions

func CleanDomain

func CleanDomain(fileURL string) string

func EmbeddedRes

func EmbeddedRes(v string, fn func(string, int64)) [][]string

EmbeddedRes 获取正文中的资源

func ExtensionRegexpEnd

func ExtensionRegexpEnd(noCaptures ...bool) string

func ExtensionRegister

func ExtensionRegister(extensions ...string)

func ExtensionUnregister

func ExtensionUnregister(extensions ...string)

func FileTypeByName

func FileTypeByName(filename string) string

FileTypeByName 根据文件名判断文件类型

func Init

func Init(pathPrefix string)

func ParseDomain

func ParseDomain(fileURL string) (scheme string, domain string)

func ParseSubdir

func ParseSubdir(fileURL string) string

ParseSubdir 从文件网址中获取子文件夹名

func RelatedRes

func RelatedRes(v string, fn func(string, int64), seperator ...string)

RelatedRes 获取字段中关联的资源

func ReplaceEmbeddedRes

func ReplaceEmbeddedRes(v string, reses map[string]string) (r string)

ReplaceEmbeddedRes 替换正文中的资源网址

func ReplaceEmbeddedResID

func ReplaceEmbeddedResID(v string, reses map[uint64]string) (r string)

ReplaceEmbeddedResID 替换正文中的资源网址

func ReplaceRelatedRes

func ReplaceRelatedRes(v string, reses map[string]string, seperator ...string) (r string)

ReplaceRelatedRes 替换字段中的资源网址

func ReplaceRelatedResID

func ReplaceRelatedResID(v string, reses map[uint64]string, seperator ...string) (r string)

ReplaceRelatedResID 替换字段中的资源网址

func URLToFile

func URLToFile(fileURL string) string

URLToFile 文件网址转为存储路径

Types

This section is empty.

Jump to

Keyboard shortcuts

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