chore: optional get func for driver

This commit is contained in:
Noah Hsu
2022-06-28 22:13:47 +08:00
parent 96380a50da
commit 505b126888
3 changed files with 22 additions and 1 deletions

View File

@ -35,7 +35,10 @@ type Reader interface {
List(ctx context.Context, dir model.Obj) ([]model.Obj, error)
// Link get url/filepath/reader of file
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
//Get(ctx context.Context, path string) (FileInfo, error) // maybe not need
}
type Getter interface {
Get(ctx context.Context, path string) (model.Obj, error)
}
type Writer interface {

View File

@ -71,6 +71,9 @@ func isRoot(path, rootFolderPath string) bool {
func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, error) {
path = utils.StandardizePath(path)
log.Debugf("operations.Get %s", path)
if g, ok := account.(driver.Getter); ok {
return g.Get(ctx, path)
}
// is root folder
if r, ok := account.GetAddition().(driver.IRootFolderId); ok && utils.PathEqual(path, "/") {
return model.Object{