@webiny/api-file-manager-s3 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.eb81deee7e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FileManagerS3Feature.d.ts +9 -0
- package/FileManagerS3Feature.js +27 -0
- package/FileManagerS3Feature.js.map +1 -0
- package/README.md +11 -1
- package/assetDelivery/abstractions.d.ts +11 -0
- package/assetDelivery/abstractions.js +7 -0
- package/assetDelivery/abstractions.js.map +1 -0
- package/assetDelivery/assetDeliveryConfig.d.ts +2 -2
- package/assetDelivery/assetDeliveryConfig.js +10 -49
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/createAssetDelivery.d.ts +3 -3
- package/assetDelivery/createAssetDelivery.js +7 -28
- package/assetDelivery/createAssetDelivery.js.map +1 -1
- package/assetDelivery/feature.d.ts +5 -0
- package/assetDelivery/feature.js +36 -0
- package/assetDelivery/feature.js.map +1 -0
- package/assetDelivery/index.d.ts +8 -9
- package/assetDelivery/index.js +8 -70
- package/assetDelivery/s3/LazySharpTransform.d.ts +34 -0
- package/assetDelivery/s3/LazySharpTransform.js +34 -0
- package/assetDelivery/s3/LazySharpTransform.js.map +1 -0
- package/assetDelivery/s3/S3AssetResolver.d.ts +9 -4
- package/assetDelivery/s3/S3AssetResolver.js +34 -32
- package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
- package/assetDelivery/s3/S3ContentsReader.d.ts +1 -3
- package/assetDelivery/s3/S3ContentsReader.js +12 -22
- package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
- package/assetDelivery/s3/S3ErrorAssetReply.js +11 -17
- package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3OutputStrategy.d.ts +6 -6
- package/assetDelivery/s3/S3OutputStrategy.js +35 -35
- package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
- package/assetDelivery/s3/S3RedirectAssetReply.js +14 -20
- package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3StreamAssetReply.js +14 -20
- package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
- package/assetDelivery/s3/SharpTransform.d.ts +22 -14
- package/assetDelivery/s3/SharpTransform.js +163 -182
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js +17 -25
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
- package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +0 -2
- package/assetDelivery/s3/transformation/CallableContentsReader.js +7 -13
- package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
- package/assetDelivery/s3/transformation/WidthCollection.js +14 -22
- package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
- package/assetDelivery/s3/transformation/utils.d.ts +1 -3
- package/assetDelivery/s3/transformation/utils.js +26 -28
- package/assetDelivery/s3/transformation/utils.js.map +1 -1
- package/assetDelivery/threatDetection/ObjectKey.d.ts +7 -0
- package/assetDelivery/threatDetection/ObjectKey.js +18 -0
- package/assetDelivery/threatDetection/ObjectKey.js.map +1 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +22 -2
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +49 -58
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +1 -1
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +3 -11
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -1
- package/assetDelivery/threatDetection/index.d.ts +2 -2
- package/assetDelivery/threatDetection/index.js +2 -29
- package/assetDelivery/threatDetection/processThreatScanResult.d.ts +3 -2
- package/assetDelivery/threatDetection/processThreatScanResult.js +56 -61
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
- package/assetDelivery/threatDetection/types.d.ts +0 -4
- package/assetDelivery/threatDetection/types.js +0 -7
- package/assetDelivery/types.d.ts +4 -2
- package/assetDelivery/types.js +0 -7
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +13 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +28 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -0
- package/enterprise/ApplyThreatScanning/feature.d.ts +4 -0
- package/enterprise/ApplyThreatScanning/feature.js +11 -0
- package/enterprise/ApplyThreatScanning/feature.js.map +1 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.d.ts +15 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +35 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +37 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +57 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -0
- package/features/DeleteFileFromBucket/feature.d.ts +4 -0
- package/features/DeleteFileFromBucket/feature.js +13 -0
- package/features/DeleteFileFromBucket/feature.js.map +1 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +11 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.js +25 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -0
- package/features/ExtractMetadata/ExtractMetadataTask.d.ts +29 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js +99 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
- package/features/ExtractMetadata/feature.d.ts +4 -0
- package/features/ExtractMetadata/feature.js +13 -0
- package/features/ExtractMetadata/feature.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +12 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +28 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.d.ts +12 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +31 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -0
- package/features/FlushCache/InvalidateCacheTask.d.ts +31 -0
- package/features/FlushCache/InvalidateCacheTask.js +84 -0
- package/features/FlushCache/InvalidateCacheTask.js.map +1 -0
- package/features/FlushCache/feature.d.ts +4 -0
- package/features/FlushCache/feature.js +15 -0
- package/features/FlushCache/feature.js.map +1 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.d.ts +13 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +40 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.js.map +1 -0
- package/features/GetFileContentsById/feature.d.ts +4 -0
- package/features/GetFileContentsById/feature.js +11 -0
- package/features/GetFileContentsById/feature.js.map +1 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.d.ts +13 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +40 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js.map +1 -0
- package/features/GetFileContentsByKey/feature.d.ts +4 -0
- package/features/GetFileContentsByKey/feature.js +11 -0
- package/features/GetFileContentsByKey/feature.js.map +1 -0
- package/features/WriteFileMetadata/MetadataReader.d.ts +14 -0
- package/features/WriteFileMetadata/MetadataReader.js +13 -0
- package/features/WriteFileMetadata/MetadataReader.js.map +1 -0
- package/features/WriteFileMetadata/MetadataWriter.d.ts +10 -0
- package/features/WriteFileMetadata/MetadataWriter.js +28 -0
- package/features/WriteFileMetadata/MetadataWriter.js.map +1 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +12 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +23 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +12 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +25 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
- package/features/WriteFileMetadata/feature.d.ts +4 -0
- package/features/WriteFileMetadata/feature.js +13 -0
- package/features/WriteFileMetadata/feature.js.map +1 -0
- package/graphql/S3GraphQLSchema.d.ts +10 -0
- package/graphql/S3GraphQLSchema.js +233 -0
- package/graphql/S3GraphQLSchema.js.map +1 -0
- package/graphql/checkPermissions.d.ts +5 -0
- package/graphql/checkPermissions.js +22 -0
- package/graphql/checkPermissions.js.map +1 -0
- package/index.d.ts +4 -5
- package/index.js +3 -36
- package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +1 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js +49 -59
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
- package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +2 -2
- package/multiPartUpload/CreateMultiPartUploadUseCase.js +30 -44
- package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
- package/package.json +36 -34
- package/types.d.ts +2 -1
- package/types.js +1 -7
- package/utils/CdnPathsGenerator.d.ts +3 -0
- package/utils/CdnPathsGenerator.js +11 -0
- package/utils/CdnPathsGenerator.js.map +1 -0
- package/utils/FileExtension.d.ts +1 -1
- package/utils/FileExtension.js +11 -19
- package/utils/FileExtension.js.map +1 -1
- package/utils/FileKey.d.ts +1 -1
- package/utils/FileKey.js +29 -29
- package/utils/FileKey.js.map +1 -1
- package/utils/FileKey.test.js +50 -51
- package/utils/FileKey.test.js.map +1 -1
- package/utils/FileNormalizer.d.ts +2 -2
- package/utils/FileNormalizer.js +35 -43
- package/utils/FileNormalizer.js.map +1 -1
- package/utils/FileUploadModifier.d.ts +9 -3
- package/utils/FileUploadModifier.js +36 -44
- package/utils/FileUploadModifier.js.map +1 -1
- package/utils/createFileNormalizerFromContext.d.ts +2 -2
- package/utils/createFileNormalizerFromContext.js +6 -12
- package/utils/createFileNormalizerFromContext.js.map +1 -1
- package/utils/getPresignedPostPayload.d.ts +4 -3
- package/utils/getPresignedPostPayload.js +38 -40
- package/utils/getPresignedPostPayload.js.map +1 -1
- package/utils/mimeTypes.js +6 -20
- package/utils/mimeTypes.js.map +1 -1
- package/utils/uploadFileToS3.d.ts +2 -5
- package/utils/uploadFileToS3.js +11 -23
- package/utils/uploadFileToS3.js.map +1 -1
- package/assetDelivery/createCustomAssetDelivery.d.ts +0 -12
- package/assetDelivery/createCustomAssetDelivery.js +0 -28
- package/assetDelivery/createCustomAssetDelivery.js.map +0 -1
- package/assetDelivery/customAssets/CustomAsset.d.ts +0 -6
- package/assetDelivery/customAssets/CustomAsset.js +0 -14
- package/assetDelivery/customAssets/CustomAsset.js.map +0 -1
- package/assetDelivery/customAssets/CustomAssetProcessor.d.ts +0 -10
- package/assetDelivery/customAssets/CustomAssetProcessor.js +0 -25
- package/assetDelivery/customAssets/CustomAssetProcessor.js.map +0 -1
- package/assetDelivery/customAssets/S3CustomAssetResolver.d.ts +0 -15
- package/assetDelivery/customAssets/S3CustomAssetResolver.js +0 -90
- package/assetDelivery/customAssets/S3CustomAssetResolver.js.map +0 -1
- package/assetDelivery/customAssets/customAssetDeliveryConfig.d.ts +0 -1
- package/assetDelivery/customAssets/customAssetDeliveryConfig.js +0 -30
- package/assetDelivery/customAssets/customAssetDeliveryConfig.js.map +0 -1
- package/assetDelivery/index.js.map +0 -1
- package/assetDelivery/s3/S3AssetMetadataReader.d.ts +0 -15
- package/assetDelivery/s3/S3AssetMetadataReader.js +0 -36
- package/assetDelivery/s3/S3AssetMetadataReader.js.map +0 -1
- package/assetDelivery/s3/transformation/legacyUtils.d.ts +0 -12
- package/assetDelivery/s3/transformation/legacyUtils.js +0 -34
- package/assetDelivery/s3/transformation/legacyUtils.js.map +0 -1
- package/assetDelivery/threatDetection/index.js.map +0 -1
- package/assetDelivery/threatDetection/types.js.map +0 -1
- package/assetDelivery/types.js.map +0 -1
- package/flushCdnCache/CdnPathsGenerator.d.ts +0 -4
- package/flushCdnCache/CdnPathsGenerator.js +0 -14
- package/flushCdnCache/CdnPathsGenerator.js.map +0 -1
- package/flushCdnCache/InvalidateCacheTask.d.ts +0 -18
- package/flushCdnCache/InvalidateCacheTask.js +0 -78
- package/flushCdnCache/InvalidateCacheTask.js.map +0 -1
- package/flushCdnCache/flushCacheOnFileDelete.d.ts +0 -3
- package/flushCdnCache/flushCacheOnFileDelete.js +0 -34
- package/flushCdnCache/flushCacheOnFileDelete.js.map +0 -1
- package/flushCdnCache/flushCacheOnFileUpdate.d.ts +0 -3
- package/flushCdnCache/flushCacheOnFileUpdate.js +0 -40
- package/flushCdnCache/flushCacheOnFileUpdate.js.map +0 -1
- package/flushCdnCache/index.d.ts +0 -1
- package/flushCdnCache/index.js +0 -15
- package/flushCdnCache/index.js.map +0 -1
- package/flushCdnCache/invalidateCacheTaskDefinition.d.ts +0 -2
- package/flushCdnCache/invalidateCacheTaskDefinition.js +0 -22
- package/flushCdnCache/invalidateCacheTaskDefinition.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/addFileMetadata.d.ts +0 -10
- package/plugins/addFileMetadata.js +0 -67
- package/plugins/addFileMetadata.js.map +0 -1
- package/plugins/checkPermissions.d.ts +0 -4
- package/plugins/checkPermissions.js +0 -44
- package/plugins/checkPermissions.js.map +0 -1
- package/plugins/fileStorageS3.d.ts +0 -3
- package/plugins/fileStorageS3.js +0 -60
- package/plugins/fileStorageS3.js.map +0 -1
- package/plugins/graphqlFileStorageS3.d.ts +0 -4
- package/plugins/graphqlFileStorageS3.js +0 -213
- package/plugins/graphqlFileStorageS3.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.S3ContentsReader = void 0;
|
|
7
1
|
class S3ContentsReader {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!Body) {
|
|
20
|
-
throw Error(`Unable to read ${asset.getKey()}!`);
|
|
2
|
+
constructor(s3, bucket){
|
|
3
|
+
this.s3 = s3;
|
|
4
|
+
this.bucket = bucket;
|
|
5
|
+
}
|
|
6
|
+
async read(asset) {
|
|
7
|
+
const { Body } = await this.s3.getObject({
|
|
8
|
+
Bucket: this.bucket,
|
|
9
|
+
Key: asset.getKey()
|
|
10
|
+
});
|
|
11
|
+
if (!Body) throw Error(`Unable to read ${asset.getKey()}!`);
|
|
12
|
+
return Buffer.from(await Body.transformToByteArray());
|
|
21
13
|
}
|
|
22
|
-
return Buffer.from(await Body.transformToByteArray());
|
|
23
|
-
}
|
|
24
14
|
}
|
|
25
|
-
|
|
15
|
+
export { S3ContentsReader };
|
|
26
16
|
|
|
27
17
|
//# sourceMappingURL=S3ContentsReader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assetDelivery/s3/S3ContentsReader.js","sources":["../../../src/assetDelivery/s3/S3ContentsReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type { Asset, AssetContentsReader } from \"@webiny/api-file-manager\";\n\nexport class S3ContentsReader implements AssetContentsReader {\n private s3: S3;\n private readonly bucket: string;\n\n constructor(s3: S3, bucket: string) {\n this.s3 = s3;\n this.bucket = bucket;\n }\n\n async read(asset: Asset): Promise<Buffer> {\n const { Body } = await this.s3.getObject({\n Bucket: this.bucket,\n Key: asset.getKey()\n });\n\n if (!Body) {\n throw Error(`Unable to read ${asset.getKey()}!`);\n }\n\n return Buffer.from(await Body.transformToByteArray());\n }\n}\n"],"names":["S3ContentsReader","s3","bucket","asset","Body","Error","Buffer"],"mappings":"AAGO,MAAMA;IAIT,YAAYC,EAAM,EAAEC,MAAc,CAAE;QAChC,IAAI,CAAC,EAAE,GAAGD;QACV,IAAI,CAAC,MAAM,GAAGC;IAClB;IAEA,MAAM,KAAKC,KAAY,EAAmB;QACtC,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC;YACrC,QAAQ,IAAI,CAAC,MAAM;YACnB,KAAKD,MAAM,MAAM;QACrB;QAEA,IAAI,CAACC,MACD,MAAMC,MAAM,CAAC,eAAe,EAAEF,MAAM,MAAM,GAAG,CAAC,CAAC;QAGnD,OAAOG,OAAO,IAAI,CAAC,MAAMF,KAAK,oBAAoB;IACtD;AACJ"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
code: 400,
|
|
12
|
-
body: () => ({
|
|
13
|
-
error: message
|
|
14
|
-
})
|
|
15
|
-
});
|
|
16
|
-
}
|
|
1
|
+
import { AssetReply } from "@webiny/api-file-manager";
|
|
2
|
+
class S3ErrorAssetReply extends AssetReply {
|
|
3
|
+
constructor(message){
|
|
4
|
+
super({
|
|
5
|
+
code: 400,
|
|
6
|
+
body: ()=>({
|
|
7
|
+
error: message
|
|
8
|
+
})
|
|
9
|
+
});
|
|
10
|
+
}
|
|
17
11
|
}
|
|
18
|
-
|
|
12
|
+
export { S3ErrorAssetReply };
|
|
19
13
|
|
|
20
14
|
//# sourceMappingURL=S3ErrorAssetReply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assetDelivery/s3/S3ErrorAssetReply.js","sources":["../../../src/assetDelivery/s3/S3ErrorAssetReply.ts"],"sourcesContent":["import { AssetReply } from \"@webiny/api-file-manager\";\n\nexport class S3ErrorAssetReply extends AssetReply {\n constructor(message: string) {\n super({\n code: 400,\n body: () => ({ error: message })\n });\n }\n}\n"],"names":["S3ErrorAssetReply","AssetReply","message"],"mappings":";AAEO,MAAMA,0BAA0BC;IACnC,YAAYC,OAAe,CAAE;QACzB,KAAK,CAAC;YACF,MAAM;YACN,MAAM,IAAO;oBAAE,OAAOA;gBAAQ;QAClC;IACJ;AACJ"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Asset, AssetOutputStrategy, AssetReply } from "@webiny/api-file-manager";
|
|
2
|
-
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
3
|
-
|
|
4
|
-
* This strategy outputs an asset taking into account the size of the asset contents.
|
|
5
|
-
* If the asset is larger than 5MB, a presigned URL will be generated, and a redirect will happen.
|
|
6
|
-
*/
|
|
2
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
3
|
+
import type { IS3AssetDeliveryConfig } from "../../assetDelivery/abstractions.js";
|
|
7
4
|
export declare class S3OutputStrategy implements AssetOutputStrategy {
|
|
8
5
|
private readonly s3;
|
|
9
6
|
private readonly bucket;
|
|
10
7
|
private readonly presignedUrlTtl;
|
|
11
8
|
private readonly assetStreamingMaxSize;
|
|
12
|
-
constructor(s3: S3, bucket: string,
|
|
9
|
+
constructor(s3: S3, bucket: string, config: IS3AssetDeliveryConfig);
|
|
13
10
|
output(asset: Asset): Promise<AssetReply>;
|
|
14
11
|
protected getPresignedUrl(asset: Asset): Promise<string>;
|
|
15
12
|
}
|
|
13
|
+
export declare const S3OutputStrategyImpl: typeof S3OutputStrategy & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<AssetOutputStrategy>;
|
|
15
|
+
};
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
exports.S3OutputStrategy = void 0;
|
|
7
|
-
var _clientS = require("@webiny/aws-sdk/client-s3");
|
|
8
|
-
var _S3RedirectAssetReply = require("./S3RedirectAssetReply");
|
|
9
|
-
var _S3StreamAssetReply = require("./S3StreamAssetReply");
|
|
10
|
-
/**
|
|
11
|
-
* This strategy outputs an asset taking into account the size of the asset contents.
|
|
12
|
-
* If the asset is larger than 5MB, a presigned URL will be generated, and a redirect will happen.
|
|
13
|
-
*/
|
|
1
|
+
import { AssetOutputStrategy } from "@webiny/api-file-manager/features/assetDelivery/abstractions.js";
|
|
2
|
+
import { GetObjectCommand, getSignedUrl } from "@webiny/aws-sdk/client-s3/index.js";
|
|
3
|
+
import { S3RedirectAssetReply } from "./S3RedirectAssetReply.js";
|
|
4
|
+
import { S3StreamAssetReply } from "./S3StreamAssetReply.js";
|
|
5
|
+
import { S3AssetDeliveryConfig, S3Bucket, S3Client } from "../abstractions.js";
|
|
14
6
|
class S3OutputStrategy {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
constructor(s3, bucket, config){
|
|
8
|
+
this.s3 = s3;
|
|
9
|
+
this.bucket = bucket;
|
|
10
|
+
this.presignedUrlTtl = config.presignedUrlTtl;
|
|
11
|
+
this.assetStreamingMaxSize = config.assetStreamingMaxSize;
|
|
12
|
+
}
|
|
13
|
+
async output(asset) {
|
|
14
|
+
if (asset.getSize() > this.assetStreamingMaxSize) {
|
|
15
|
+
console.log(`Asset size is greater than ${this.assetStreamingMaxSize}; redirecting to a presigned S3 URL.`);
|
|
16
|
+
return new S3RedirectAssetReply(await this.getPresignedUrl(asset), this.presignedUrlTtl);
|
|
17
|
+
}
|
|
18
|
+
console.log(`Asset size is smaller than ${this.assetStreamingMaxSize}; streaming directly from Lambda function.`);
|
|
19
|
+
return new S3StreamAssetReply(asset);
|
|
20
|
+
}
|
|
21
|
+
getPresignedUrl(asset) {
|
|
22
|
+
return getSignedUrl(this.s3, new GetObjectCommand({
|
|
23
|
+
Bucket: this.bucket,
|
|
24
|
+
Key: asset.getKey()
|
|
25
|
+
}), {
|
|
26
|
+
expiresIn: this.presignedUrlTtl
|
|
27
|
+
});
|
|
25
28
|
}
|
|
26
|
-
console.log(`Asset size is smaller than ${this.assetStreamingMaxSize}; streaming directly from Lambda function.`);
|
|
27
|
-
return new _S3StreamAssetReply.S3StreamAssetReply(asset);
|
|
28
|
-
}
|
|
29
|
-
getPresignedUrl(asset) {
|
|
30
|
-
return (0, _clientS.getSignedUrl)(this.s3, new _clientS.GetObjectCommand({
|
|
31
|
-
Bucket: this.bucket,
|
|
32
|
-
Key: asset.getKey()
|
|
33
|
-
}), {
|
|
34
|
-
expiresIn: this.presignedUrlTtl
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
29
|
}
|
|
38
|
-
|
|
30
|
+
const S3OutputStrategyImpl = AssetOutputStrategy.createImplementation({
|
|
31
|
+
implementation: S3OutputStrategy,
|
|
32
|
+
dependencies: [
|
|
33
|
+
S3Client,
|
|
34
|
+
S3Bucket,
|
|
35
|
+
S3AssetDeliveryConfig
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { S3OutputStrategy, S3OutputStrategyImpl };
|
|
39
39
|
|
|
40
40
|
//# sourceMappingURL=S3OutputStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assetDelivery/s3/S3OutputStrategy.js","sources":["../../../src/assetDelivery/s3/S3OutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetReply } from \"@webiny/api-file-manager\";\nimport { AssetOutputStrategy as AssetOutputStrategyAbstraction } from \"@webiny/api-file-manager/features/assetDelivery/abstractions.js\";\nimport type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { GetObjectCommand, getSignedUrl } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { S3RedirectAssetReply } from \"~/assetDelivery/s3/S3RedirectAssetReply.js\";\nimport { S3StreamAssetReply } from \"~/assetDelivery/s3/S3StreamAssetReply.js\";\nimport { S3Client, S3Bucket, S3AssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\nimport type { IS3AssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\n\nexport class S3OutputStrategy implements AssetOutputStrategy {\n private readonly s3: S3;\n private readonly bucket: string;\n private readonly presignedUrlTtl: number;\n private readonly assetStreamingMaxSize: number;\n\n constructor(s3: S3, bucket: string, config: IS3AssetDeliveryConfig) {\n this.s3 = s3;\n this.bucket = bucket;\n this.presignedUrlTtl = config.presignedUrlTtl;\n this.assetStreamingMaxSize = config.assetStreamingMaxSize;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n if (asset.getSize() > this.assetStreamingMaxSize) {\n console.log(\n `Asset size is greater than ${this.assetStreamingMaxSize}; redirecting to a presigned S3 URL.`\n );\n\n return new S3RedirectAssetReply(\n await this.getPresignedUrl(asset),\n this.presignedUrlTtl\n );\n }\n\n console.log(\n `Asset size is smaller than ${this.assetStreamingMaxSize}; streaming directly from Lambda function.`\n );\n return new S3StreamAssetReply(asset);\n }\n\n protected getPresignedUrl(asset: Asset) {\n return getSignedUrl(\n this.s3,\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: asset.getKey()\n }),\n { expiresIn: this.presignedUrlTtl }\n );\n }\n}\n\nexport const S3OutputStrategyImpl = AssetOutputStrategyAbstraction.createImplementation({\n implementation: S3OutputStrategy,\n dependencies: [S3Client, S3Bucket, S3AssetDeliveryConfig]\n});\n"],"names":["S3OutputStrategy","s3","bucket","config","asset","console","S3RedirectAssetReply","S3StreamAssetReply","getSignedUrl","GetObjectCommand","S3OutputStrategyImpl","AssetOutputStrategyAbstraction","S3Client","S3Bucket","S3AssetDeliveryConfig"],"mappings":";;;;;AASO,MAAMA;IAMT,YAAYC,EAAM,EAAEC,MAAc,EAAEC,MAA8B,CAAE;QAChE,IAAI,CAAC,EAAE,GAAGF;QACV,IAAI,CAAC,MAAM,GAAGC;QACd,IAAI,CAAC,eAAe,GAAGC,OAAO,eAAe;QAC7C,IAAI,CAAC,qBAAqB,GAAGA,OAAO,qBAAqB;IAC7D;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,IAAIA,MAAM,OAAO,KAAK,IAAI,CAAC,qBAAqB,EAAE;YAC9CC,QAAQ,GAAG,CACP,CAAC,2BAA2B,EAAE,IAAI,CAAC,qBAAqB,CAAC,oCAAoC,CAAC;YAGlG,OAAO,IAAIC,qBACP,MAAM,IAAI,CAAC,eAAe,CAACF,QAC3B,IAAI,CAAC,eAAe;QAE5B;QAEAC,QAAQ,GAAG,CACP,CAAC,2BAA2B,EAAE,IAAI,CAAC,qBAAqB,CAAC,0CAA0C,CAAC;QAExG,OAAO,IAAIE,mBAAmBH;IAClC;IAEU,gBAAgBA,KAAY,EAAE;QACpC,OAAOI,aACH,IAAI,CAAC,EAAE,EACP,IAAIC,iBAAiB;YACjB,QAAQ,IAAI,CAAC,MAAM;YACnB,KAAKL,MAAM,MAAM;QACrB,IACA;YAAE,WAAW,IAAI,CAAC,eAAe;QAAC;IAE1C;AACJ;AAEO,MAAMM,uBAAuBC,oBAAAA,oBAAmD,CAAC;IACpF,gBAAgBX;IAChB,cAAc;QAACY;QAAUC;QAAUC;KAAsB;AAC7D"}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
location: url,
|
|
15
|
-
"cache-control": "public, max-age=" + cacheDuration
|
|
16
|
-
}),
|
|
17
|
-
body: () => ""
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
import { AssetReply } from "@webiny/api-file-manager";
|
|
2
|
+
import { ResponseHeaders } from "@webiny/handler";
|
|
3
|
+
class S3RedirectAssetReply extends AssetReply {
|
|
4
|
+
constructor(url, cacheDuration){
|
|
5
|
+
super({
|
|
6
|
+
code: 301,
|
|
7
|
+
headers: ResponseHeaders.create({
|
|
8
|
+
location: url,
|
|
9
|
+
"cache-control": "public, max-age=" + cacheDuration
|
|
10
|
+
}),
|
|
11
|
+
body: ()=>""
|
|
12
|
+
});
|
|
13
|
+
}
|
|
20
14
|
}
|
|
21
|
-
|
|
15
|
+
export { S3RedirectAssetReply };
|
|
22
16
|
|
|
23
17
|
//# sourceMappingURL=S3RedirectAssetReply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assetDelivery/s3/S3RedirectAssetReply.js","sources":["../../../src/assetDelivery/s3/S3RedirectAssetReply.ts"],"sourcesContent":["import { AssetReply } from \"@webiny/api-file-manager\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class S3RedirectAssetReply extends AssetReply {\n constructor(url: string, cacheDuration: number) {\n super({\n code: 301,\n headers: ResponseHeaders.create({\n location: url,\n \"cache-control\": \"public, max-age=\" + cacheDuration\n }),\n body: () => \"\"\n });\n }\n}\n"],"names":["S3RedirectAssetReply","AssetReply","url","cacheDuration","ResponseHeaders"],"mappings":";;AAGO,MAAMA,6BAA6BC;IACtC,YAAYC,GAAW,EAAEC,aAAqB,CAAE;QAC5C,KAAK,CAAC;YACF,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,UAAUF;gBACV,iBAAiB,qBAAqBC;YAC1C;YACA,MAAM,IAAM;QAChB;IACJ;AACJ"}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"cache-control": `public, max-age=${86400 * 365}`,
|
|
15
|
-
"content-type": asset.getContentType()
|
|
16
|
-
}),
|
|
17
|
-
body: () => asset.getContents()
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
import { AssetReply } from "@webiny/api-file-manager";
|
|
2
|
+
import { ResponseHeaders } from "@webiny/handler";
|
|
3
|
+
class S3StreamAssetReply extends AssetReply {
|
|
4
|
+
constructor(asset){
|
|
5
|
+
super({
|
|
6
|
+
code: 200,
|
|
7
|
+
headers: ResponseHeaders.create({
|
|
8
|
+
"cache-control": "public, max-age=31536000",
|
|
9
|
+
"content-type": asset.getContentType()
|
|
10
|
+
}),
|
|
11
|
+
body: ()=>asset.getContents()
|
|
12
|
+
});
|
|
13
|
+
}
|
|
20
14
|
}
|
|
21
|
-
|
|
15
|
+
export { S3StreamAssetReply };
|
|
22
16
|
|
|
23
17
|
//# sourceMappingURL=S3StreamAssetReply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assetDelivery/s3/S3StreamAssetReply.js","sources":["../../../src/assetDelivery/s3/S3StreamAssetReply.ts"],"sourcesContent":["import type { Asset } from \"@webiny/api-file-manager\";\nimport { AssetReply } from \"@webiny/api-file-manager\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class S3StreamAssetReply extends AssetReply {\n constructor(asset: Asset) {\n super({\n code: 200,\n headers: ResponseHeaders.create({\n \"cache-control\": `public, max-age=${86400 * 365}`,\n \"content-type\": asset.getContentType()\n }),\n body: () => asset.getContents()\n });\n }\n}\n"],"names":["S3StreamAssetReply","AssetReply","asset","ResponseHeaders"],"mappings":";;AAIO,MAAMA,2BAA2BC;IACpC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,iBAAiB;gBACjB,gBAAgBD,MAAM,cAAc;YACxC;YACA,MAAM,IAAMA,MAAM,WAAW;QACjC;IACJ;AACJ"}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export declare class SharpTransform implements
|
|
9
|
-
private readonly
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
|
|
4
|
+
import { ImageAssetTypeHandler } from "@webiny/api-file-manager/features/assetDelivery/assetTypes/image/index.js";
|
|
5
|
+
import type { Asset } from "@webiny/api-file-manager/delivery/AssetDelivery/Asset.js";
|
|
6
|
+
import type { AssetRequest } from "@webiny/api-file-manager/delivery/AssetDelivery/AssetRequest.js";
|
|
7
|
+
import type { IS3AssetDeliveryConfig } from "../../assetDelivery/abstractions.js";
|
|
8
|
+
export declare class SharpTransform implements ImageAssetTypeHandler.Interface {
|
|
9
|
+
private readonly s3;
|
|
10
|
+
private readonly bucket;
|
|
11
|
+
private readonly imageResizeWidths;
|
|
12
|
+
private readonly imageQuality;
|
|
13
|
+
private readonly identityContext;
|
|
14
|
+
private readonly getFile;
|
|
15
|
+
private transformer?;
|
|
16
|
+
constructor(s3: S3, bucket: string, config: IS3AssetDeliveryConfig, identityContext: IdentityContext.Interface, getFile: GetFileUseCase.Interface);
|
|
17
|
+
private getTransformer;
|
|
18
|
+
handle(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
19
|
+
private loadAssetCrop;
|
|
12
20
|
private transformAsset;
|
|
13
21
|
private optimizeAsset;
|
|
14
22
|
private isAssetAnimated;
|
|
15
|
-
private optimizePng;
|
|
16
|
-
private optimizeJpeg;
|
|
17
23
|
}
|
|
18
|
-
export {
|
|
24
|
+
export declare const SharpTransformImpl: typeof SharpTransform & {
|
|
25
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/assetDelivery/abstractions/AssetType").IAssetTypeHandler>;
|
|
26
|
+
};
|