Documentation ¶
Index ¶
- Constants
- Variables
- func CleanDomain(fileURL string) string
- func EmbeddedRes(v string, fn func(string, int64)) [][]string
- func ExtensionRegexpEnd(noCaptures ...bool) string
- func FileTypeByName(filename string) string
- func ParseDomain(fileURL string) (scheme string, domain string)
- func ParseSubdir(fileURL string) string
- func RelatedRes(v string, fn func(string, int64), seperator ...string)
- func ReplaceEmbeddedRes(v string, reses map[string]string) (r string)
- func ReplaceEmbeddedResID(v string, reses map[uint64]string) (r string)
- func ReplaceRelatedRes(v string, reses map[string]string, seperator ...string) (r string)
- func ReplaceRelatedResID(v string, reses map[uint64]string, seperator ...string) (r string)
- func URLToFile(fileURL string) string
- type Config
- func (c *Config) CheckTypeExtension(typ string, extension string) bool
- func (c *Config) DetectType(extension string) string
- func (c *Config) Extensions(typ string) (r []string)
- func (c *Config) FileIcon(typ string) string
- func (c *Config) Init()
- func (c *Config) MaxSizeBytes(typ string) int
- func (c *Config) Reload() error
- func (c *Config) SetDefaults()
- type FileType
Constants ¶
View Source
const Name = `upload`
Variables ¶
View Source
var ( // UploadURLPath 上传文件网址访问路径 UploadURLPath = defaultUploadURLPath // UploadDir 定义上传目录(首尾必须带“/”) UploadDir = defaultUploadDir // AllowedExtensions 被允许上传的文件的扩展名 AllowedExtensions = []string{ `.jpeg`, `.jpg`, `.gif`, `.png`, `.mp4`, } )
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)) cfg := Get() if !com.InSlice(ext, cfg.AllowedExtensions) { return errors.WithMessage(ErrUnsupportedExtension, ext) } if !strings.HasPrefix(src, UploadURLPath) { return ErrIncorrectPath } return nil }
IsRightUploadFile 是否是正确的上传文件
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 EmbeddedRes ¶
EmbeddedRes 获取正文中的资源
func ExtensionRegexpEnd ¶
func ParseDomain ¶
func RelatedRes ¶
RelatedRes 获取字段中关联的资源
func ReplaceEmbeddedRes ¶
ReplaceEmbeddedRes 替换正文中的资源网址
func ReplaceEmbeddedResID ¶
ReplaceEmbeddedResID 替换正文中的资源网址
func ReplaceRelatedRes ¶
ReplaceRelatedRes 替换字段中的资源网址
func ReplaceRelatedResID ¶
ReplaceRelatedResID 替换字段中的资源网址
Types ¶
type Config ¶
type Config struct { FileTypes map[string]*FileType `json:"fileTypes"` MaxSize string `json:"maxSize"` Icon string `json:"icon"` AllowedExtensions []string `json:"allowedExtensions"` // contains filtered or unexported fields }
func (*Config) CheckTypeExtension ¶
CheckTypeExtension 检查类型扩展名
func (*Config) DetectType ¶
DetectType 根据扩展名判断类型
func (*Config) Extensions ¶
Extensions 文件类型文件扩展名
func (*Config) MaxSizeBytes ¶
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
type FileType ¶
type FileType struct { Icon string `json:"icon"` Extensions []string `json:"extensions"` MIMEs []string `json:"mimes"` MIMEKeywords []string `json:"mimeKeywords"` MaxSize string `json:"maxSize"` Description string `json:"description"` Disabled bool `json:"disabled"` // contains filtered or unexported fields }
func (*FileType) MaxSizeBytes ¶
Click to show internal directories.
Click to hide internal directories.