Skip to content

Commit

Permalink
fix: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sridhar committed Aug 16, 2023
1 parent be25267 commit f51c9b2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/storage/src/providers/s3/apis/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AmplifyV6 } from '@aws-amplify/core';
import {
ListObjectsV2Input,
ListObjectsV2Output,
Expand Down
7 changes: 6 additions & 1 deletion packages/storage/src/providers/s3/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export { S3TransferOptions, S3GetUrlOptions, S3UploadOptions } from './options';
export {
S3TransferOptions,
S3GetUrlOptions,
S3UploadOptions,
GetKeyWithPrefixOptions,
} from './options';
export {
S3DownloadDataResult,
S3DownloadFileResult,
Expand Down
7 changes: 7 additions & 0 deletions packages/storage/src/providers/s3/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { TransferProgressEvent } from '../../../types';
import { StorageOptions } from '../../../types/params';
import { StorageAccessLevel } from '@aws-amplify/core';

type S3Options = StorageOptions & {
/**
Expand Down Expand Up @@ -57,3 +58,9 @@ export type S3UploadOptions = S3TransferOptions & {
*/
metadata?: Record<string, string>;
};

export type GetKeyWithPrefixOptions = {
accessLevel: StorageAccessLevel;
targetIdentityId?: string;
key: string;
};
11 changes: 6 additions & 5 deletions packages/storage/src/providers/s3/utils/getKeyWithPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import { AmplifyV6, StorageAccessLevel } from '@aws-amplify/core';
import { prefixResolver as defaultPrefixResolver } from '../../../utils/prefixResolver';
import { GetKeyWithPrefixOptions } from '../types';

export function getKeyWithPrefix(
accessLevel: StorageAccessLevel,
targetIdentityId: string,
key: string
) {
export function getKeyWithPrefix({
accessLevel,
targetIdentityId,
key,
}: GetKeyWithPrefixOptions) {
const { prefixResolver = defaultPrefixResolver } =
AmplifyV6.libraryOptions?.Storage ?? {};
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { AmplifyV6 } from '@aws-amplify/core';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

const DEFAULT_ACCESS_LEVEL = 'guest';

export function resolveStorageConfig() {
const { bucket, region } = AmplifyV6.getConfig()?.Storage ?? {};
assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);
assertValidationError(!!region, StorageValidationErrorCode.NoRegion);
const { defaultAccessLevel } = AmplifyV6.libraryOptions?.Storage ?? {};
const { defaultAccessLevel = DEFAULT_ACCESS_LEVEL } =
AmplifyV6.libraryOptions?.Storage ?? {};
return {
defaultAccessLevel,
bucket,
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/src/types/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { Credentials } from '@aws-sdk/types';

export type StorageConfig = {
region?: string;
credentials?: Credentials;
region: string;
credentials: Credentials;
};

export type StorageOptions =
Expand Down

0 comments on commit f51c9b2

Please sign in to comment.