Skip to content

Commit

Permalink
feat: set path as ID if it's empty
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 17, 2022
1 parent 56c95ea commit 52ab131
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/model/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ type URL interface {
type Thumbnail interface {
Thumbnail() string
}

type SetID interface {
SetID(id string)
}
4 changes: 4 additions & 0 deletions internal/model/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions internal/operations/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/") {
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 52ab131

Please sign in to comment.