mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-05-31 10:09:38 +08:00
feat(webdav): implement Getter interface (#2421)
* feat(webdav): implement Getter interface * fix(webdav): update Get method to use correct path handling Co-authored-by: Copilot <copilot@github.com> * fix(s3): correct path handling in Get method for object retrieval --------- Co-authored-by: j2rong4cn <j2rong@qq.com> Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -249,7 +249,8 @@ func (d *S3) GetDirectUploadInfo(ctx context.Context, _ string, dstDir model.Obj
|
||||
// implements driver.Getter interface
|
||||
func (d *S3) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||
// try to get object as a file using HeadObject
|
||||
key := getKey(stdpath.Join(d.GetRootPath(), path), false)
|
||||
path = stdpath.Join(d.GetRootPath(), path)
|
||||
key := getKey(path, false)
|
||||
headInput := &s3.HeadObjectInput{
|
||||
Bucket: &d.Bucket,
|
||||
Key: &key,
|
||||
@@ -303,7 +304,7 @@ func (d *S3) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||
return nil, fmt.Errorf("unsupported ListObjectVersion: %s", d.ListObjectVersion)
|
||||
}
|
||||
if len(contents) > 0 || len(commonPrefixes) > 0 {
|
||||
dirName := stdpath.Base(path + "/")
|
||||
dirName := stdpath.Base(path)
|
||||
return &model.Object{
|
||||
Name: dirName,
|
||||
Modified: d.Modified,
|
||||
|
||||
@@ -125,4 +125,22 @@ func (d *WebDav) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer
|
||||
return err
|
||||
}
|
||||
|
||||
// implements driver.Getter interface
|
||||
func (d *WebDav) Get(ctx context.Context, _path string) (model.Obj, error) {
|
||||
_path = path.Join(d.GetRootPath(), _path)
|
||||
info, err := d.client.Stat(_path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &model.Object{
|
||||
Name: info.Name(),
|
||||
Size: info.Size(),
|
||||
Modified: info.ModTime(),
|
||||
IsFolder: info.IsDir(),
|
||||
Path: _path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ driver.Driver = (*WebDav)(nil)
|
||||
var _ driver.Getter = (*WebDav)(nil)
|
||||
|
||||
Reference in New Issue
Block a user