feat: add baidu_netdisk
driver
This commit is contained in:
@ -13,6 +13,7 @@ type Obj interface {
|
||||
ModTime() time.Time
|
||||
IsDir() bool
|
||||
GetID() string
|
||||
GetPath() string
|
||||
}
|
||||
|
||||
type FileStreamer interface {
|
||||
@ -32,8 +33,8 @@ type Thumb interface {
|
||||
Thumb() string
|
||||
}
|
||||
|
||||
type SetID interface {
|
||||
SetID(id string)
|
||||
type SetPath interface {
|
||||
SetPath(path string)
|
||||
}
|
||||
|
||||
func SortFiles(objs []Obj, orderBy, orderDirection string) {
|
||||
|
@ -4,6 +4,7 @@ import "time"
|
||||
|
||||
type Object struct {
|
||||
ID string
|
||||
Path string
|
||||
Name string
|
||||
Size int64
|
||||
Modified time.Time
|
||||
@ -30,8 +31,12 @@ func (o *Object) GetID() string {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Object) SetID(id string) {
|
||||
o.ID = id
|
||||
func (o *Object) GetPath() string {
|
||||
return o.Path
|
||||
}
|
||||
|
||||
func (o *Object) SetPath(id string) {
|
||||
o.Path = id
|
||||
}
|
||||
|
||||
type Thumbnail struct {
|
||||
|
@ -35,6 +35,7 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "failed get dir")
|
||||
}
|
||||
log.Debugf("list dir: %+v", dir)
|
||||
if !dir.IsDir() {
|
||||
return nil, errors.WithStack(errs.NotFolder)
|
||||
}
|
||||
@ -94,7 +95,7 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
|
||||
}
|
||||
if r, ok := storage.GetAddition().(driver.IRootFolderPath); ok && isRoot(path, r.GetRootFolderPath()) {
|
||||
return &model.Object{
|
||||
ID: r.GetRootFolderPath(),
|
||||
Path: r.GetRootFolderPath(),
|
||||
Name: "root",
|
||||
Size: 0,
|
||||
Modified: storage.GetStorage().Modified,
|
||||
@ -108,12 +109,13 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
|
||||
return nil, errors.WithMessage(err, "failed get parent list")
|
||||
}
|
||||
for _, f := range files {
|
||||
// TODO maybe copy obj here
|
||||
if f.GetName() == name {
|
||||
// use path as id, why don't set id in List function?
|
||||
// because files maybe cache, set id here can reduce memory usage
|
||||
if f.GetID() == "" {
|
||||
if s, ok := f.(model.SetID); ok {
|
||||
s.SetID(path)
|
||||
if f.GetPath() == "" {
|
||||
if s, ok := f.(model.SetPath); ok {
|
||||
s.SetPath(path)
|
||||
}
|
||||
}
|
||||
return f, nil
|
||||
|
Reference in New Issue
Block a user