feat: improve driver
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
package driver
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
NoNeedSetLink bool
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ import (
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
Other
|
||||
Meta
|
||||
Reader
|
||||
Writer
|
||||
Other
|
||||
}
|
||||
|
||||
type Other interface {
|
||||
type Meta interface {
|
||||
Config() Config
|
||||
Init(ctx context.Context, account model.Account) error
|
||||
Update(ctx context.Context, account model.Account) error
|
||||
@ -20,8 +21,12 @@ type Other interface {
|
||||
GetAccount() model.Account
|
||||
}
|
||||
|
||||
type Other interface {
|
||||
Other(ctx context.Context, data interface{}) (interface{}, error)
|
||||
}
|
||||
|
||||
type Reader interface {
|
||||
File(ctx context.Context, path string) (*FileInfo, error)
|
||||
File(ctx context.Context, path string) (FileInfo, error)
|
||||
List(ctx context.Context, path string) ([]FileInfo, error)
|
||||
Link(ctx context.Context, args LinkArgs) (*Link, error)
|
||||
}
|
||||
|
@ -5,4 +5,7 @@ import "errors"
|
||||
var (
|
||||
ErrorDirNotFound = errors.New("directory not found")
|
||||
ErrorObjectNotFound = errors.New("object not found")
|
||||
ErrNotImplement = errors.New("not implement")
|
||||
ErrNotSupport = errors.New("not support")
|
||||
ErrRelativePath = errors.New("access using relative path is not allowed")
|
||||
)
|
||||
|
@ -6,9 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type FileInfo interface {
|
||||
GetSize() uint64
|
||||
GetName() string
|
||||
GetModTime() time.Time
|
||||
GetSize() int64
|
||||
ModTime() time.Time
|
||||
IsDir() bool
|
||||
}
|
||||
|
||||
type FileStream interface {
|
||||
@ -16,3 +17,11 @@ type FileStream interface {
|
||||
FileInfo
|
||||
GetMimetype() string
|
||||
}
|
||||
|
||||
type URL interface {
|
||||
URL() string
|
||||
}
|
||||
|
||||
type Thumbnail interface {
|
||||
Thumbnail() string
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ type New func() Driver
|
||||
|
||||
var driversMap = map[string]New{}
|
||||
|
||||
func RegisterDriver(name string, new New) {
|
||||
log.Infof("register driver: [%s]", name)
|
||||
driversMap[name] = new
|
||||
func RegisterDriver(config Config, driver New) {
|
||||
log.Infof("register driver: [%s]", config.Name)
|
||||
driversMap[config.Name] = driver
|
||||
}
|
||||
|
26
internal/model/file.go
Normal file
26
internal/model/file.go
Normal file
@ -0,0 +1,26 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type File struct {
|
||||
Name string
|
||||
Size uint64
|
||||
Modified time.Time
|
||||
IsFolder bool
|
||||
}
|
||||
|
||||
func (f File) GetName() string {
|
||||
return f.Name
|
||||
}
|
||||
|
||||
func (f File) GetSize() uint64 {
|
||||
return f.Size
|
||||
}
|
||||
|
||||
func (f File) ModTime() time.Time {
|
||||
return f.Modified
|
||||
}
|
||||
|
||||
func (f File) IsDir() bool {
|
||||
return f.IsFolder
|
||||
}
|
Reference in New Issue
Block a user