filesystem

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MimeType = map[string]string{
	"application/xml": "xml",
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":         "xlsx",
	"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document":   "docx",
	"application/vnd.android.package-archive":                                   "apk",
	"application/msword":            "doc",
	"application/ogg":               "ogg",
	"application/pdf":               "pdf",
	"application/vnd.ms-excel":      "xls",
	"application/vnd.ms-powerpoint": "ppt",
	"audio/mpeg":                    "mp2",
	"audio/mp3":                     "mp3",
	"audio/midi":                    "mid",
	"audio/x-wav":                   "wav",
	"audio/x-ms-wma":                "wma",
	"audio/x-ms-wax":                "wax",
	"audio/x-mpegurl":               "m3u",
	"image/bmp":                     "bmp",
	"image/gif":                     "gif",
	"image/ief":                     "ief",
	"image/png":                     "png",
	"image/x-rgb":                   "rgb",
	"image/cgm":                     "cgm",
	"image/x-icon":                  "ico",
	"image/vnd.microsoft.icon":      "ico",
	"image/jp2":                     "jp2",
	"image/jpeg":                    "jpg",
	"image/jpe":                     "jpg",
	"image/jpg":                     "jpg",
	"image/webp":                    "webp",
	"image/svg":                     "svg",
	"image/svg+xml":                 "svg",
	"image/tiff":                    "tif",
	"text/csv":                      "csv",
	"text/plain":                    "txt",
	"text/rtf":                      "rtf",
	"video/quicktime":               "mov",
	"video/mp4":                     "mp4",
	"video/mpeg":                    "mpg",
	"video/x-flv":                   "flv",
	"video/x-ms-wm":                 "wm",
	"video/x-msvideo":               "avi",
	"video/x-sgi-movie":             "movie",
	"video/3gpp":                    "3gp",
}

Functions

func DeleteFile

func DeleteFile(userType string, id uint64)

DeleteFile 删除不存在的文件记录

func IsExistsMimeAllow

func IsExistsMimeAllow(value string, array []string) bool

IsExistsMimeAllow 判断文件MimeType

func SaveFile

func SaveFile(userType string, userId uint64, info Info) (id uint64, err error)

SaveFile 保存文件

Types

type Filesystem

type Filesystem struct {
	// contains filtered or unexported fields
}

func Instance

func Instance() *Filesystem

Instance 获取单例 注意,单例仅仅为了获取filesystem及storage实例,不涉及任何上传相关的实例,如果要上传文件,还是得使用NewFilesystem生成实例

func NewFilesystem

func NewFilesystem(userType string, userId uint64) (*Filesystem, error)

NewFilesystem 创建Filesystem

func (*Filesystem) DeleteFile

func (filesystem *Filesystem) DeleteFile(filePath string) (bool, error)

DeleteFile 删除文件

func (*Filesystem) DeleteMultipleFile

func (filesystem *Filesystem) DeleteMultipleFile(filePath []string) (bool, error)

DeleteMultipleFile 删除多个文件

func (*Filesystem) DownloadNetworkFile

func (filesystem *Filesystem) DownloadNetworkFile(networkFileUrl, filePath string) error

DownloadNetworkFile 下载网络文件到本地

func (*Filesystem) EditorUpload

func (filesystem *Filesystem) EditorUpload(fileBytes []byte, allow config.FileAllow, field, filename, mime, ext string) (Info, error)

EditorUpload 编辑器文件上传

func (*Filesystem) FullPath

func (filesystem *Filesystem) FullPath(filePath string) string

FullPath 完整路径

func (*Filesystem) HasDir

func (filesystem *Filesystem) HasDir(file string) bool

func (*Filesystem) HasFile

func (filesystem *Filesystem) HasFile(filePath string) bool

HasFile 判断文件是否存在

func (*Filesystem) MkDir

func (filesystem *Filesystem) MkDir(dir string, mode os.FileMode) (bool, error)

func (*Filesystem) NetworkFileSaveObject

func (filesystem *Filesystem) NetworkFileSaveObject(networkFileUrl, filePath, mime string) (bool, error)

NetworkFileSaveObject 保存网络文件到存储器

func (*Filesystem) OriginalPath

func (filesystem *Filesystem) OriginalPath(filePath string) string

OriginalPath 原始文件路径

func (*Filesystem) SaveFile

func (filesystem *Filesystem) SaveFile(dstFile string, srcFile io.Reader, mimeType string) (bool, error)

func (*Filesystem) Storage

func (filesystem *Filesystem) Storage() adapter.Adapter

func (*Filesystem) Upload

func (filesystem *Filesystem) Upload(file *multipart.FileHeader, allow config.FileAllow, field string) (Info, error)

Upload 文件上传

type Info

type Info struct {
	Id       uint64 `json:"id"`
	Path     string `json:"path"`
	FileMd5  string `json:"file_md5"`
	Sha1     string `json:"sha1"`
	Filename string `json:"filename"`
	Ext      string `json:"ext"`
	MimeType string `json:"mime_type"`
	FileSize uint64 `json:"file_size"`
	Width    uint64 `json:"width"`
	Height   uint64 `json:"height"`
	Attach   string `json:"attach"`
	Code     int    `json:"code"`
	IsImage  uint8  `json:"is_image"`
}

Info 文件信息

func FileExists

func FileExists(userType, userId string, sha1 string, md5 string) (Info, error)

FileExists 查询文件是否存在

type Size

type Size interface {
	Size() int64
}

type Stat

type Stat interface {
	Stat() (os.FileInfo, error)
}

type Uploader

type Uploader struct {
	// contains filtered or unexported fields
}

func NewUploader

func NewUploader(storage adapter.Adapter, allow config.FileAllow, field string) *Uploader

func (*Uploader) EditorUpload

func (uploader *Uploader) EditorUpload(userType string, userId uint64, fileBytes []byte, filename, mime, ext string) (Info, error)

EditorUpload 编辑器文件上传

func (*Uploader) HasFile

func (uploader *Uploader) HasFile(filePath string) bool

func (*Uploader) Upload

func (uploader *Uploader) Upload(userType string, fileHeader *multipart.FileHeader) (Info, error)

Upload 文件上传

Jump to

Keyboard shortcuts

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