chore: standardize context keys with custom ContextKey type (#697)

* chore: standardize context keys with custom ContextKey type

* fix bug

* 使用Request.Context
This commit is contained in:
j2rong4cn
2025-07-14 23:55:17 +08:00
committed by GitHub
parent 2a4c546a8b
commit 0c461991f9
51 changed files with 253 additions and 219 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/OpenListTeam/OpenList/v4/internal/conf"
"github.com/OpenListTeam/OpenList/v4/internal/errs"
"github.com/OpenListTeam/OpenList/v4/internal/fs"
"github.com/OpenListTeam/OpenList/v4/internal/model"
@ -108,7 +109,7 @@ func (b *s3Backend) HeadObject(ctx context.Context, bucketName, objectName strin
fp := path.Join(bucketPath, objectName)
fmeta, _ := op.GetNearestMeta(fp)
node, err := fs.Get(context.WithValue(ctx, "meta", fmeta), fp, &fs.GetArgs{})
node, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), fp, &fs.GetArgs{})
if err != nil {
return nil, gofakes3.KeyNotFound(objectName)
}
@ -151,7 +152,7 @@ func (b *s3Backend) GetObject(ctx context.Context, bucketName, objectName string
fp := path.Join(bucketPath, objectName)
fmeta, _ := op.GetNearestMeta(fp)
node, err := fs.Get(context.WithValue(ctx, "meta", fmeta), fp, &fs.GetArgs{})
node, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), fp, &fs.GetArgs{})
if err != nil {
return nil, gofakes3.KeyNotFound(objectName)
}
@ -247,7 +248,7 @@ func (b *s3Backend) PutObject(
}
log.Debugf("reqPath: %s", reqPath)
fmeta, _ := op.GetNearestMeta(fp)
ctx = context.WithValue(ctx, "meta", fmeta)
ctx = context.WithValue(ctx, conf.MetaKey, fmeta)
_, err = fs.Get(ctx, reqPath, &fs.GetArgs{})
if err != nil {
@ -341,7 +342,7 @@ func (b *s3Backend) deleteObject(ctx context.Context, bucketName, objectName str
fmeta, _ := op.GetNearestMeta(fp)
// S3 does not report an error when attemping to delete a key that does not exist, so
// we need to skip IsNotExist errors.
if _, err := fs.Get(context.WithValue(ctx, "meta", fmeta), fp, &fs.GetArgs{}); err != nil && !errs.IsObjectNotFound(err) {
if _, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), fp, &fs.GetArgs{}); err != nil && !errs.IsObjectNotFound(err) {
return err
}
@ -388,7 +389,7 @@ func (b *s3Backend) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket
srcFp := path.Join(srcBucketPath, srcKey)
fmeta, _ := op.GetNearestMeta(srcFp)
srcNode, err := fs.Get(context.WithValue(ctx, "meta", fmeta), srcFp, &fs.GetArgs{})
srcNode, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), srcFp, &fs.GetArgs{})
c, err := b.GetObject(ctx, srcBucket, srcKey, nil)
if err != nil {