mirror of https://github.com/Xhofe/alist
chore: optional get func for driver
parent
96380a50da
commit
505b126888
|
@ -76,6 +76,21 @@ func (d *Driver) List(ctx context.Context, dir model.Obj) ([]model.Obj, error) {
|
|||
return files, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||
f, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error while stat %s", path)
|
||||
}
|
||||
file := model.Object{
|
||||
ID: path,
|
||||
Name: f.Name(),
|
||||
Modified: f.ModTime(),
|
||||
Size: f.Size(),
|
||||
IsFolder: f.IsDir(),
|
||||
}
|
||||
return &file, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||
fullPath := file.GetID()
|
||||
link := model.Link{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue