feat: improve driver

This commit is contained in:
Noah Hsu
2022-06-07 22:02:41 +08:00
parent 0d93a6aa41
commit 677047c80b
9 changed files with 88 additions and 27 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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")
)

View File

@ -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
}

View File

@ -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
View 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
}