Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions drivers/s3/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
"github.com/OpenListTeam/OpenList/v4/pkg/cron"
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
"github.com/OpenListTeam/OpenList/v4/server/common"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -243,4 +246,40 @@ func (d *S3) GetDirectUploadInfo(ctx context.Context, _ string, dstDir model.Obj
}, nil
}

// implements driver.Getter interface
func (d *S3) Get(ctx context.Context, path string) (model.Obj, error) {
if utils.PathEqual(path, "/") {
return &model.Object{
Name: "Root",
IsFolder: true,
Path: "/",
}, nil
}
Comment on lines +251 to +257
Copy link
Member

@j2rong4cn j2rong4cn Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if utils.PathEqual(path, "/") {
return &model.Object{
Name: "Root",
IsFolder: true,
Path: "/",
}, nil
}

已经不用Get获取根目录对象了


// try to get object as a file using HeadObject
key := getKey(path, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
key := getKey(path, false)
key := getKey(stdpath.Join(d.GetRootPath(), path), false)

headInput := &s3.HeadObjectInput{
Bucket: &d.Bucket,
Key: &key,
}
headOutput, err := d.client.HeadObjectWithContext(ctx, headInput)
if err == nil {
// Object exists as a file
fileName := stdpath.Base(path)
return &model.Object{
Name: fileName,
Size: *headOutput.ContentLength,
Modified: *headOutput.LastModified,
Path: path,
}, nil
}
var awsErr awserr.Error
if errors.As(err, &awsErr) && awsErr.Code() != "NotFound" {
return nil, errors.WithMessage(err, "failed to head object")
}

return nil, errs.NotSupport
}

var _ driver.Driver = (*S3)(nil)
var _ driver.Getter = (*S3)(nil)