feat: set path as ID if it's empty

refactor/fs
Noah Hsu 2022-06-16 20:25:33 +08:00
parent 56c95eadea
commit 52ab1310be
3 changed files with 16 additions and 2 deletions

View File

@ -26,3 +26,7 @@ type URL interface {
type Thumbnail interface {
Thumbnail() string
}
type SetID interface {
SetID(id string)
}

View File

@ -29,3 +29,7 @@ func (f Object) IsDir() bool {
func (f Object) GetID() string {
return f.ID
}
func (f *Object) SetID(id string) {
f.ID = id
}

View File

@ -44,8 +44,7 @@ func List(ctx context.Context, account driver.Driver, path string) ([]model.Obj,
return files, err
}
// Get get object from list of files
// TODO: maybe should set object ID with path here
// Get object from list of files
func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, error) {
// is root folder
if r, ok := account.GetAddition().(driver.IRootFolderId); ok && utils.PathEqual(path, "/") {
@ -74,6 +73,13 @@ func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, er
}
for _, f := range files {
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)
}
}
return f, nil
}
}