Refactor: use universal FileHeader when handling file upload, remove usage of global ctx with FileHeader, SavePath, DisableOverwrite
parent
8a222e7df4
commit
868a88e5fc
@ -1,38 +0,0 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// FileStream 用户传来的文件
|
||||
type FileStream struct {
|
||||
File io.ReadCloser
|
||||
Size uint64
|
||||
VirtualPath string
|
||||
Name string
|
||||
MIMEType string
|
||||
}
|
||||
|
||||
func (file FileStream) Read(p []byte) (n int, err error) {
|
||||
return file.File.Read(p)
|
||||
}
|
||||
|
||||
func (file FileStream) GetMIMEType() string {
|
||||
return file.MIMEType
|
||||
}
|
||||
|
||||
func (file FileStream) GetSize() uint64 {
|
||||
return file.Size
|
||||
}
|
||||
|
||||
func (file FileStream) Close() error {
|
||||
return file.File.Close()
|
||||
}
|
||||
|
||||
func (file FileStream) GetFileName() string {
|
||||
return file.Name
|
||||
}
|
||||
|
||||
func (file FileStream) GetVirtualPath() string {
|
||||
return file.VirtualPath
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package fsctx
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WriteMode int
|
||||
|
||||
const (
|
||||
Overwrite WriteMode = iota
|
||||
Append
|
||||
Create
|
||||
)
|
||||
|
||||
// FileStream 用户传来的文件
|
||||
type FileStream struct {
|
||||
Mode WriteMode
|
||||
Hidden bool
|
||||
LastModified time.Time
|
||||
Metadata map[string]string
|
||||
File io.ReadCloser
|
||||
Size uint64
|
||||
VirtualPath string
|
||||
Name string
|
||||
MIMEType string
|
||||
SavePath string
|
||||
}
|
||||
|
||||
func (file *FileStream) Read(p []byte) (n int, err error) {
|
||||
return file.File.Read(p)
|
||||
}
|
||||
|
||||
func (file *FileStream) GetMIMEType() string {
|
||||
return file.MIMEType
|
||||
}
|
||||
|
||||
func (file *FileStream) GetSize() uint64 {
|
||||
return file.Size
|
||||
}
|
||||
|
||||
func (file *FileStream) Close() error {
|
||||
return file.File.Close()
|
||||
}
|
||||
|
||||
func (file *FileStream) GetFileName() string {
|
||||
return file.Name
|
||||
}
|
||||
|
||||
func (file *FileStream) GetVirtualPath() string {
|
||||
return file.VirtualPath
|
||||
}
|
||||
|
||||
func (file *FileStream) GetMode() WriteMode {
|
||||
return file.Mode
|
||||
}
|
||||
|
||||
func (file *FileStream) GetMetadata() map[string]string {
|
||||
return file.Metadata
|
||||
}
|
||||
|
||||
func (file *FileStream) GetLastModified() time.Time {
|
||||
return file.LastModified
|
||||
}
|
||||
|
||||
func (file *FileStream) IsHidden() bool {
|
||||
return file.Hidden
|
||||
}
|
||||
|
||||
func (file *FileStream) GetSavePath() string {
|
||||
return file.SavePath
|
||||
}
|
||||
|
||||
// FileHeader 上传来的文件数据处理器
|
||||
type FileHeader interface {
|
||||
io.Reader
|
||||
io.Closer
|
||||
GetSize() uint64
|
||||
GetMIMEType() string
|
||||
GetFileName() string
|
||||
GetVirtualPath() string
|
||||
GetMode() WriteMode
|
||||
GetMetadata() map[string]string
|
||||
GetLastModified() time.Time
|
||||
IsHidden() bool
|
||||
GetSavePath() string
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package local
|
||||
package fsctx
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
Loading…
Reference in new issue