Skip to content

Commit

Permalink
chore: use consistent naming when resolving path
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Nelson committed Mar 26, 2024
1 parent b426317 commit 933c2ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ class StorageS3Service {
required StoragePath path,
required StorageGetPropertiesOptions options,
}) async {
final fullPath = await _pathResolver.resolvePath(path: path);
final resolvedPath = await _pathResolver.resolvePath(path: path);

return S3GetPropertiesResult(
storageItem: S3Item.fromHeadObjectOutput(
await headObject(
s3client: _defaultS3Client,
bucket: _s3PluginConfig.bucket,
key: fullPath,
key: resolvedPath,
),
path: fullPath,
path: resolvedPath,
),
);
}
Expand Down Expand Up @@ -255,18 +255,12 @@ class StorageS3Service {
);
}

final fullPath = await _pathResolver.resolvePath(path: path);
var keyToGetUrl = fullPath;
if (!keyToGetUrl.startsWith('/')) {
keyToGetUrl = '/$keyToGetUrl';
}

var resolvedPath = await _pathResolver.resolvePath(path: path);
var host =
'${_s3PluginConfig.bucket}.${_getS3EndpointHost(region: _s3PluginConfig.region)}';

if (_defaultS3ClientConfig.usePathStyle) {
host = host.replaceFirst('${_s3PluginConfig.bucket}.', '');
keyToGetUrl = '/${_s3PluginConfig.bucket}$keyToGetUrl';
resolvedPath = '/${_s3PluginConfig.bucket}/$resolvedPath';
} else if (s3PluginOptions.useAccelerateEndpoint) {
// https: //docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration-getting-started.html
host = host
Expand All @@ -277,7 +271,7 @@ class StorageS3Service {
final urlRequest = AWSHttpRequest.raw(
method: AWSHttpMethod.get,
host: host,
path: keyToGetUrl,
path: resolvedPath,
);

return S3GetUrlResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class S3UploadTask {
bool _isMultipartUpload = false;

late StorageTransferState _state;
late final String _resolvedKey;
late final String _resolvedPath;

// fields used to manage the single upload process
smithy.SmithyOperation<s3.PutObjectOutput>? _putObjectOperation;
Expand Down Expand Up @@ -200,7 +200,7 @@ class S3UploadTask {
}

try {
await _setResolvedKey();
await _setResolvedPath();
} on Exception catch (error, stackTrace) {
_completeUploadWithError(error, stackTrace);
return;
Expand Down Expand Up @@ -307,8 +307,8 @@ class S3UploadTask {
}
}

Future<void> _setResolvedKey() async {
_resolvedKey = await _pathResolver.resolvePath(path: _path);
Future<void> _setResolvedPath() async {
_resolvedPath = await _pathResolver.resolvePath(path: _path);
}

Future<void> _startPutObject(S3DataPayload body) async {
Expand All @@ -320,7 +320,7 @@ class S3UploadTask {
..bucket = _bucket
..body = body
..contentType = body.contentType ?? fallbackContentType
..key = _resolvedKey
..key = _resolvedPath
..metadata.addAll(_metadata);
});

Expand All @@ -345,11 +345,11 @@ class S3UploadTask {
await StorageS3Service.headObject(
s3client: _s3Client,
bucket: _bucket,
key: _resolvedKey,
key: _resolvedPath,
),
path: _resolvedKey,
path: _resolvedPath,
)
: S3Item(path: _resolvedKey),
: S3Item(path: _resolvedPath),
);

_state = StorageTransferState.success;
Expand Down Expand Up @@ -454,11 +454,11 @@ class S3UploadTask {
await StorageS3Service.headObject(
s3client: _s3Client,
bucket: _bucket,
key: _resolvedKey,
key: _resolvedPath,
),
path: _resolvedKey,
path: _resolvedPath,
)
: S3Item(path: _resolvedKey),
: S3Item(path: _resolvedPath),
);
_state = StorageTransferState.success;
_emitTransferProgress();
Expand All @@ -474,7 +474,7 @@ class S3UploadTask {
builder
..bucket = _bucket
..contentType = contentType ?? fallbackContentType
..key = _resolvedKey
..key = _resolvedPath
..metadata.addAll(_metadata);
});

Expand All @@ -491,7 +491,7 @@ class S3UploadTask {
await _transferDatabase.insertTransferRecord(
TransferRecord(
uploadId: uploadId,
objectKey: _resolvedKey,
objectKey: _resolvedPath,
createdAt: DateTime.now(),
),
);
Expand All @@ -518,7 +518,7 @@ class S3UploadTask {
final request = s3.CompleteMultipartUploadRequest.build((builder) {
builder
..bucket = _bucket
..key = _resolvedKey
..key = _resolvedPath
..uploadId = _multipartUploadId
..multipartUpload = s3.CompletedMultipartUpload(
parts: (_completedSubtasks
Expand Down Expand Up @@ -638,7 +638,7 @@ class S3UploadTask {
builder
..bucket = _bucket
..body = partBody
..key = _resolvedKey
..key = _resolvedPath
..partNumber = partNumber
..uploadId = _multipartUploadId;
});
Expand Down Expand Up @@ -729,7 +729,7 @@ class S3UploadTask {
final request = s3.AbortMultipartUploadRequest.build((builder) {
builder
..bucket = _bucket
..key = _resolvedKey
..key = _resolvedPath
..uploadId = _multipartUploadId;
});

Expand Down

0 comments on commit 933c2ad

Please sign in to comment.