@webiny/api-file-manager-s3 0.0.0-unstable.de38392959 → 0.0.0-unstable.e0bfc55d5a
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/assetDelivery/assetDeliveryConfig.d.ts +1 -5
- package/assetDelivery/assetDeliveryConfig.js +8 -2
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/createAssetDelivery.d.ts +3 -3
- package/assetDelivery/createAssetDelivery.js +13 -3
- package/assetDelivery/createAssetDelivery.js.map +1 -1
- package/assetDelivery/createCustomAssetDelivery.js +1 -1
- package/assetDelivery/createCustomAssetDelivery.js.map +1 -1
- package/assetDelivery/customAssets/CustomAsset.js.map +1 -1
- package/assetDelivery/customAssets/CustomAssetProcessor.d.ts +1 -1
- package/assetDelivery/customAssets/CustomAssetProcessor.js.map +1 -1
- package/assetDelivery/customAssets/S3CustomAssetResolver.d.ts +2 -2
- package/assetDelivery/customAssets/S3CustomAssetResolver.js.map +1 -1
- package/assetDelivery/customAssets/customAssetDeliveryConfig.js.map +1 -1
- package/assetDelivery/index.js.map +1 -1
- package/assetDelivery/s3/S3AssetMetadataReader.js.map +1 -1
- package/assetDelivery/s3/S3AssetResolver.d.ts +3 -2
- package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
- package/assetDelivery/s3/S3ContentsReader.d.ts +3 -2
- package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
- package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3OutputStrategy.d.ts +4 -3
- package/assetDelivery/s3/S3OutputStrategy.js +5 -4
- package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
- package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3StreamAssetReply.d.ts +2 -1
- package/assetDelivery/s3/S3StreamAssetReply.js +1 -0
- package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
- package/assetDelivery/s3/SharpTransform.d.ts +2 -2
- package/assetDelivery/s3/SharpTransform.js +51 -15
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.d.ts +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
- package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +2 -1
- package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
- package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
- package/assetDelivery/s3/transformation/legacyUtils.js +4 -8
- package/assetDelivery/s3/transformation/legacyUtils.js.map +1 -1
- package/assetDelivery/s3/transformation/utils.js +3 -6
- package/assetDelivery/s3/transformation/utils.js.map +1 -1
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +2 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +62 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +2 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +13 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -0
- package/assetDelivery/threatDetection/index.d.ts +2 -0
- package/assetDelivery/threatDetection/index.js +29 -0
- package/assetDelivery/threatDetection/index.js.map +1 -0
- package/assetDelivery/threatDetection/processThreatScanResult.d.ts +2 -0
- package/assetDelivery/threatDetection/processThreatScanResult.js +66 -0
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -0
- package/assetDelivery/threatDetection/types.d.ts +13 -0
- package/assetDelivery/threatDetection/types.js +7 -0
- package/assetDelivery/threatDetection/types.js.map +1 -0
- package/assetDelivery/types.d.ts +11 -0
- package/assetDelivery/types.js +7 -0
- package/assetDelivery/types.js.map +1 -0
- package/flushCdnCache/CdnPathsGenerator.d.ts +1 -1
- package/flushCdnCache/CdnPathsGenerator.js.map +1 -1
- package/flushCdnCache/InvalidateCacheTask.d.ts +3 -3
- package/flushCdnCache/InvalidateCacheTask.js.map +1 -1
- package/flushCdnCache/flushCacheOnFileDelete.d.ts +1 -1
- package/flushCdnCache/flushCacheOnFileDelete.js.map +1 -1
- package/flushCdnCache/flushCacheOnFileUpdate.d.ts +1 -1
- package/flushCdnCache/flushCacheOnFileUpdate.js.map +1 -1
- package/flushCdnCache/index.js.map +1 -1
- package/flushCdnCache/invalidateCacheTaskDefinition.d.ts +1 -1
- package/flushCdnCache/invalidateCacheTaskDefinition.js.map +1 -1
- package/index.js.map +1 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +3 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js +12 -12
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
- package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +2 -2
- package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
- package/package.json +22 -22
- package/plugins/addFileMetadata.d.ts +1 -1
- package/plugins/addFileMetadata.js.map +1 -1
- package/plugins/checkPermissions.d.ts +1 -1
- package/plugins/checkPermissions.js.map +1 -1
- package/plugins/fileStorageS3.js.map +1 -1
- package/plugins/graphqlFileStorageS3.d.ts +2 -2
- package/plugins/graphqlFileStorageS3.js +2 -2
- package/plugins/graphqlFileStorageS3.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
- package/utils/FileExtension.d.ts +1 -1
- package/utils/FileExtension.js.map +1 -1
- package/utils/FileKey.d.ts +1 -1
- package/utils/FileKey.js.map +1 -1
- package/utils/FileKey.test.js.map +1 -1
- package/utils/FileNormalizer.d.ts +2 -2
- package/utils/FileNormalizer.js.map +1 -1
- package/utils/FileUploadModifier.d.ts +1 -1
- package/utils/FileUploadModifier.js.map +1 -1
- package/utils/createFileNormalizerFromContext.d.ts +1 -1
- package/utils/createFileNormalizerFromContext.js.map +1 -1
- package/utils/getPresignedPostPayload.d.ts +2 -2
- package/utils/getPresignedPostPayload.js.map +1 -1
- package/utils/mimeTypes.js +1 -2
- package/utils/mimeTypes.js.map +1 -1
- package/utils/uploadFileToS3.d.ts +3 -2
- package/utils/uploadFileToS3.js.map +1 -1
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type AssetDeliveryParams = Parameters<typeof createBaseAssetDelivery>[0] & {
|
|
3
|
-
imageResizeWidths?: number[];
|
|
4
|
-
presignedUrlTtl?: number;
|
|
5
|
-
};
|
|
1
|
+
import type { AssetDeliveryParams } from "./types";
|
|
6
2
|
export declare const assetDeliveryConfig: (params: AssetDeliveryParams) => (import("@webiny/api-file-manager").AssetDeliveryConfigModifierPlugin | (import("@webiny/api-file-manager").AssetDeliveryConfigModifierPlugin | import("@webiny/handler").ModifyFastifyPlugin)[])[];
|
|
@@ -13,8 +13,14 @@ const assetDeliveryConfig = params => {
|
|
|
13
13
|
const bucket = process.env.S3_BUCKET;
|
|
14
14
|
const region = process.env.AWS_REGION;
|
|
15
15
|
const {
|
|
16
|
-
|
|
16
|
+
// Presigned URLs last 1 hour
|
|
17
|
+
presignedUrlTtl = 3600,
|
|
17
18
|
imageResizeWidths = [100, 300, 500, 750, 1000, 1500, 2500],
|
|
19
|
+
/**
|
|
20
|
+
* Even though Lambda's response payload limit is 6,291,556 bytes, we leave some room for the response envelope.
|
|
21
|
+
* We had situations where a 4.7MB file would cause the payload to go over the limit, so let's be on the safe side.
|
|
22
|
+
*/
|
|
23
|
+
assetStreamingMaxSize = 4718592,
|
|
18
24
|
...baseParams
|
|
19
25
|
} = params;
|
|
20
26
|
return [
|
|
@@ -30,7 +36,7 @@ const assetDeliveryConfig = params => {
|
|
|
30
36
|
return new _S3AssetResolver.S3AssetResolver(s3, bucket);
|
|
31
37
|
});
|
|
32
38
|
config.decorateAssetOutputStrategy(() => {
|
|
33
|
-
return new _S3OutputStrategy.S3OutputStrategy(s3, bucket, presignedUrlTtl);
|
|
39
|
+
return new _S3OutputStrategy.S3OutputStrategy(s3, bucket, presignedUrlTtl, assetStreamingMaxSize);
|
|
34
40
|
});
|
|
35
41
|
config.decorateAssetTransformationStrategy(() => {
|
|
36
42
|
return new _SharpTransform.SharpTransform({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","_clientS","_S3AssetResolver","_S3OutputStrategy","_SharpTransform","assetDeliveryConfig","params","bucket","process","env","S3_BUCKET","region","AWS_REGION","presignedUrlTtl","imageResizeWidths","baseParams","createBaseAssetDelivery","createAssetDeliveryConfig","config","s3","S3","decorateAssetResolver","S3AssetResolver","decorateAssetOutputStrategy","S3OutputStrategy","decorateAssetTransformationStrategy","SharpTransform","exports"],"sources":["assetDeliveryConfig.ts"],"sourcesContent":["import {\n createAssetDelivery as createBaseAssetDelivery,\n createAssetDeliveryConfig\n} from \"@webiny/api-file-manager\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { S3AssetResolver } from \"~/assetDelivery/s3/S3AssetResolver\";\nimport { S3OutputStrategy } from \"~/assetDelivery/s3/S3OutputStrategy\";\nimport { SharpTransform } from \"~/assetDelivery/s3/SharpTransform\";\
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_clientS","_S3AssetResolver","_S3OutputStrategy","_SharpTransform","assetDeliveryConfig","params","bucket","process","env","S3_BUCKET","region","AWS_REGION","presignedUrlTtl","imageResizeWidths","assetStreamingMaxSize","baseParams","createBaseAssetDelivery","createAssetDeliveryConfig","config","s3","S3","decorateAssetResolver","S3AssetResolver","decorateAssetOutputStrategy","S3OutputStrategy","decorateAssetTransformationStrategy","SharpTransform","exports"],"sources":["assetDeliveryConfig.ts"],"sourcesContent":["import {\n createAssetDelivery as createBaseAssetDelivery,\n createAssetDeliveryConfig\n} from \"@webiny/api-file-manager\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { S3AssetResolver } from \"~/assetDelivery/s3/S3AssetResolver\";\nimport { S3OutputStrategy } from \"~/assetDelivery/s3/S3OutputStrategy\";\nimport { SharpTransform } from \"~/assetDelivery/s3/SharpTransform\";\nimport type { AssetDeliveryParams } from \"~/assetDelivery/types\";\n\nexport const assetDeliveryConfig = (params: AssetDeliveryParams) => {\n const bucket = process.env.S3_BUCKET as string;\n const region = process.env.AWS_REGION as string;\n\n const {\n // Presigned URLs last 1 hour\n presignedUrlTtl = 3600,\n imageResizeWidths = [100, 300, 500, 750, 1000, 1500, 2500],\n /**\n * Even though Lambda's response payload limit is 6,291,556 bytes, we leave some room for the response envelope.\n * We had situations where a 4.7MB file would cause the payload to go over the limit, so let's be on the safe side.\n */\n assetStreamingMaxSize = 4718592,\n ...baseParams\n } = params;\n\n return [\n // Base asset delivery\n createBaseAssetDelivery(baseParams),\n // S3 plugins\n createAssetDeliveryConfig(config => {\n const s3 = new S3({ region });\n\n config.decorateAssetResolver(() => {\n // This resolver loads file information from the `.metadata` file.\n return new S3AssetResolver(s3, bucket);\n });\n\n config.decorateAssetOutputStrategy(() => {\n return new S3OutputStrategy(s3, bucket, presignedUrlTtl, assetStreamingMaxSize);\n });\n\n config.decorateAssetTransformationStrategy(() => {\n return new SharpTransform({ s3, bucket, imageResizeWidths });\n });\n })\n ];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAGO,MAAMK,mBAAmB,GAAIC,MAA2B,IAAK;EAChE,MAAMC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAACC,SAAmB;EAC9C,MAAMC,MAAM,GAAGH,OAAO,CAACC,GAAG,CAACG,UAAoB;EAE/C,MAAM;IACF;IACAC,eAAe,GAAG,IAAI;IACtBC,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC1D;AACR;AACA;AACA;IACQC,qBAAqB,GAAG,OAAO;IAC/B,GAAGC;EACP,CAAC,GAAGV,MAAM;EAEV,OAAO;EACH;EACA,IAAAW,mCAAuB,EAACD,UAAU,CAAC;EACnC;EACA,IAAAE,yCAAyB,EAACC,MAAM,IAAI;IAChC,MAAMC,EAAE,GAAG,IAAIC,WAAE,CAAC;MAAEV;IAAO,CAAC,CAAC;IAE7BQ,MAAM,CAACG,qBAAqB,CAAC,MAAM;MAC/B;MACA,OAAO,IAAIC,gCAAe,CAACH,EAAE,EAAEb,MAAM,CAAC;IAC1C,CAAC,CAAC;IAEFY,MAAM,CAACK,2BAA2B,CAAC,MAAM;MACrC,OAAO,IAAIC,kCAAgB,CAACL,EAAE,EAAEb,MAAM,EAAEM,eAAe,EAAEE,qBAAqB,CAAC;IACnF,CAAC,CAAC;IAEFI,MAAM,CAACO,mCAAmC,CAAC,MAAM;MAC7C,OAAO,IAAIC,8BAAc,CAAC;QAAEP,EAAE;QAAEb,MAAM;QAAEO;MAAkB,CAAC,CAAC;IAChE,CAAC,CAAC;EACN,CAAC,CAAC,CACL;AACL,CAAC;AAACc,OAAA,CAAAvB,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { PluginFactory } from "@webiny/plugins/types";
|
|
2
|
-
import type { AssetDeliveryParams } from "./
|
|
3
|
-
export declare const createAssetDelivery: (params: AssetDeliveryParams) => PluginFactory;
|
|
1
|
+
import type { PluginFactory } from "@webiny/plugins/types";
|
|
2
|
+
import type { AssetDeliveryParams } from "./types";
|
|
3
|
+
export declare const createAssetDelivery: (params: AssetDeliveryParams) => PluginFactory[];
|
|
@@ -5,15 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createAssetDelivery = void 0;
|
|
7
7
|
var _apiFileManager = require("@webiny/api-file-manager");
|
|
8
|
+
var _threatDetection = require("./threatDetection");
|
|
8
9
|
const createAssetDelivery = params => {
|
|
10
|
+
return [
|
|
9
11
|
/**
|
|
10
12
|
* We only want to load this plugin in the context of the Asset Delivery Lambda function.
|
|
11
13
|
*/
|
|
12
|
-
|
|
13
|
-
return import(
|
|
14
|
+
(0, _apiFileManager.createAssetDeliveryPluginLoader)(() => {
|
|
15
|
+
return import(/* webpackChunkName: "s3AssetDelivery" */"./assetDeliveryConfig").then(({
|
|
14
16
|
assetDeliveryConfig
|
|
15
17
|
}) => assetDeliveryConfig(params));
|
|
16
|
-
})
|
|
18
|
+
}),
|
|
19
|
+
/**
|
|
20
|
+
* We only want to load this plugin in the context of the Threat Detection Lambda function.
|
|
21
|
+
*/
|
|
22
|
+
(0, _threatDetection.createThreatDetectionPluginLoader)(() => {
|
|
23
|
+
return import(/* webpackChunkName: "threatDetectionEventHandler" */"./threatDetection/createThreatDetectionEventHandler").then(({
|
|
24
|
+
createThreatDetectionEventHandler
|
|
25
|
+
}) => createThreatDetectionEventHandler());
|
|
26
|
+
})];
|
|
17
27
|
};
|
|
18
28
|
exports.createAssetDelivery = createAssetDelivery;
|
|
19
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","createAssetDelivery","params","createAssetDeliveryPluginLoader","then","assetDeliveryConfig","exports"],"sources":["createAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager\";\nimport { PluginFactory } from \"@webiny/plugins/types\";\nimport type { AssetDeliveryParams } from \"
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_threatDetection","createAssetDelivery","params","createAssetDeliveryPluginLoader","then","assetDeliveryConfig","createThreatDetectionPluginLoader","createThreatDetectionEventHandler","exports"],"sources":["createAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager\";\nimport type { PluginFactory } from \"@webiny/plugins/types\";\nimport { createThreatDetectionPluginLoader } from \"~/assetDelivery/threatDetection\";\nimport type { AssetDeliveryParams } from \"~/assetDelivery/types\";\n\nexport const createAssetDelivery = (params: AssetDeliveryParams): PluginFactory[] => {\n return [\n /**\n * We only want to load this plugin in the context of the Asset Delivery Lambda function.\n */\n createAssetDeliveryPluginLoader(() => {\n return import(/* webpackChunkName: \"s3AssetDelivery\" */ \"./assetDeliveryConfig\").then(\n ({ assetDeliveryConfig }) => assetDeliveryConfig(params)\n );\n }),\n /**\n * We only want to load this plugin in the context of the Threat Detection Lambda function.\n */\n createThreatDetectionPluginLoader(() => {\n return import(\n /* webpackChunkName: \"threatDetectionEventHandler\" */ \"./threatDetection/createThreatDetectionEventHandler\"\n ).then(({ createThreatDetectionEventHandler }) => createThreatDetectionEventHandler());\n })\n ];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAGO,MAAME,mBAAmB,GAAIC,MAA2B,IAAsB;EACjF,OAAO;EACH;AACR;AACA;EACQ,IAAAC,+CAA+B,EAAC,MAAM;IAClC,OAAO,MAAM,CAAC,gEAAiE,CAAC,CAACC,IAAI,CACjF,CAAC;MAAEC;IAAoB,CAAC,KAAKA,mBAAmB,CAACH,MAAM,CAC3D,CAAC;EACL,CAAC,CAAC;EACF;AACR;AACA;EACQ,IAAAI,kDAAiC,EAAC,MAAM;IACpC,OAAO,MAAM,CACT,0GACJ,CAAC,CAACF,IAAI,CAAC,CAAC;MAAEG;IAAkC,CAAC,KAAKA,iCAAiC,CAAC,CAAC,CAAC;EAC1F,CAAC,CAAC,CACL;AACL,CAAC;AAACC,OAAA,CAAAP,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -18,7 +18,7 @@ var _apiFileManager = require("@webiny/api-file-manager");
|
|
|
18
18
|
*/
|
|
19
19
|
const createCustomAssetDelivery = () => {
|
|
20
20
|
return (0, _apiFileManager.createAssetDeliveryPluginLoader)(async () => {
|
|
21
|
-
return import(
|
|
21
|
+
return import(/* webpackChunkName: "customAssetDelivery" */"./customAssets/customAssetDeliveryConfig").then(({
|
|
22
22
|
customAssetDeliveryConfig
|
|
23
23
|
}) => customAssetDeliveryConfig());
|
|
24
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","createCustomAssetDelivery","createAssetDeliveryPluginLoader","then","customAssetDeliveryConfig","exports"],"sources":["createCustomAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager\";\n\n/**\n * !! EXPERIMENTAL !!\n *\n * This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.\n * These are usually files that go through background processing, video transcoding, image optimization, etc.\n * Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able\n * to resolve them.\n *\n * With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder\n * it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.\n */\nexport const createCustomAssetDelivery = () => {\n return createAssetDeliveryPluginLoader(async () => {\n return import(\n /* webpackChunkName: \"customAssetDelivery\" */ \"./customAssets/customAssetDeliveryConfig\"\n ).then(({ customAssetDeliveryConfig }) => customAssetDeliveryConfig());\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAAC,+CAA+B,EAAC,YAAY;IAC/C,OAAO,MAAM,
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","createCustomAssetDelivery","createAssetDeliveryPluginLoader","then","customAssetDeliveryConfig","exports"],"sources":["createCustomAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager\";\n\n/**\n * !! EXPERIMENTAL !!\n *\n * This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.\n * These are usually files that go through background processing, video transcoding, image optimization, etc.\n * Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able\n * to resolve them.\n *\n * With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder\n * it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.\n */\nexport const createCustomAssetDelivery = () => {\n return createAssetDeliveryPluginLoader(async () => {\n return import(\n /* webpackChunkName: \"customAssetDelivery\" */ \"./customAssets/customAssetDeliveryConfig\"\n ).then(({ customAssetDeliveryConfig }) => customAssetDeliveryConfig());\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAAC,+CAA+B,EAAC,YAAY;IAC/C,OAAO,MAAM,CACT,uFACJ,CAAC,CAACC,IAAI,CAAC,CAAC;MAAEC;IAA0B,CAAC,KAAKA,yBAAyB,CAAC,CAAC,CAAC;EAC1E,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAJ,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","CustomAsset","Asset","exports"],"sources":["CustomAsset.ts"],"sourcesContent":["import { Asset } from \"@webiny/api-file-manager\";\n\n/**\n * This class is used to differentiate between regular and custom assets.\n */\nexport class CustomAsset extends Asset {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,MAAMC,WAAW,SAASC,qBAAK,CAAC;AAAEC,OAAA,CAAAF,WAAA,GAAAA,WAAA"}
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","CustomAsset","Asset","exports"],"sources":["CustomAsset.ts"],"sourcesContent":["import { Asset } from \"@webiny/api-file-manager\";\n\n/**\n * This class is used to differentiate between regular and custom assets.\n */\nexport class CustomAsset extends Asset {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,MAAMC,WAAW,SAASC,qBAAK,CAAC;AAAEC,OAAA,CAAAF,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, AssetProcessor, AssetRequest } from "@webiny/api-file-manager";
|
|
1
|
+
import type { Asset, AssetProcessor, AssetRequest } from "@webiny/api-file-manager";
|
|
2
2
|
/**
|
|
3
3
|
* We don't want to run any kind of transformations on custom assets.
|
|
4
4
|
* Custom assets are usually pre-processed and ready to be delivered to the client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_CustomAsset","require","CustomAssetProcessor","constructor","assetProcessor","process","assetRequest","asset","CustomAsset","exports"],"sources":["CustomAssetProcessor.ts"],"sourcesContent":["import { Asset, AssetProcessor, AssetRequest } from \"@webiny/api-file-manager\";\nimport { CustomAsset } from \"./CustomAsset\";\n\n/**\n * We don't want to run any kind of transformations on custom assets.\n * Custom assets are usually pre-processed and ready to be delivered to the client.\n */\nexport class CustomAssetProcessor implements AssetProcessor {\n private assetProcessor: AssetProcessor;\n\n constructor(assetProcessor: AssetProcessor) {\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n if (asset instanceof CustomAsset) {\n return asset;\n }\n\n return this.assetProcessor.process(assetRequest, asset);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,CAA2B;EAGxDC,WAAWA,CAACC,cAA8B,EAAE;IACxC,IAAI,CAACA,cAAc,GAAGA,cAAc;EACxC;EAEA,MAAMC,OAAOA,CAACC,YAA0B,EAAEC,KAAY,EAAkB;IACpE,IAAIA,KAAK,YAAYC,wBAAW,EAAE;MAC9B,OAAOD,KAAK;IAChB;IAEA,OAAO,IAAI,CAACH,cAAc,CAACC,OAAO,CAACC,YAAY,EAAEC,KAAK,CAAC;EAC3D;AACJ;AAACE,OAAA,CAAAP,oBAAA,GAAAA,oBAAA"}
|
|
1
|
+
{"version":3,"names":["_CustomAsset","require","CustomAssetProcessor","constructor","assetProcessor","process","assetRequest","asset","CustomAsset","exports"],"sources":["CustomAssetProcessor.ts"],"sourcesContent":["import type { Asset, AssetProcessor, AssetRequest } from \"@webiny/api-file-manager\";\nimport { CustomAsset } from \"./CustomAsset\";\n\n/**\n * We don't want to run any kind of transformations on custom assets.\n * Custom assets are usually pre-processed and ready to be delivered to the client.\n */\nexport class CustomAssetProcessor implements AssetProcessor {\n private assetProcessor: AssetProcessor;\n\n constructor(assetProcessor: AssetProcessor) {\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n if (asset instanceof CustomAsset) {\n return asset;\n }\n\n return this.assetProcessor.process(assetRequest, asset);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,CAA2B;EAGxDC,WAAWA,CAACC,cAA8B,EAAE;IACxC,IAAI,CAACA,cAAc,GAAGA,cAAc;EACxC;EAEA,MAAMC,OAAOA,CAACC,YAA0B,EAAEC,KAAY,EAAkB;IACpE,IAAIA,KAAK,YAAYC,wBAAW,EAAE;MAC9B,OAAOD,KAAK;IAChB;IAEA,OAAO,IAAI,CAACH,cAAc,CAACC,OAAO,CAACC,YAAY,EAAEC,KAAK,CAAC;EAC3D;AACJ;AAACE,OAAA,CAAAP,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
-
import { Asset, AssetRequest, AssetResolver } from "@webiny/api-file-manager";
|
|
1
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
+
import type { Asset, AssetRequest, AssetResolver } from "@webiny/api-file-manager";
|
|
3
3
|
/**
|
|
4
4
|
* This asset resolver kicks in only if the default resolution fails to resolve an asset.
|
|
5
5
|
* The goal of this resolver is to fetch .metadata from the original file that was uploaded via th File Manager.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","_interopRequireDefault","require","_S3AssetMetadataReader","_S3ContentsReader","_CustomAsset","S3CustomAssetResolver","constructor","s3","bucket","assetResolver","resolve","request","resolvedAsset","originalFileMetadataKey","findMetadata","undefined","attrs","getFileAttributes","getKey","metadataReader","S3AssetMetadataReader","metadata","getMetadata","replace","asset","CustomAsset","id","tenant","locale","size","contentType","key","setContentsReader","S3ContentsReader","error","console","requestFolder","path","dirname","assetList","listObjects","Bucket","Prefix","Contents","find","file","Key","endsWith","head","headObject","ContentLength","ContentType","exports"],"sources":["S3CustomAssetResolver.ts"],"sourcesContent":["import path from \"path\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { Asset, AssetRequest, AssetResolver } from \"@webiny/api-file-manager\";\nimport { S3AssetMetadataReader } from \"~/assetDelivery/s3/S3AssetMetadataReader\";\nimport { S3ContentsReader } from \"~/assetDelivery/s3/S3ContentsReader\";\nimport { CustomAsset } from \"./CustomAsset\";\n\n/**\n * This asset resolver kicks in only if the default resolution fails to resolve an asset.\n * The goal of this resolver is to fetch .metadata from the original file that was uploaded via th File Manager.\n */\nexport class S3CustomAssetResolver implements AssetResolver {\n private readonly s3: S3;\n private readonly bucket: string;\n private assetResolver: AssetResolver;\n\n constructor(s3: S3, bucket: string, assetResolver: AssetResolver) {\n this.assetResolver = assetResolver;\n this.s3 = s3;\n this.bucket = bucket;\n }\n\n async resolve(request: AssetRequest): Promise<Asset | undefined> {\n const resolvedAsset = await this.assetResolver.resolve(request);\n\n if (resolvedAsset) {\n return resolvedAsset;\n }\n\n try {\n const originalFileMetadataKey = await this.findMetadata(request);\n\n if (!originalFileMetadataKey) {\n return undefined;\n }\n\n // We need to fetch the actual size and content type of the file.\n const attrs = await this.getFileAttributes(request.getKey());\n\n if (!attrs) {\n return undefined;\n }\n\n const metadataReader = new S3AssetMetadataReader(this.s3, this.bucket);\n const metadata = await metadataReader.getMetadata(\n originalFileMetadataKey.replace(\".metadata\", \"\")\n );\n\n const asset = new CustomAsset({\n // These attributes do not change between the original and derived files.\n id: metadata.id,\n tenant: metadata.tenant,\n locale: metadata.locale,\n // Assign the size and content type of the requested file.\n size: attrs.size,\n contentType: attrs.contentType,\n key: request.getKey()\n });\n\n asset.setContentsReader(new S3ContentsReader(this.s3, this.bucket));\n\n return asset;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n }\n\n // https://d1s78zhy5i2noq.cloudfront.net/files/65a99721c20390000869e3d3/9l9iafhgn-17.jpeg\n\n private async findMetadata(request: AssetRequest) {\n const requestFolder = path.dirname(request.getKey());\n\n const assetList = await this.s3.listObjects({\n Bucket: this.bucket,\n Prefix: requestFolder + \"/\"\n });\n\n if (!assetList.Contents) {\n return undefined;\n }\n\n // We assume that there's only one asset with the `.metadata`, and that's the original file.\n const metadata = assetList.Contents.find(file => file.Key?.endsWith(\".metadata\"));\n\n return metadata ? metadata.Key : undefined;\n }\n\n private async getFileAttributes(key: string) {\n const head = await this.s3.headObject({\n Bucket: this.bucket,\n Key: key\n });\n\n if (!head) {\n return undefined;\n }\n\n return {\n size: head.ContentLength || 0,\n contentType: head.ContentType || \"\"\n };\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"names":["_path","_interopRequireDefault","require","_S3AssetMetadataReader","_S3ContentsReader","_CustomAsset","S3CustomAssetResolver","constructor","s3","bucket","assetResolver","resolve","request","resolvedAsset","originalFileMetadataKey","findMetadata","undefined","attrs","getFileAttributes","getKey","metadataReader","S3AssetMetadataReader","metadata","getMetadata","replace","asset","CustomAsset","id","tenant","locale","size","contentType","key","setContentsReader","S3ContentsReader","error","console","requestFolder","path","dirname","assetList","listObjects","Bucket","Prefix","Contents","find","file","Key","endsWith","head","headObject","ContentLength","ContentType","exports"],"sources":["S3CustomAssetResolver.ts"],"sourcesContent":["import path from \"path\";\nimport type { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport type { Asset, AssetRequest, AssetResolver } from \"@webiny/api-file-manager\";\nimport { S3AssetMetadataReader } from \"~/assetDelivery/s3/S3AssetMetadataReader\";\nimport { S3ContentsReader } from \"~/assetDelivery/s3/S3ContentsReader\";\nimport { CustomAsset } from \"./CustomAsset\";\n\n/**\n * This asset resolver kicks in only if the default resolution fails to resolve an asset.\n * The goal of this resolver is to fetch .metadata from the original file that was uploaded via th File Manager.\n */\nexport class S3CustomAssetResolver implements AssetResolver {\n private readonly s3: S3;\n private readonly bucket: string;\n private assetResolver: AssetResolver;\n\n constructor(s3: S3, bucket: string, assetResolver: AssetResolver) {\n this.assetResolver = assetResolver;\n this.s3 = s3;\n this.bucket = bucket;\n }\n\n async resolve(request: AssetRequest): Promise<Asset | undefined> {\n const resolvedAsset = await this.assetResolver.resolve(request);\n\n if (resolvedAsset) {\n return resolvedAsset;\n }\n\n try {\n const originalFileMetadataKey = await this.findMetadata(request);\n\n if (!originalFileMetadataKey) {\n return undefined;\n }\n\n // We need to fetch the actual size and content type of the file.\n const attrs = await this.getFileAttributes(request.getKey());\n\n if (!attrs) {\n return undefined;\n }\n\n const metadataReader = new S3AssetMetadataReader(this.s3, this.bucket);\n const metadata = await metadataReader.getMetadata(\n originalFileMetadataKey.replace(\".metadata\", \"\")\n );\n\n const asset = new CustomAsset({\n // These attributes do not change between the original and derived files.\n id: metadata.id,\n tenant: metadata.tenant,\n locale: metadata.locale,\n // Assign the size and content type of the requested file.\n size: attrs.size,\n contentType: attrs.contentType,\n key: request.getKey()\n });\n\n asset.setContentsReader(new S3ContentsReader(this.s3, this.bucket));\n\n return asset;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n }\n\n // https://d1s78zhy5i2noq.cloudfront.net/files/65a99721c20390000869e3d3/9l9iafhgn-17.jpeg\n\n private async findMetadata(request: AssetRequest) {\n const requestFolder = path.dirname(request.getKey());\n\n const assetList = await this.s3.listObjects({\n Bucket: this.bucket,\n Prefix: requestFolder + \"/\"\n });\n\n if (!assetList.Contents) {\n return undefined;\n }\n\n // We assume that there's only one asset with the `.metadata`, and that's the original file.\n const metadata = assetList.Contents.find(file => file.Key?.endsWith(\".metadata\"));\n\n return metadata ? metadata.Key : undefined;\n }\n\n private async getFileAttributes(key: string) {\n const head = await this.s3.headObject({\n Bucket: this.bucket,\n Key: key\n });\n\n if (!head) {\n return undefined;\n }\n\n return {\n size: head.ContentLength || 0,\n contentType: head.ContentType || \"\"\n };\n }\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","_clientS","_S3CustomAssetResolver","_CustomAssetProcessor","customAssetDeliveryConfig","createAssetDeliveryConfig","config","decorateAssetResolver","assetResolver","s3","S3","region","process","env","AWS_REGION","S3CustomAssetResolver","String","S3_BUCKET","decorateAssetProcessor","assetProcessor","CustomAssetProcessor","exports"],"sources":["customAssetDeliveryConfig.ts"],"sourcesContent":["import { createAssetDeliveryConfig } from \"@webiny/api-file-manager\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { S3CustomAssetResolver } from \"./S3CustomAssetResolver\";\nimport { CustomAssetProcessor } from \"~/assetDelivery/customAssets/CustomAssetProcessor\";\n\nexport const customAssetDeliveryConfig = () => {\n return createAssetDeliveryConfig(config => {\n config.decorateAssetResolver(({ assetResolver }) => {\n const s3 = new S3({ region: process.env.AWS_REGION });\n return new S3CustomAssetResolver(s3, String(process.env.S3_BUCKET), assetResolver);\n });\n\n config.decorateAssetProcessor(({ assetProcessor }) => {\n return new CustomAssetProcessor(assetProcessor);\n });\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAEO,MAAMI,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAAC,yCAAyB,EAACC,MAAM,IAAI;IACvCA,MAAM,CAACC,qBAAqB,CAAC,CAAC;MAAEC;IAAc,CAAC,KAAK;MAChD,MAAMC,EAAE,GAAG,IAAIC,WAAE,CAAC;QAAEC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MAAW,CAAC,CAAC;MACrD,OAAO,IAAIC,4CAAqB,CAACN,EAAE,EAAEO,MAAM,CAACJ,OAAO,CAACC,GAAG,CAACI,SAAS,CAAC,EAAET,aAAa,CAAC;IACtF,CAAC,CAAC;IAEFF,MAAM,CAACY,sBAAsB,CAAC,CAAC;MAAEC;IAAe,CAAC,KAAK;MAClD,OAAO,IAAIC,0CAAoB,CAACD,cAAc,CAAC;IACnD,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAjB,yBAAA,GAAAA,yBAAA"}
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_clientS","_S3CustomAssetResolver","_CustomAssetProcessor","customAssetDeliveryConfig","createAssetDeliveryConfig","config","decorateAssetResolver","assetResolver","s3","S3","region","process","env","AWS_REGION","S3CustomAssetResolver","String","S3_BUCKET","decorateAssetProcessor","assetProcessor","CustomAssetProcessor","exports"],"sources":["customAssetDeliveryConfig.ts"],"sourcesContent":["import { createAssetDeliveryConfig } from \"@webiny/api-file-manager\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { S3CustomAssetResolver } from \"./S3CustomAssetResolver\";\nimport { CustomAssetProcessor } from \"~/assetDelivery/customAssets/CustomAssetProcessor\";\n\nexport const customAssetDeliveryConfig = () => {\n return createAssetDeliveryConfig(config => {\n config.decorateAssetResolver(({ assetResolver }) => {\n const s3 = new S3({ region: process.env.AWS_REGION });\n return new S3CustomAssetResolver(s3, String(process.env.S3_BUCKET), assetResolver);\n });\n\n config.decorateAssetProcessor(({ assetProcessor }) => {\n return new CustomAssetProcessor(assetProcessor);\n });\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAEO,MAAMI,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAAC,yCAAyB,EAACC,MAAM,IAAI;IACvCA,MAAM,CAACC,qBAAqB,CAAC,CAAC;MAAEC;IAAc,CAAC,KAAK;MAChD,MAAMC,EAAE,GAAG,IAAIC,WAAE,CAAC;QAAEC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MAAW,CAAC,CAAC;MACrD,OAAO,IAAIC,4CAAqB,CAACN,EAAE,EAAEO,MAAM,CAACJ,OAAO,CAACC,GAAG,CAACI,SAAS,CAAC,EAAET,aAAa,CAAC;IACtF,CAAC,CAAC;IAEFF,MAAM,CAACY,sBAAsB,CAAC,CAAC;MAAEC;IAAe,CAAC,KAAK;MAClD,OAAO,IAAIC,0CAAoB,CAACD,cAAc,CAAC;IACnD,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAjB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_S3AssetResolver","require","_S3AssetMetadataReader","_S3OutputStrategy","_S3ContentsReader","_S3ErrorAssetReply","_S3RedirectAssetReply","_S3StreamAssetReply","_SharpTransform","_CallableContentsReader"],"sources":["index.ts"],"sourcesContent":["export { S3AssetResolver } from \"./s3/S3AssetResolver\";\nexport { S3AssetMetadataReader } from \"./s3/S3AssetMetadataReader\";\nexport { S3OutputStrategy } from \"./s3/S3OutputStrategy\";\nexport { S3ContentsReader } from \"./s3/S3ContentsReader\";\nexport { S3ErrorAssetReply } from \"./s3/S3ErrorAssetReply\";\nexport { S3RedirectAssetReply } from \"./s3/S3RedirectAssetReply\";\nexport { S3StreamAssetReply } from \"./s3/S3StreamAssetReply\";\nexport { SharpTransform } from \"./s3/SharpTransform\";\nexport { CallableContentsReader } from \"./s3/transformation/CallableContentsReader\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAR,OAAA"}
|
|
1
|
+
{"version":3,"names":["_S3AssetResolver","require","_S3AssetMetadataReader","_S3OutputStrategy","_S3ContentsReader","_S3ErrorAssetReply","_S3RedirectAssetReply","_S3StreamAssetReply","_SharpTransform","_CallableContentsReader"],"sources":["index.ts"],"sourcesContent":["export { S3AssetResolver } from \"./s3/S3AssetResolver\";\nexport { S3AssetMetadataReader } from \"./s3/S3AssetMetadataReader\";\nexport { S3OutputStrategy } from \"./s3/S3OutputStrategy\";\nexport { S3ContentsReader } from \"./s3/S3ContentsReader\";\nexport { S3ErrorAssetReply } from \"./s3/S3ErrorAssetReply\";\nexport { S3RedirectAssetReply } from \"./s3/S3RedirectAssetReply\";\nexport { S3StreamAssetReply } from \"./s3/S3StreamAssetReply\";\nexport { SharpTransform } from \"./s3/SharpTransform\";\nexport { CallableContentsReader } from \"./s3/transformation/CallableContentsReader\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAR,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3AssetMetadataReader","constructor","s3","bucket","getMetadata","key","metadataKey","console","log","Body","getObject","Bucket","Key","Error","metadata","JSON","parse","transformToString","id","tenant","locale","size","contentType","exports"],"sources":["S3AssetMetadataReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3\";\n\ninterface AssetMetadata {\n id: string;\n tenant: string;\n locale: string;\n size: number;\n contentType: string;\n}\n\nexport class S3AssetMetadataReader {\n private readonly s3: S3;\n private readonly bucket: string;\n\n constructor(s3: S3, bucket: string) {\n this.bucket = bucket;\n this.s3 = s3;\n }\n\n async getMetadata(key: string): Promise<AssetMetadata> {\n const metadataKey = `${key}.metadata`;\n\n console.log(\"Reading metadata\", metadataKey);\n\n const { Body } = await this.s3.getObject({\n Bucket: this.bucket,\n Key: metadataKey\n });\n\n if (!Body) {\n throw Error(`Missing or corrupted ${metadataKey} file!`);\n }\n\n const metadata = JSON.parse(await Body.transformToString());\n\n return {\n id: metadata.id,\n tenant: metadata.tenant,\n locale: metadata.locale,\n size: metadata.size,\n contentType: metadata.contentType\n };\n }\n}\n"],"mappings":";;;;;;AAUO,MAAMA,qBAAqB,CAAC;EAI/BC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAE;IAChC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACD,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAME,WAAWA,CAACC,GAAW,EAA0B;IACnD,MAAMC,WAAW,
|
|
1
|
+
{"version":3,"names":["S3AssetMetadataReader","constructor","s3","bucket","getMetadata","key","metadataKey","console","log","Body","getObject","Bucket","Key","Error","metadata","JSON","parse","transformToString","id","tenant","locale","size","contentType","exports"],"sources":["S3AssetMetadataReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3\";\n\ninterface AssetMetadata {\n id: string;\n tenant: string;\n locale: string;\n size: number;\n contentType: string;\n}\n\nexport class S3AssetMetadataReader {\n private readonly s3: S3;\n private readonly bucket: string;\n\n constructor(s3: S3, bucket: string) {\n this.bucket = bucket;\n this.s3 = s3;\n }\n\n async getMetadata(key: string): Promise<AssetMetadata> {\n const metadataKey = `${key}.metadata`;\n\n console.log(\"Reading metadata\", metadataKey);\n\n const { Body } = await this.s3.getObject({\n Bucket: this.bucket,\n Key: metadataKey\n });\n\n if (!Body) {\n throw Error(`Missing or corrupted ${metadataKey} file!`);\n }\n\n const metadata = JSON.parse(await Body.transformToString());\n\n return {\n id: metadata.id,\n tenant: metadata.tenant,\n locale: metadata.locale,\n size: metadata.size,\n contentType: metadata.contentType\n };\n }\n}\n"],"mappings":";;;;;;AAUO,MAAMA,qBAAqB,CAAC;EAI/BC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAE;IAChC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACD,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAME,WAAWA,CAACC,GAAW,EAA0B;IACnD,MAAMC,WAAW,GAAG,GAAGD,GAAG,WAAW;IAErCE,OAAO,CAACC,GAAG,CAAC,kBAAkB,EAAEF,WAAW,CAAC;IAE5C,MAAM;MAAEG;IAAK,CAAC,GAAG,MAAM,IAAI,CAACP,EAAE,CAACQ,SAAS,CAAC;MACrCC,MAAM,EAAE,IAAI,CAACR,MAAM;MACnBS,GAAG,EAAEN;IACT,CAAC,CAAC;IAEF,IAAI,CAACG,IAAI,EAAE;MACP,MAAMI,KAAK,CAAC,wBAAwBP,WAAW,QAAQ,CAAC;IAC5D;IAEA,MAAMQ,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAAC,MAAMP,IAAI,CAACQ,iBAAiB,CAAC,CAAC,CAAC;IAE3D,OAAO;MACHC,EAAE,EAAEJ,QAAQ,CAACI,EAAE;MACfC,MAAM,EAAEL,QAAQ,CAACK,MAAM;MACvBC,MAAM,EAAEN,QAAQ,CAACM,MAAM;MACvBC,IAAI,EAAEP,QAAQ,CAACO,IAAI;MACnBC,WAAW,EAAER,QAAQ,CAACQ;IAC1B,CAAC;EACL;AACJ;AAACC,OAAA,CAAAvB,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
-
import {
|
|
1
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
+
import type { AssetRequest, AssetResolver } from "@webiny/api-file-manager";
|
|
3
|
+
import { Asset } from "@webiny/api-file-manager";
|
|
3
4
|
export declare class S3AssetResolver implements AssetResolver {
|
|
4
5
|
private readonly s3;
|
|
5
6
|
private readonly bucket;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","_S3AssetMetadataReader","_S3ContentsReader","S3AssetResolver","constructor","s3","bucket","resolve","request","metadataReader","S3AssetMetadataReader","metadata","getMetadata","getKey","asset","Asset","id","tenant","locale","size","contentType","key","setContentsReader","S3ContentsReader","error","console","log","message","undefined","exports"],"sources":["S3AssetResolver.ts"],"sourcesContent":["import { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport {
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_S3AssetMetadataReader","_S3ContentsReader","S3AssetResolver","constructor","s3","bucket","resolve","request","metadataReader","S3AssetMetadataReader","metadata","getMetadata","getKey","asset","Asset","id","tenant","locale","size","contentType","key","setContentsReader","S3ContentsReader","error","console","log","message","undefined","exports"],"sources":["S3AssetResolver.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport type { AssetRequest, AssetResolver } from \"@webiny/api-file-manager\";\nimport { Asset } from \"@webiny/api-file-manager\";\nimport { S3AssetMetadataReader } from \"./S3AssetMetadataReader\";\nimport { S3ContentsReader } from \"./S3ContentsReader\";\n\nexport class S3AssetResolver implements AssetResolver {\n private readonly 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 resolve(request: AssetRequest): Promise<Asset | undefined> {\n try {\n const metadataReader = new S3AssetMetadataReader(this.s3, this.bucket);\n const metadata = await metadataReader.getMetadata(request.getKey());\n\n const asset = new Asset({\n id: metadata.id,\n tenant: metadata.tenant,\n locale: metadata.locale,\n size: metadata.size,\n contentType: metadata.contentType,\n key: request.getKey()\n });\n\n asset.setContentsReader(new S3ContentsReader(this.s3, this.bucket));\n\n return asset;\n } catch (error) {\n console.log(`S3AssetResolver failed to read metadata: ${error.message}`);\n return undefined;\n }\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEO,MAAMG,eAAe,CAA0B;EAIlDC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAE;IAChC,IAAI,CAACD,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAMC,OAAOA,CAACC,OAAqB,EAA8B;IAC7D,IAAI;MACA,MAAMC,cAAc,GAAG,IAAIC,4CAAqB,CAAC,IAAI,CAACL,EAAE,EAAE,IAAI,CAACC,MAAM,CAAC;MACtE,MAAMK,QAAQ,GAAG,MAAMF,cAAc,CAACG,WAAW,CAACJ,OAAO,CAACK,MAAM,CAAC,CAAC,CAAC;MAEnE,MAAMC,KAAK,GAAG,IAAIC,qBAAK,CAAC;QACpBC,EAAE,EAAEL,QAAQ,CAACK,EAAE;QACfC,MAAM,EAAEN,QAAQ,CAACM,MAAM;QACvBC,MAAM,EAAEP,QAAQ,CAACO,MAAM;QACvBC,IAAI,EAAER,QAAQ,CAACQ,IAAI;QACnBC,WAAW,EAAET,QAAQ,CAACS,WAAW;QACjCC,GAAG,EAAEb,OAAO,CAACK,MAAM,CAAC;MACxB,CAAC,CAAC;MAEFC,KAAK,CAACQ,iBAAiB,CAAC,IAAIC,kCAAgB,CAAC,IAAI,CAAClB,EAAE,EAAE,IAAI,CAACC,MAAM,CAAC,CAAC;MAEnE,OAAOQ,KAAK;IAChB,CAAC,CAAC,OAAOU,KAAK,EAAE;MACZC,OAAO,CAACC,GAAG,CAAC,4CAA4CF,KAAK,CAACG,OAAO,EAAE,CAAC;MACxE,OAAOC,SAAS;IACpB;EACJ;AACJ;AAACC,OAAA,CAAA1B,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
4
|
+
import type { Asset, AssetContentsReader } from "@webiny/api-file-manager";
|
|
4
5
|
export declare class S3ContentsReader implements AssetContentsReader {
|
|
5
6
|
private s3;
|
|
6
7
|
private readonly bucket;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3ContentsReader","constructor","s3","bucket","read","asset","Body","getObject","Bucket","Key","getKey","Error","Buffer","from","transformToByteArray","exports"],"sources":["S3ContentsReader.ts"],"sourcesContent":["import { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { 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"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAgC;EAIzDC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAE;IAChC,IAAI,CAACD,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAMC,IAAIA,CAACC,KAAY,EAAmB;IACtC,MAAM;MAAEC;IAAK,CAAC,GAAG,MAAM,IAAI,CAACJ,EAAE,CAACK,SAAS,CAAC;MACrCC,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBM,GAAG,EAAEJ,KAAK,CAACK,MAAM,CAAC;IACtB,CAAC,CAAC;IAEF,IAAI,CAACJ,IAAI,EAAE;MACP,MAAMK,KAAK,
|
|
1
|
+
{"version":3,"names":["S3ContentsReader","constructor","s3","bucket","read","asset","Body","getObject","Bucket","Key","getKey","Error","Buffer","from","transformToByteArray","exports"],"sources":["S3ContentsReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3\";\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"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAgC;EAIzDC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAE;IAChC,IAAI,CAACD,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAMC,IAAIA,CAACC,KAAY,EAAmB;IACtC,MAAM;MAAEC;IAAK,CAAC,GAAG,MAAM,IAAI,CAACJ,EAAE,CAACK,SAAS,CAAC;MACrCC,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBM,GAAG,EAAEJ,KAAK,CAACK,MAAM,CAAC;IACtB,CAAC,CAAC;IAEF,IAAI,CAACJ,IAAI,EAAE;MACP,MAAMK,KAAK,CAAC,kBAAkBN,KAAK,CAACK,MAAM,CAAC,CAAC,GAAG,CAAC;IACpD;IAEA,OAAOE,MAAM,CAACC,IAAI,CAAC,MAAMP,IAAI,CAACQ,oBAAoB,CAAC,CAAC,CAAC;EACzD;AACJ;AAACC,OAAA,CAAAf,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","S3ErrorAssetReply","AssetReply","constructor","message","code","body","error","exports"],"sources":["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"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEO,MAAMC,iBAAiB,SAASC,0BAAU,CAAC;EAC9CC,WAAWA,CAACC,OAAe,EAAE;IACzB,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,IAAI,EAAEA,CAAA,MAAO;QAAEC,KAAK,EAAEH;MAAQ,CAAC;IACnC,CAAC,CAAC;EACN;AACJ;AAACI,OAAA,CAAAP,iBAAA,GAAAA,iBAAA"}
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","S3ErrorAssetReply","AssetReply","constructor","message","code","body","error","exports"],"sources":["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"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEO,MAAMC,iBAAiB,SAASC,0BAAU,CAAC;EAC9CC,WAAWA,CAACC,OAAe,EAAE;IACzB,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,IAAI,EAAEA,CAAA,MAAO;QAAEC,KAAK,EAAEH;MAAQ,CAAC;IACnC,CAAC,CAAC;EACN;AACJ;AAACI,OAAA,CAAAP,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Asset, AssetOutputStrategy, AssetReply } from "@webiny/api-file-manager";
|
|
2
|
-
import { S3 } from "@webiny/aws-sdk/client-s3";
|
|
1
|
+
import type { Asset, AssetOutputStrategy, AssetReply } from "@webiny/api-file-manager";
|
|
2
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
3
3
|
/**
|
|
4
4
|
* This strategy outputs an asset taking into account the size of the asset contents.
|
|
5
5
|
* If the asset is larger than 5MB, a presigned URL will be generated, and a redirect will happen.
|
|
@@ -8,7 +8,8 @@ export declare class S3OutputStrategy implements AssetOutputStrategy {
|
|
|
8
8
|
private readonly s3;
|
|
9
9
|
private readonly bucket;
|
|
10
10
|
private readonly presignedUrlTtl;
|
|
11
|
-
|
|
11
|
+
private readonly assetStreamingMaxSize;
|
|
12
|
+
constructor(s3: S3, bucket: string, presignedUrlTtl: number, assetStreamingMaxSize: number);
|
|
12
13
|
output(asset: Asset): Promise<AssetReply>;
|
|
13
14
|
protected getPresignedUrl(asset: Asset): Promise<string>;
|
|
14
15
|
}
|
|
@@ -7,22 +7,23 @@ exports.S3OutputStrategy = void 0;
|
|
|
7
7
|
var _clientS = require("@webiny/aws-sdk/client-s3");
|
|
8
8
|
var _S3RedirectAssetReply = require("./S3RedirectAssetReply");
|
|
9
9
|
var _S3StreamAssetReply = require("./S3StreamAssetReply");
|
|
10
|
-
const MAX_RETURN_CONTENT_LENGTH = 4915200; // ~4.8 MB
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* This strategy outputs an asset taking into account the size of the asset contents.
|
|
14
12
|
* If the asset is larger than 5MB, a presigned URL will be generated, and a redirect will happen.
|
|
15
13
|
*/
|
|
16
14
|
class S3OutputStrategy {
|
|
17
|
-
constructor(s3, bucket, presignedUrlTtl) {
|
|
15
|
+
constructor(s3, bucket, presignedUrlTtl, assetStreamingMaxSize) {
|
|
16
|
+
this.assetStreamingMaxSize = assetStreamingMaxSize;
|
|
18
17
|
this.presignedUrlTtl = presignedUrlTtl;
|
|
19
18
|
this.s3 = s3;
|
|
20
19
|
this.bucket = bucket;
|
|
21
20
|
}
|
|
22
21
|
async output(asset) {
|
|
23
|
-
if (
|
|
22
|
+
if (asset.getSize() > this.assetStreamingMaxSize) {
|
|
23
|
+
console.log(`Asset size is greater than ${this.assetStreamingMaxSize}; redirecting to a presigned S3 URL.`);
|
|
24
24
|
return new _S3RedirectAssetReply.S3RedirectAssetReply(await this.getPresignedUrl(asset), this.presignedUrlTtl);
|
|
25
25
|
}
|
|
26
|
+
console.log(`Asset size is smaller than ${this.assetStreamingMaxSize}; streaming directly from Lambda function.`);
|
|
26
27
|
return new _S3StreamAssetReply.S3StreamAssetReply(asset);
|
|
27
28
|
}
|
|
28
29
|
getPresignedUrl(asset) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clientS","require","_S3RedirectAssetReply","_S3StreamAssetReply","
|
|
1
|
+
{"version":3,"names":["_clientS","require","_S3RedirectAssetReply","_S3StreamAssetReply","S3OutputStrategy","constructor","s3","bucket","presignedUrlTtl","assetStreamingMaxSize","output","asset","getSize","console","log","S3RedirectAssetReply","getPresignedUrl","S3StreamAssetReply","getSignedUrl","GetObjectCommand","Bucket","Key","getKey","expiresIn","exports"],"sources":["S3OutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetReply } from \"@webiny/api-file-manager\";\nimport type { S3 } from \"@webiny/aws-sdk/client-s3\";\nimport { GetObjectCommand, getSignedUrl } from \"@webiny/aws-sdk/client-s3\";\nimport { S3RedirectAssetReply } from \"~/assetDelivery/s3/S3RedirectAssetReply\";\nimport { S3StreamAssetReply } from \"~/assetDelivery/s3/S3StreamAssetReply\";\n\n/**\n * This strategy outputs an asset taking into account the size of the asset contents.\n * If the asset is larger than 5MB, a presigned URL will be generated, and a redirect will happen.\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, presignedUrlTtl: number, assetStreamingMaxSize: number) {\n this.assetStreamingMaxSize = assetStreamingMaxSize;\n this.presignedUrlTtl = presignedUrlTtl;\n this.s3 = s3;\n this.bucket = bucket;\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"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMG,gBAAgB,CAAgC;EAMzDC,WAAWA,CAACC,EAAM,EAAEC,MAAc,EAAEC,eAAuB,EAAEC,qBAA6B,EAAE;IACxF,IAAI,CAACA,qBAAqB,GAAGA,qBAAqB;IAClD,IAAI,CAACD,eAAe,GAAGA,eAAe;IACtC,IAAI,CAACF,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAMG,MAAMA,CAACC,KAAY,EAAuB;IAC5C,IAAIA,KAAK,CAACC,OAAO,CAAC,CAAC,GAAG,IAAI,CAACH,qBAAqB,EAAE;MAC9CI,OAAO,CAACC,GAAG,CACP,8BAA8B,IAAI,CAACL,qBAAqB,sCAC5D,CAAC;MAED,OAAO,IAAIM,0CAAoB,CAC3B,MAAM,IAAI,CAACC,eAAe,CAACL,KAAK,CAAC,EACjC,IAAI,CAACH,eACT,CAAC;IACL;IAEAK,OAAO,CAACC,GAAG,CACP,8BAA8B,IAAI,CAACL,qBAAqB,4CAC5D,CAAC;IACD,OAAO,IAAIQ,sCAAkB,CAACN,KAAK,CAAC;EACxC;EAEUK,eAAeA,CAACL,KAAY,EAAE;IACpC,OAAO,IAAAO,qBAAY,EACf,IAAI,CAACZ,EAAE,EACP,IAAIa,yBAAgB,CAAC;MACjBC,MAAM,EAAE,IAAI,CAACb,MAAM;MACnBc,GAAG,EAAEV,KAAK,CAACW,MAAM,CAAC;IACtB,CAAC,CAAC,EACF;MAAEC,SAAS,EAAE,IAAI,CAACf;IAAgB,CACtC,CAAC;EACL;AACJ;AAACgB,OAAA,CAAApB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","_handler","S3RedirectAssetReply","AssetReply","constructor","url","cacheDuration","code","headers","ResponseHeaders","create","location","body","exports"],"sources":["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"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEO,MAAME,oBAAoB,SAASC,0BAAU,CAAC;EACjDC,WAAWA,CAACC,GAAW,EAAEC,aAAqB,EAAE;IAC5C,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,OAAO,EAAEC,wBAAe,CAACC,MAAM,CAAC;QAC5BC,QAAQ,EAAEN,GAAG;QACb,eAAe,EAAE,kBAAkB,GAAGC;MAC1C,CAAC,CAAC;MACFM,IAAI,EAAEA,CAAA,KAAM;IAChB,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAAX,oBAAA,GAAAA,oBAAA"}
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_handler","S3RedirectAssetReply","AssetReply","constructor","url","cacheDuration","code","headers","ResponseHeaders","create","location","body","exports"],"sources":["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"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEO,MAAME,oBAAoB,SAASC,0BAAU,CAAC;EACjDC,WAAWA,CAACC,GAAW,EAAEC,aAAqB,EAAE;IAC5C,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,OAAO,EAAEC,wBAAe,CAACC,MAAM,CAAC;QAC5BC,QAAQ,EAAEN,GAAG;QACb,eAAe,EAAE,kBAAkB,GAAGC;MAC1C,CAAC,CAAC;MACFM,IAAI,EAAEA,CAAA,KAAM;IAChB,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAAX,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Asset
|
|
1
|
+
import type { Asset } from "@webiny/api-file-manager";
|
|
2
|
+
import { AssetReply } from "@webiny/api-file-manager";
|
|
2
3
|
export declare class S3StreamAssetReply extends AssetReply {
|
|
3
4
|
constructor(asset: Asset);
|
|
4
5
|
}
|
|
@@ -11,6 +11,7 @@ class S3StreamAssetReply extends _apiFileManager.AssetReply {
|
|
|
11
11
|
super({
|
|
12
12
|
code: 200,
|
|
13
13
|
headers: _handler.ResponseHeaders.create({
|
|
14
|
+
"cache-control": `public, max-age=${86400 * 365}`,
|
|
14
15
|
"content-type": asset.getContentType()
|
|
15
16
|
}),
|
|
16
17
|
body: () => asset.getContents()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFileManager","require","_handler","S3StreamAssetReply","AssetReply","constructor","asset","code","headers","ResponseHeaders","create","getContentType","body","getContents","exports"],"sources":["S3StreamAssetReply.ts"],"sourcesContent":["import { Asset
|
|
1
|
+
{"version":3,"names":["_apiFileManager","require","_handler","S3StreamAssetReply","AssetReply","constructor","asset","code","headers","ResponseHeaders","create","getContentType","body","getContents","exports"],"sources":["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"],"mappings":";;;;;;AACA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEO,MAAME,kBAAkB,SAASC,0BAAU,CAAC;EAC/CC,WAAWA,CAACC,KAAY,EAAE;IACtB,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,OAAO,EAAEC,wBAAe,CAACC,MAAM,CAAC;QAC5B,eAAe,EAAE,mBAAmB,KAAK,GAAG,GAAG,EAAE;QACjD,cAAc,EAAEJ,KAAK,CAACK,cAAc,CAAC;MACzC,CAAC,CAAC;MACFC,IAAI,EAAEA,CAAA,KAAMN,KAAK,CAACO,WAAW,CAAC;IAClC,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAAX,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
-
import { Asset, AssetRequest, AssetTransformationStrategy } from "@webiny/api-file-manager";
|
|
1
|
+
import type { S3 } from "@webiny/aws-sdk/client-s3";
|
|
2
|
+
import type { Asset, AssetRequest, AssetTransformationStrategy } from "@webiny/api-file-manager";
|
|
3
3
|
interface SharpTransformationParams {
|
|
4
4
|
s3: S3;
|
|
5
5
|
bucket: string;
|
|
@@ -17,6 +17,7 @@ class SharpTransform {
|
|
|
17
17
|
}
|
|
18
18
|
async transform(assetRequest, asset) {
|
|
19
19
|
if (!utils.SUPPORTED_TRANSFORMABLE_IMAGES.includes(asset.getExtension())) {
|
|
20
|
+
console.log(`Transformations/optimizations of ${asset.getContentType()} assets are not supported. Skipping.`);
|
|
20
21
|
return asset;
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -36,6 +37,7 @@ class SharpTransform {
|
|
|
36
37
|
return this.optimizeAsset(transformedAsset);
|
|
37
38
|
}
|
|
38
39
|
async transformAsset(asset, options) {
|
|
40
|
+
console.log("Transform asset", options);
|
|
39
41
|
if (options.width) {
|
|
40
42
|
const {
|
|
41
43
|
s3,
|
|
@@ -54,7 +56,15 @@ class SharpTransform {
|
|
|
54
56
|
throw new Error(`Missing image body!`);
|
|
55
57
|
}
|
|
56
58
|
const buffer = Buffer.from(await Body.transformToByteArray());
|
|
57
|
-
asset.
|
|
59
|
+
const newAsset = asset.withProps({
|
|
60
|
+
size: buffer.length
|
|
61
|
+
});
|
|
62
|
+
newAsset.setContentsReader(new _CallableContentsReader.CallableContentsReader(() => buffer));
|
|
63
|
+
console.log(`Return a previously transformed asset`, {
|
|
64
|
+
key: transformedAssetKey,
|
|
65
|
+
size: newAsset.getSize()
|
|
66
|
+
});
|
|
67
|
+
return newAsset;
|
|
58
68
|
} catch (e) {
|
|
59
69
|
const optimizedImage = await this.optimizeAsset(asset);
|
|
60
70
|
const widths = new _WidthCollection.WidthCollection(this.params.imageResizeWidths);
|
|
@@ -63,23 +73,33 @@ class SharpTransform {
|
|
|
63
73
|
/**
|
|
64
74
|
* `width` is the only transformation we currently support.
|
|
65
75
|
*/
|
|
76
|
+
console.log(`Resize the asset (width: ${width})`);
|
|
66
77
|
const buffer = await optimizedImage.getContents();
|
|
67
|
-
const transformedBuffer = (0, _sharp.default)(buffer, {
|
|
78
|
+
const transformedBuffer = await (0, _sharp.default)(buffer, {
|
|
68
79
|
animated: this.isAssetAnimated(asset)
|
|
69
|
-
}).resize({
|
|
70
|
-
width
|
|
80
|
+
}).withMetadata().resize({
|
|
81
|
+
width,
|
|
82
|
+
withoutEnlargement: true
|
|
71
83
|
}).toBuffer();
|
|
72
84
|
|
|
73
85
|
/**
|
|
74
86
|
* Transformations are applied to the optimized image.
|
|
75
87
|
*/
|
|
76
|
-
asset.
|
|
88
|
+
const newAsset = asset.withProps({
|
|
89
|
+
size: transformedBuffer.length
|
|
90
|
+
});
|
|
91
|
+
newAsset.setContentsReader(new _CallableContentsReader.CallableContentsReader(() => transformedBuffer));
|
|
77
92
|
await s3.putObject({
|
|
78
93
|
Bucket: bucket,
|
|
79
94
|
Key: transformedAssetKey,
|
|
80
|
-
ContentType:
|
|
81
|
-
Body: await
|
|
95
|
+
ContentType: newAsset.getContentType(),
|
|
96
|
+
Body: await newAsset.getContents()
|
|
97
|
+
});
|
|
98
|
+
console.log(`Return the resized asset`, {
|
|
99
|
+
key: transformedAssetKey,
|
|
100
|
+
size: newAsset.getSize()
|
|
82
101
|
});
|
|
102
|
+
return newAsset;
|
|
83
103
|
}
|
|
84
104
|
}
|
|
85
105
|
return asset;
|
|
@@ -89,6 +109,12 @@ class SharpTransform {
|
|
|
89
109
|
s3,
|
|
90
110
|
bucket
|
|
91
111
|
} = this.params;
|
|
112
|
+
console.log("Optimize asset", {
|
|
113
|
+
id: asset.getId(),
|
|
114
|
+
key: asset.getKey(),
|
|
115
|
+
size: asset.getSize(),
|
|
116
|
+
type: asset.getContentType()
|
|
117
|
+
});
|
|
92
118
|
const assetKey = new _AssetKeyGenerator.AssetKeyGenerator(asset);
|
|
93
119
|
const optimizedAssetKey = assetKey.getOptimizedImageKey();
|
|
94
120
|
try {
|
|
@@ -101,9 +127,15 @@ class SharpTransform {
|
|
|
101
127
|
if (!Body) {
|
|
102
128
|
throw new Error(`Missing image body!`);
|
|
103
129
|
}
|
|
130
|
+
console.log("Return a previously optimized asset", optimizedAssetKey);
|
|
104
131
|
const buffer = Buffer.from(await Body.transformToByteArray());
|
|
105
|
-
asset.
|
|
132
|
+
const newAsset = asset.withProps({
|
|
133
|
+
size: buffer.length
|
|
134
|
+
});
|
|
135
|
+
newAsset.setContentsReader(new _CallableContentsReader.CallableContentsReader(() => buffer));
|
|
136
|
+
return newAsset;
|
|
106
137
|
} catch (e) {
|
|
138
|
+
console.log("Create an optimized version of the original asset", asset.getKey());
|
|
107
139
|
// If not found, create an optimized version of the original asset.
|
|
108
140
|
const buffer = await asset.getContents();
|
|
109
141
|
const optimizationMap = {
|
|
@@ -113,19 +145,23 @@ class SharpTransform {
|
|
|
113
145
|
};
|
|
114
146
|
const optimization = optimizationMap[asset.getContentType()];
|
|
115
147
|
if (!optimization) {
|
|
116
|
-
console.log(`
|
|
148
|
+
console.log(`No optimizations defined for ${asset.getContentType()}`);
|
|
117
149
|
return asset;
|
|
118
150
|
}
|
|
119
|
-
const optimizedBuffer = optimization(buffer).toBuffer();
|
|
120
|
-
|
|
151
|
+
const optimizedBuffer = await optimization(buffer).toBuffer();
|
|
152
|
+
console.log("Optimized asset size", optimizedBuffer.length);
|
|
153
|
+
const newAsset = asset.withProps({
|
|
154
|
+
size: optimizedBuffer.length
|
|
155
|
+
});
|
|
156
|
+
newAsset.setContentsReader(new _CallableContentsReader.CallableContentsReader(() => optimizedBuffer));
|
|
121
157
|
await s3.putObject({
|
|
122
158
|
Bucket: bucket,
|
|
123
159
|
Key: optimizedAssetKey,
|
|
124
|
-
ContentType:
|
|
125
|
-
Body: await
|
|
160
|
+
ContentType: newAsset.getContentType(),
|
|
161
|
+
Body: await newAsset.getContents()
|
|
126
162
|
});
|
|
163
|
+
return newAsset;
|
|
127
164
|
}
|
|
128
|
-
return asset;
|
|
129
165
|
}
|
|
130
166
|
isAssetAnimated(asset) {
|
|
131
167
|
return ["gif", "webp"].includes(asset.getExtension());
|
|
@@ -146,7 +182,7 @@ class SharpTransform {
|
|
|
146
182
|
width: 2560,
|
|
147
183
|
withoutEnlargement: true,
|
|
148
184
|
fit: "inside"
|
|
149
|
-
}).toFormat("jpeg", {
|
|
185
|
+
}).withMetadata().toFormat("jpeg", {
|
|
150
186
|
quality: 90
|
|
151
187
|
});
|
|
152
188
|
}
|