mirror of https://github.com/Xhofe/alist
feat: set path as ID if it's empty
parent
56c95eadea
commit
52ab1310be
|
@ -26,3 +26,7 @@ type URL interface {
|
|||
type Thumbnail interface {
|
||||
Thumbnail() string
|
||||
}
|
||||
|
||||
type SetID interface {
|
||||
SetID(id string)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue