@aws-amplify/storage
Version:
Storage category of aws-amplify
1 lines • 4.51 kB
Source Map (JSON)
{"version":3,"file":"getUrl.mjs","sources":["../../../../../../src/providers/s3/apis/internal/getUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { StorageAction } from '@aws-amplify/core/internals/utils';\nimport { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { getPresignedGetObjectUrl } from '../../utils/client';\nimport { resolveS3ConfigAndInput, validateStorageOperationInput, } from '../../utils';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { DEFAULT_PRESIGN_EXPIRATION, MAX_URL_EXPIRATION, STORAGE_INPUT_KEY, } from '../../utils/constants';\nimport { constructContentDisposition } from '../../utils/constructContentDisposition';\nimport { getProperties } from './getProperties';\nexport const getUrl = async (amplify, input) => {\n const { options: getUrlOptions } = input;\n const { s3Config, keyPrefix, bucket, identityId } = await resolveS3ConfigAndInput(amplify, getUrlOptions);\n const { inputType, objectKey } = validateStorageOperationInput(input, identityId);\n const finalKey = inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;\n if (getUrlOptions?.validateObjectExistence) {\n await getProperties(amplify, input, StorageAction.GetUrl);\n }\n let urlExpirationInSec = getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;\n const resolvedCredential = typeof s3Config.credentials === 'function'\n ? await s3Config.credentials()\n : s3Config.credentials;\n const awsCredExpiration = resolvedCredential.expiration;\n if (awsCredExpiration) {\n const awsCredExpirationInSec = Math.floor((awsCredExpiration.getTime() - Date.now()) / 1000);\n urlExpirationInSec = Math.min(awsCredExpirationInSec, urlExpirationInSec);\n }\n const maxUrlExpirationInSec = MAX_URL_EXPIRATION / 1000;\n assertValidationError(urlExpirationInSec <= maxUrlExpirationInSec, StorageValidationErrorCode.UrlExpirationMaxLimitExceed);\n // expiresAt is the minimum of credential expiration and url expiration\n return {\n url: await getPresignedGetObjectUrl({\n ...s3Config,\n credentials: resolvedCredential,\n expiration: urlExpirationInSec,\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(getUrlOptions?.contentDisposition && {\n ResponseContentDisposition: constructContentDisposition(getUrlOptions.contentDisposition),\n }),\n ...(getUrlOptions?.contentType && {\n ResponseContentType: getUrlOptions.contentType,\n }),\n }),\n expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AASY,MAAC,MAAM,GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;AAChD,IAAI,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;AAC7C,IAAI,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAC9G,IAAI,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,6BAA6B,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACtF,IAAI,MAAM,QAAQ,GAAG,SAAS,KAAK,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AACzF,IAAI,IAAI,aAAa,EAAE,uBAAuB,EAAE;AAChD,QAAQ,MAAM,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;AAClE,KAAK;AACL,IAAI,IAAI,kBAAkB,GAAG,aAAa,EAAE,SAAS,IAAI,0BAA0B,CAAC;AACpF,IAAI,MAAM,kBAAkB,GAAG,OAAO,QAAQ,CAAC,WAAW,KAAK,UAAU;AACzE,UAAU,MAAM,QAAQ,CAAC,WAAW,EAAE;AACtC,UAAU,QAAQ,CAAC,WAAW,CAAC;AAC/B,IAAI,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,CAAC;AAC5D,IAAI,IAAI,iBAAiB,EAAE;AAC3B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