@webiny/api-file-manager-s3 6.3.0 → 6.4.0-beta.0
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.js +32 -39
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/createAssetDelivery.js +5 -19
- package/assetDelivery/createAssetDelivery.js.map +1 -1
- package/assetDelivery/index.js +0 -2
- package/assetDelivery/s3/S3AssetResolver.js +21 -22
- package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
- package/assetDelivery/s3/S3ContentsReader.js +13 -16
- package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
- package/assetDelivery/s3/S3ErrorAssetReply.js +10 -9
- package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3OutputStrategy.js +23 -27
- package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
- package/assetDelivery/s3/S3RedirectAssetReply.js +12 -11
- package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3StreamAssetReply.js +12 -11
- package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
- package/assetDelivery/s3/SharpTransform.js +139 -169
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js +18 -17
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
- package/assetDelivery/s3/transformation/CallableContentsReader.js +8 -7
- package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
- package/assetDelivery/s3/transformation/WidthCollection.js +15 -16
- package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
- package/assetDelivery/s3/transformation/utils.js +24 -30
- package/assetDelivery/s3/transformation/utils.js.map +1 -1
- package/assetDelivery/threatDetection/ObjectKey.js +15 -14
- package/assetDelivery/threatDetection/ObjectKey.js.map +1 -1
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +28 -42
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +2 -3
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -1
- package/assetDelivery/threatDetection/index.js +0 -2
- package/assetDelivery/threatDetection/processThreatScanResult.js +48 -54
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
- package/assetDelivery/threatDetection/types.js +0 -3
- package/assetDelivery/types.js +0 -3
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +17 -13
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -1
- package/enterprise/ApplyThreatScanning/feature.js +6 -5
- package/enterprise/ApplyThreatScanning/feature.js.map +1 -1
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +26 -27
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -1
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +40 -51
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -1
- package/features/DeleteFileFromBucket/feature.js +7 -6
- package/features/DeleteFileFromBucket/feature.js.map +1 -1
- package/features/ExtractMetadata/ExtractMetadataHandler.js +18 -19
- package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -1
- package/features/ExtractMetadata/ExtractMetadataTask.js +75 -114
- package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -1
- package/features/ExtractMetadata/feature.js +7 -6
- package/features/ExtractMetadata/feature.js.map +1 -1
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +20 -19
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -1
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +22 -26
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -1
- package/features/FlushCache/InvalidateCacheTask.js +63 -75
- package/features/FlushCache/InvalidateCacheTask.js.map +1 -1
- package/features/FlushCache/feature.js +8 -7
- package/features/FlushCache/feature.js.map +1 -1
- 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.js +9 -10
- package/features/WriteFileMetadata/MetadataReader.js.map +1 -1
- package/features/WriteFileMetadata/MetadataWriter.js +23 -25
- package/features/WriteFileMetadata/MetadataWriter.js.map +1 -1
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +14 -12
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -1
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +16 -12
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -1
- package/features/WriteFileMetadata/feature.js +7 -6
- package/features/WriteFileMetadata/feature.js.map +1 -1
- package/graphql/checkPermissions.js +17 -32
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/schema.js +99 -102
- package/graphql/schema.js.map +1 -1
- package/index.js +19 -13
- package/index.js.map +1 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js +50 -53
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
- package/multiPartUpload/CreateMultiPartUploadUseCase.js +31 -38
- package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
- package/package.json +17 -17
- package/types.js +0 -2
- package/utils/CdnPathsGenerator.js +8 -4
- package/utils/CdnPathsGenerator.js.map +1 -1
- package/utils/FileExtension.js +12 -13
- package/utils/FileExtension.js.map +1 -1
- package/utils/FileKey.js +29 -21
- package/utils/FileKey.js.map +1 -1
- package/utils/FileKey.test.js +49 -49
- package/utils/FileKey.test.js.map +1 -1
- package/utils/FileNormalizer.js +34 -35
- package/utils/FileNormalizer.js.map +1 -1
- package/utils/FileUploadModifier.js +32 -32
- package/utils/FileUploadModifier.js.map +1 -1
- package/utils/createFileNormalizerFromContext.js +5 -4
- package/utils/createFileNormalizerFromContext.js.map +1 -1
- package/utils/getPresignedPostPayload.js +36 -33
- package/utils/getPresignedPostPayload.js.map +1 -1
- package/utils/mimeTypes.js +6 -10
- package/utils/mimeTypes.js.map +1 -1
- package/utils/uploadFileToS3.js +11 -10
- package/utils/uploadFileToS3.js.map +1 -1
- package/assetDelivery/index.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/types.js.map +0 -1
|
@@ -2,86 +2,74 @@ import { ServiceDiscovery } from "@webiny/api";
|
|
|
2
2
|
import { CloudFront } from "@webiny/aws-sdk/client-cloudfront/index.js";
|
|
3
3
|
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
4
|
import { executeWithRetry } from "@webiny/utils";
|
|
5
|
-
class ReturnContinue extends Error {
|
|
5
|
+
class ReturnContinue extends Error {
|
|
6
|
+
}
|
|
6
7
|
class InvalidateCloudfrontCacheTask {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
async run({ input, controller }) {
|
|
9
|
+
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
10
|
+
const manifest = await ServiceDiscovery.load();
|
|
11
|
+
if (!manifest) return controller.response.error({
|
|
12
|
+
message: "Unable to invalidate cache due to a missing service manifest.",
|
|
13
|
+
code: "MISSING_SERVICE_MANIFEST",
|
|
14
|
+
data: {
|
|
15
|
+
manifest: "api"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { distributionId } = manifest.api.cloudfront;
|
|
19
|
+
const invalidateCache = ()=>this.invalidateCache(input.caller, distributionId, input.paths);
|
|
20
|
+
try {
|
|
21
|
+
await executeWithRetry(invalidateCache, {
|
|
22
|
+
minTimeout: 2000,
|
|
23
|
+
retries: 10000,
|
|
24
|
+
onFailedAttempt: ({ error })=>{
|
|
25
|
+
if (this.continueIfCode.includes(error.name)) throw new ReturnContinue();
|
|
26
|
+
if (error.message.includes("not authorized to perform")) throw error;
|
|
27
|
+
if (controller.runtime.isCloseToTimeout()) throw new ReturnContinue();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof ReturnContinue) return controller.response.continue(input);
|
|
32
|
+
return controller.response.error({
|
|
33
|
+
message: error.message,
|
|
34
|
+
code: "EXECUTE_WITH_RETRY_FAILED",
|
|
35
|
+
data: input.paths
|
|
36
|
+
});
|
|
28
37
|
}
|
|
29
|
-
|
|
38
|
+
return controller.response.done();
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return controller.response.continue(input);
|
|
59
|
-
}
|
|
60
|
-
return controller.response.error({
|
|
61
|
-
message: error.message,
|
|
62
|
-
code: "EXECUTE_WITH_RETRY_FAILED",
|
|
63
|
-
data: input.paths
|
|
64
|
-
});
|
|
40
|
+
async invalidateCache(caller, distributionId, paths) {
|
|
41
|
+
const cloudfront = new CloudFront();
|
|
42
|
+
await cloudfront.createInvalidation({
|
|
43
|
+
DistributionId: distributionId,
|
|
44
|
+
InvalidationBatch: {
|
|
45
|
+
CallerReference: `${new Date().getTime()}-${caller}`,
|
|
46
|
+
Paths: {
|
|
47
|
+
Quantity: paths.length,
|
|
48
|
+
Items: paths
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
constructor(){
|
|
54
|
+
this.id = "cloudfrontInvalidateCache";
|
|
55
|
+
this.title = "Invalidate CloudFront Cache";
|
|
56
|
+
this.description = "A task to invalidate Cloudfront cache by given paths.";
|
|
57
|
+
this.maxIterations = 100;
|
|
58
|
+
this.isPrivate = true;
|
|
59
|
+
this.selfCleanup = [
|
|
60
|
+
"onSuccess",
|
|
61
|
+
"onAbort"
|
|
62
|
+
];
|
|
63
|
+
this.continueIfCode = [
|
|
64
|
+
"TooManyInvalidationsInProgress",
|
|
65
|
+
"Throttling"
|
|
66
|
+
];
|
|
65
67
|
}
|
|
66
|
-
return controller.response.done();
|
|
67
|
-
}
|
|
68
|
-
async invalidateCache(caller, distributionId, paths) {
|
|
69
|
-
const cloudfront = new CloudFront();
|
|
70
|
-
await cloudfront.createInvalidation({
|
|
71
|
-
DistributionId: distributionId,
|
|
72
|
-
InvalidationBatch: {
|
|
73
|
-
CallerReference: `${new Date().getTime()}-${caller}`,
|
|
74
|
-
Paths: {
|
|
75
|
-
Quantity: paths.length,
|
|
76
|
-
Items: paths
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
68
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({
|
|
70
|
+
implementation: InvalidateCloudfrontCacheTask,
|
|
71
|
+
dependencies: []
|
|
85
72
|
});
|
|
73
|
+
export { InvalidateCloudfrontCacheTaskDefinition };
|
|
86
74
|
|
|
87
75
|
//# sourceMappingURL=InvalidateCacheTask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/FlushCache/InvalidateCacheTask.js","sources":["../../../src/features/FlushCache/InvalidateCacheTask.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api\";\nimport { CloudFront } from \"@webiny/aws-sdk/client-cloudfront/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nclass ReturnContinue extends Error {}\n\nexport interface InvalidateCacheInput {\n /**\n * Caller of the task (e.g., `fm-before-update`, `fm-after-delete`).\n */\n caller: string;\n /**\n * Cache paths to invalidate.\n */\n paths: string[];\n}\n\nclass InvalidateCloudfrontCacheTask implements TaskDefinition.Interface<InvalidateCacheInput> {\n id = \"cloudfrontInvalidateCache\";\n title = \"Invalidate CloudFront Cache\";\n description = \"A task to invalidate Cloudfront cache by given paths.\";\n maxIterations = 100;\n isPrivate = true;\n\n selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n private continueIfCode = [\"TooManyInvalidationsInProgress\", \"Throttling\"];\n\n public async run({ input, controller }: TaskDefinition.RunParams<InvalidateCacheInput>) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n const manifest = await ServiceDiscovery.load();\n\n if (!manifest) {\n return controller.response.error({\n message: `Unable to invalidate cache due to a missing service manifest.`,\n code: \"MISSING_SERVICE_MANIFEST\",\n data: {\n manifest: \"api\"\n }\n });\n }\n\n const { distributionId } = manifest.api.cloudfront;\n\n const invalidateCache = () => {\n return this.invalidateCache(input.caller, distributionId as string, input.paths);\n };\n\n try {\n await executeWithRetry(invalidateCache, {\n minTimeout: 2000,\n // instead of forever: true\n retries: 10000,\n onFailedAttempt: ({ error }) => {\n if (this.continueIfCode.includes(error.name)) {\n throw new ReturnContinue();\n }\n\n if (error.message.includes(\"not authorized to perform\")) {\n throw error;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n throw new ReturnContinue();\n }\n }\n });\n } catch (error) {\n if (error instanceof ReturnContinue) {\n return controller.response.continue(input);\n }\n\n return controller.response.error({\n message: error.message,\n code: \"EXECUTE_WITH_RETRY_FAILED\",\n data: input.paths\n });\n }\n\n return controller.response.done();\n }\n\n private async invalidateCache(\n caller: string,\n distributionId: string,\n paths: string[]\n ): Promise<void> {\n const cloudfront = new CloudFront();\n await cloudfront.createInvalidation({\n DistributionId: distributionId,\n InvalidationBatch: {\n CallerReference: `${new Date().getTime()}-${caller}`,\n Paths: {\n Quantity: paths.length,\n Items: paths\n }\n }\n });\n }\n}\n\nexport const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({\n implementation: InvalidateCloudfrontCacheTask,\n dependencies: []\n});\n"],"names":["ReturnContinue","Error","InvalidateCloudfrontCacheTask","input","controller","manifest","ServiceDiscovery","distributionId","invalidateCache","executeWithRetry","error","caller","paths","cloudfront","CloudFront","Date","InvalidateCloudfrontCacheTaskDefinition","TaskDefinition"],"mappings":";;;;AAKA,MAAMA,uBAAuBC;AAAO;AAapC,MAAMC;IAWF,MAAa,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAkD,EAAE;QACpF,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAGtC,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAE5C,IAAI,CAACD,UACD,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAAC;YAC7B,SAAS;YACT,MAAM;YACN,MAAM;gBACF,UAAU;YACd;QACJ;QAGJ,MAAM,EAAEG,cAAc,EAAE,GAAGF,SAAS,GAAG,CAAC,UAAU;QAElD,MAAMG,kBAAkB,IACb,IAAI,CAAC,eAAe,CAACL,MAAM,MAAM,EAAEI,gBAA0BJ,MAAM,KAAK;QAGnF,IAAI;YACA,MAAMM,iBAAiBD,iBAAiB;gBACpC,YAAY;gBAEZ,SAAS;gBACT,iBAAiB,CAAC,EAAEE,KAAK,EAAE;oBACvB,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,CAACA,MAAM,IAAI,GACvC,MAAM,IAAIV;oBAGd,IAAIU,MAAM,OAAO,CAAC,QAAQ,CAAC,8BACvB,MAAMA;oBAGV,IAAIN,WAAW,OAAO,CAAC,gBAAgB,IACnC,MAAM,IAAIJ;gBAElB;YACJ;QACJ,EAAE,OAAOU,OAAO;YACZ,IAAIA,iBAAiBV,gBACjB,OAAOI,WAAW,QAAQ,CAAC,QAAQ,CAACD;YAGxC,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;gBAC7B,SAASM,MAAM,OAAO;gBACtB,MAAM;gBACN,MAAMP,MAAM,KAAK;YACrB;QACJ;QAEA,OAAOC,WAAW,QAAQ,CAAC,IAAI;IACnC;IAEA,MAAc,gBACVO,MAAc,EACdJ,cAAsB,EACtBK,KAAe,EACF;QACb,MAAMC,aAAa,IAAIC;QACvB,MAAMD,WAAW,kBAAkB,CAAC;YAChC,gBAAgBN;YAChB,mBAAmB;gBACf,iBAAiB,GAAG,IAAIQ,OAAO,OAAO,GAAG,CAAC,EAAEJ,QAAQ;gBACpD,OAAO;oBACH,UAAUC,MAAM,MAAM;oBACtB,OAAOA;gBACX;YACJ;QACJ;IACJ;;aAnFA,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GAAG;aACd,aAAa,GAAG;aAChB,SAAS,GAAG;aAEZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAEhD,cAAc,GAAG;YAAC;YAAkC;SAAa;;AA4E7E;AAEO,MAAMI,0CAA0CC,eAAe,oBAAoB,CAAC;IACvF,gBAAgBf;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -2,13 +2,14 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { FlushCacheOnFileDeleteHandler } from "./FlushCacheOnFileDeleteHandler.js";
|
|
3
3
|
import { FlushCacheOnFileUpdateHandler } from "./FlushCacheOnFileUpdateHandler.js";
|
|
4
4
|
import { InvalidateCloudfrontCacheTaskDefinition } from "./InvalidateCacheTask.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const FlushCacheFeature = createFeature({
|
|
6
|
+
name: "FileManagerS3/FlushCache",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(FlushCacheOnFileDeleteHandler);
|
|
9
|
+
container.register(FlushCacheOnFileUpdateHandler);
|
|
10
|
+
container.register(InvalidateCloudfrontCacheTaskDefinition);
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
|
+
export { FlushCacheFeature };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/FlushCache/feature.js","sources":["../../../src/features/FlushCache/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FlushCacheOnFileDeleteHandler } from \"./FlushCacheOnFileDeleteHandler.js\";\nimport { FlushCacheOnFileUpdateHandler } from \"./FlushCacheOnFileUpdateHandler.js\";\nimport { InvalidateCloudfrontCacheTaskDefinition } from \"./InvalidateCacheTask.js\";\n\nexport const FlushCacheFeature = createFeature({\n name: \"FileManagerS3/FlushCache\",\n register(container) {\n container.register(FlushCacheOnFileDeleteHandler);\n container.register(FlushCacheOnFileUpdateHandler);\n container.register(InvalidateCloudfrontCacheTaskDefinition);\n }\n});\n"],"names":["FlushCacheFeature","createFeature","container","FlushCacheOnFileDeleteHandler","FlushCacheOnFileUpdateHandler","InvalidateCloudfrontCacheTaskDefinition"],"mappings":";;;;AAKO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
+
import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
4
|
+
import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
5
|
+
declare class GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCase.Interface {
|
|
6
|
+
private metadataReader;
|
|
7
|
+
constructor(keyValueStore: GlobalKeyValueStore.Interface);
|
|
8
|
+
execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCase.Error>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const GetFileContentsByIdUseCaseImplementation: typeof GetFileContentsByIdUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsById/abstractions").IGetFileContentsByIdUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
3
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
|
+
import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
5
|
+
import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
|
|
6
|
+
import { MetadataReader } from "../WriteFileMetadata/MetadataReader.js";
|
|
7
|
+
class GetFileContentsByIdUseCaseImpl {
|
|
8
|
+
constructor(keyValueStore){
|
|
9
|
+
this.metadataReader = new MetadataReader(keyValueStore);
|
|
10
|
+
}
|
|
11
|
+
async execute(fileId) {
|
|
12
|
+
const metadata = await this.metadataReader.read(fileId);
|
|
13
|
+
if (!metadata) return Result.fail(new FileNotFoundError(fileId));
|
|
14
|
+
try {
|
|
15
|
+
const s3 = new S3();
|
|
16
|
+
const bucket = String(process.env.S3_BUCKET);
|
|
17
|
+
const response = await s3.getObject({
|
|
18
|
+
Bucket: bucket,
|
|
19
|
+
Key: metadata.bucketKey
|
|
20
|
+
});
|
|
21
|
+
if (!response.Body) return Result.fail(new FileNotFoundError(fileId));
|
|
22
|
+
const buffer = Buffer.from(await response.Body.transformToByteArray());
|
|
23
|
+
return Result.ok({
|
|
24
|
+
buffer,
|
|
25
|
+
contentType: metadata.contentType
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const GetFileContentsByIdUseCaseImplementation = GetFileContentsByIdUseCase.createImplementation({
|
|
33
|
+
implementation: GetFileContentsByIdUseCaseImpl,
|
|
34
|
+
dependencies: [
|
|
35
|
+
GlobalKeyValueStore
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { GetFileContentsByIdUseCaseImplementation };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=GetFileContentsByIdUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsById/GetFileContentsByIdUseCase.js","sources":["../../../src/features/GetFileContentsById/GetFileContentsByIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { GetFileContentsByIdUseCase } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\nimport { MetadataReader } from \"~/features/WriteFileMetadata/MetadataReader.js\";\n\nclass GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCase.Interface {\n private metadataReader: MetadataReader;\n\n constructor(keyValueStore: GlobalKeyValueStore.Interface) {\n this.metadataReader = new MetadataReader(keyValueStore);\n }\n\n async execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCase.Error>> {\n const metadata = await this.metadataReader.read(fileId);\n if (!metadata) {\n return Result.fail(new FileNotFoundError(fileId));\n }\n\n try {\n const s3 = new S3();\n const bucket = String(process.env.S3_BUCKET);\n const response = await s3.getObject({ Bucket: bucket, Key: metadata.bucketKey });\n\n if (!response.Body) {\n return Result.fail(new FileNotFoundError(fileId));\n }\n\n const buffer = Buffer.from(await response.Body.transformToByteArray());\n return Result.ok({ buffer, contentType: metadata.contentType });\n } catch (error) {\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByIdUseCaseImplementation =\n GetFileContentsByIdUseCase.createImplementation({\n implementation: GetFileContentsByIdUseCaseImpl,\n dependencies: [GlobalKeyValueStore]\n });\n"],"names":["GetFileContentsByIdUseCaseImpl","keyValueStore","MetadataReader","fileId","metadata","Result","FileNotFoundError","s3","S3","bucket","String","process","response","buffer","Buffer","error","FilePersistenceError","Error","GetFileContentsByIdUseCaseImplementation","GetFileContentsByIdUseCase","GlobalKeyValueStore"],"mappings":";;;;;;AAWA,MAAMA;IAGF,YAAYC,aAA4C,CAAE;QACtD,IAAI,CAAC,cAAc,GAAG,IAAIC,eAAeD;IAC7C;IAEA,MAAM,QAAQE,MAAc,EAAmE;QAC3F,MAAMC,WAAW,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAACD;QAChD,IAAI,CAACC,UACD,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;QAG7C,IAAI;YACA,MAAMI,KAAK,IAAIC;YACf,MAAMC,SAASC,OAAOC,QAAQ,GAAG,CAAC,SAAS;YAC3C,MAAMC,WAAW,MAAML,GAAG,SAAS,CAAC;gBAAE,QAAQE;gBAAQ,KAAKL,SAAS,SAAS;YAAC;YAE9E,IAAI,CAACQ,SAAS,IAAI,EACd,OAAOP,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;YAG7C,MAAMU,SAASC,OAAO,IAAI,CAAC,MAAMF,SAAS,IAAI,CAAC,oBAAoB;YACnE,OAAOP,OAAO,EAAE,CAAC;gBAAEQ;gBAAQ,aAAaT,SAAS,WAAW;YAAC;QACjE,EAAE,OAAOW,OAAO;YACZ,OAAOV,OAAO,IAAI,CACd,IAAIW,qBAAqBD,iBAAiBE,QAAQF,QAAQ,IAAIE,MAAMP,OAAOK;QAEnF;IACJ;AACJ;AAEO,MAAMG,2CACTC,2BAA2B,oBAAoB,CAAC;IAC5C,gBAAgBnB;IAChB,cAAc;QAACoB;KAAoB;AACvC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetFileContentsByIdUseCaseImplementation } from "./GetFileContentsByIdUseCase.js";
|
|
3
|
+
const GetFileContentsByIdFeature = createFeature({
|
|
4
|
+
name: "FileManagerS3/GetFileContentsById",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetFileContentsByIdUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetFileContentsByIdFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsById/feature.js","sources":["../../../src/features/GetFileContentsById/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByIdUseCaseImplementation } from \"./GetFileContentsByIdUseCase.js\";\n\nexport const GetFileContentsByIdFeature = createFeature({\n name: \"FileManagerS3/GetFileContentsById\",\n register(container) {\n container.register(GetFileContentsByIdUseCaseImplementation);\n }\n});\n"],"names":["GetFileContentsByIdFeature","createFeature","container","GetFileContentsByIdUseCaseImplementation"],"mappings":";;AAGO,MAAMA,6BAA6BC,cAAc;IACpD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { GetFileContentsByKeyUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
|
|
4
|
+
import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
5
|
+
declare class GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCase.Interface {
|
|
6
|
+
private tenantContext;
|
|
7
|
+
constructor(tenantContext: TenantContext.Interface);
|
|
8
|
+
execute(key: string): Promise<Result<FileContents, GetFileContentsByKeyUseCase.Error>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const GetFileContentsByKeyUseCaseImplementation: typeof GetFileContentsByKeyUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsByKey/abstractions").IGetFileContentsByKeyUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { GetFileContentsByKeyUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
|
|
5
|
+
import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
|
|
6
|
+
class GetFileContentsByKeyUseCaseImpl {
|
|
7
|
+
constructor(tenantContext){
|
|
8
|
+
this.tenantContext = tenantContext;
|
|
9
|
+
}
|
|
10
|
+
async execute(key) {
|
|
11
|
+
const tenant = this.tenantContext.getTenant();
|
|
12
|
+
const bucketKey = `tenants/${tenant.id}/files/${key}`;
|
|
13
|
+
try {
|
|
14
|
+
const s3 = new S3();
|
|
15
|
+
const bucket = String(process.env.S3_BUCKET);
|
|
16
|
+
const response = await s3.getObject({
|
|
17
|
+
Bucket: bucket,
|
|
18
|
+
Key: bucketKey
|
|
19
|
+
});
|
|
20
|
+
if (!response.Body) return Result.fail(new FileNotFoundError(key));
|
|
21
|
+
const buffer = Buffer.from(await response.Body.transformToByteArray());
|
|
22
|
+
const contentType = response.ContentType || "application/octet-stream";
|
|
23
|
+
return Result.ok({
|
|
24
|
+
buffer,
|
|
25
|
+
contentType
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const GetFileContentsByKeyUseCaseImplementation = GetFileContentsByKeyUseCase.createImplementation({
|
|
33
|
+
implementation: GetFileContentsByKeyUseCaseImpl,
|
|
34
|
+
dependencies: [
|
|
35
|
+
TenantContext
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { GetFileContentsByKeyUseCaseImplementation };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=GetFileContentsByKeyUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js","sources":["../../../src/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetFileContentsByKeyUseCase } from \"@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\n\nclass GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCase.Interface {\n constructor(private tenantContext: TenantContext.Interface) {}\n\n async execute(key: string): Promise<Result<FileContents, GetFileContentsByKeyUseCase.Error>> {\n const tenant = this.tenantContext.getTenant();\n const bucketKey = `tenants/${tenant.id}/files/${key}`;\n\n try {\n const s3 = new S3();\n const bucket = String(process.env.S3_BUCKET);\n const response = await s3.getObject({ Bucket: bucket, Key: bucketKey });\n\n if (!response.Body) {\n return Result.fail(new FileNotFoundError(key));\n }\n\n const buffer = Buffer.from(await response.Body.transformToByteArray());\n const contentType = response.ContentType || \"application/octet-stream\";\n return Result.ok({ buffer, contentType });\n } catch (error) {\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByKeyUseCaseImplementation =\n GetFileContentsByKeyUseCase.createImplementation({\n implementation: GetFileContentsByKeyUseCaseImpl,\n dependencies: [TenantContext]\n });\n"],"names":["GetFileContentsByKeyUseCaseImpl","tenantContext","key","tenant","bucketKey","s3","S3","bucket","String","process","response","Result","FileNotFoundError","buffer","Buffer","contentType","error","FilePersistenceError","Error","GetFileContentsByKeyUseCaseImplementation","GetFileContentsByKeyUseCase","TenantContext"],"mappings":";;;;;AAUA,MAAMA;IACF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,MAAM,QAAQC,GAAW,EAAoE;QACzF,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,YAAY,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAED,KAAK;QAErD,IAAI;YACA,MAAMG,KAAK,IAAIC;YACf,MAAMC,SAASC,OAAOC,QAAQ,GAAG,CAAC,SAAS;YAC3C,MAAMC,WAAW,MAAML,GAAG,SAAS,CAAC;gBAAE,QAAQE;gBAAQ,KAAKH;YAAU;YAErE,IAAI,CAACM,SAAS,IAAI,EACd,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBV;YAG7C,MAAMW,SAASC,OAAO,IAAI,CAAC,MAAMJ,SAAS,IAAI,CAAC,oBAAoB;YACnE,MAAMK,cAAcL,SAAS,WAAW,IAAI;YAC5C,OAAOC,OAAO,EAAE,CAAC;gBAAEE;gBAAQE;YAAY;QAC3C,EAAE,OAAOC,OAAO;YACZ,OAAOL,OAAO,IAAI,CACd,IAAIM,qBAAqBD,iBAAiBE,QAAQF,QAAQ,IAAIE,MAAMV,OAAOQ;QAEnF;IACJ;AACJ;AAEO,MAAMG,4CACTC,4BAA4B,oBAAoB,CAAC;IAC7C,gBAAgBpB;IAChB,cAAc;QAACqB;KAAc;AACjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetFileContentsByKeyUseCaseImplementation } from "./GetFileContentsByKeyUseCase.js";
|
|
3
|
+
const GetFileContentsByKeyFeature = createFeature({
|
|
4
|
+
name: "FileManagerS3/GetFileContentsByKey",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetFileContentsByKeyUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetFileContentsByKeyFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsByKey/feature.js","sources":["../../../src/features/GetFileContentsByKey/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByKeyUseCaseImplementation } from \"./GetFileContentsByKeyUseCase.js\";\n\nexport const GetFileContentsByKeyFeature = createFeature({\n name: \"FileManagerS3/GetFileContentsByKey\",\n register(container) {\n container.register(GetFileContentsByKeyUseCaseImplementation);\n }\n});\n"],"names":["GetFileContentsByKeyFeature","createFeature","container","GetFileContentsByKeyUseCaseImplementation"],"mappings":";;AAGO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
class MetadataReader {
|
|
2
|
+
constructor(keyValueStore){
|
|
3
|
+
this.keyValueStore = keyValueStore;
|
|
4
|
+
}
|
|
5
|
+
async read(fileId) {
|
|
6
|
+
const result = await this.keyValueStore.get(`FileManager/File/${fileId}/Metadata`);
|
|
7
|
+
if (result.isFail()) return;
|
|
8
|
+
return result.value;
|
|
9
9
|
}
|
|
10
|
-
return result.value;
|
|
11
|
-
}
|
|
12
10
|
}
|
|
11
|
+
export { MetadataReader };
|
|
13
12
|
|
|
14
13
|
//# sourceMappingURL=MetadataReader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/WriteFileMetadata/MetadataReader.js","sources":["../../../src/features/WriteFileMetadata/MetadataReader.ts"],"sourcesContent":["import { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\ninterface AssetMetadata {\n id: string;\n tenant: string;\n size: number;\n contentType: string;\n bucketKey: string;\n}\n\nexport class MetadataReader {\n constructor(private keyValueStore: GlobalKeyValueStore.Interface) {}\n\n async read(fileId: string): Promise<AssetMetadata | undefined> {\n const result = await this.keyValueStore.get<AssetMetadata>(\n `FileManager/File/${fileId}/Metadata`\n );\n\n if (result.isFail()) {\n return undefined;\n }\n\n return result.value;\n }\n}\n"],"names":["MetadataReader","keyValueStore","fileId","result"],"mappings":"AAUO,MAAMA;IACT,YAAoBC,aAA4C,CAAE;aAA9CA,aAAa,GAAbA;IAA+C;IAEnE,MAAM,KAAKC,MAAc,EAAsC;QAC3D,MAAMC,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvC,CAAC,iBAAiB,EAAED,OAAO,SAAS,CAAC;QAGzC,IAAIC,OAAO,MAAM,IACb;QAGJ,OAAOA,OAAO,KAAK;IACvB;AACJ"}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
contentType: file.type
|
|
24
|
-
};
|
|
25
|
-
}
|
|
1
|
+
class MetadataWriter {
|
|
2
|
+
constructor(tenantContext, keyValueStore){
|
|
3
|
+
this.tenantContext = tenantContext;
|
|
4
|
+
this.keyValueStore = keyValueStore;
|
|
5
|
+
}
|
|
6
|
+
async write(files) {
|
|
7
|
+
const writers = files.map(async (file)=>{
|
|
8
|
+
const metadata = this.getMetadata(file);
|
|
9
|
+
await this.keyValueStore.set(`FileManager/File/${file.id}/Metadata`, metadata);
|
|
10
|
+
});
|
|
11
|
+
await Promise.all(writers);
|
|
12
|
+
}
|
|
13
|
+
getMetadata(file) {
|
|
14
|
+
const tenant = this.tenantContext.getTenant();
|
|
15
|
+
return {
|
|
16
|
+
id: file.id,
|
|
17
|
+
bucketKey: `tenants/${tenant.id}/files/${file.key}`,
|
|
18
|
+
tenant: tenant.id,
|
|
19
|
+
size: file.size,
|
|
20
|
+
contentType: file.type
|
|
21
|
+
};
|
|
22
|
+
}
|
|
26
23
|
}
|
|
24
|
+
export { MetadataWriter };
|
|
27
25
|
|
|
28
26
|
//# sourceMappingURL=MetadataWriter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/WriteFileMetadata/MetadataWriter.js","sources":["../../../src/features/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport type { File } from \"@webiny/api-file-manager/domain/file/types.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nexport class MetadataWriter {\n constructor(\n private tenantContext: TenantContext.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface\n ) {}\n\n async write(files: File[]) {\n /**\n * We need to write each file with retry.\n */\n const writers = files.map(async file => {\n const metadata = this.getMetadata(file);\n await this.keyValueStore.set(`FileManager/File/${file.id}/Metadata`, metadata);\n });\n\n await Promise.all(writers);\n }\n\n private getMetadata(file: File) {\n const tenant = this.tenantContext.getTenant();\n return {\n id: file.id,\n bucketKey: `tenants/${tenant.id}/files/${file.key}`,\n tenant: tenant.id,\n size: file.size,\n contentType: file.type\n };\n }\n}\n"],"names":["MetadataWriter","tenantContext","keyValueStore","files","writers","file","metadata","Promise","tenant"],"mappings":"AAIO,MAAMA;IACT,YACYC,aAAsC,EACtCC,aAA4C,CACtD;aAFUD,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,MAAMC,KAAa,EAAE;QAIvB,MAAMC,UAAUD,MAAM,GAAG,CAAC,OAAME;YAC5B,MAAMC,WAAW,IAAI,CAAC,WAAW,CAACD;YAClC,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAEA,KAAK,EAAE,CAAC,SAAS,CAAC,EAAEC;QACzE;QAEA,MAAMC,QAAQ,GAAG,CAACH;IACtB;IAEQ,YAAYC,IAAU,EAAE;QAC5B,MAAMG,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO;YACH,IAAIH,KAAK,EAAE;YACX,WAAW,CAAC,QAAQ,EAAEG,OAAO,EAAE,CAAC,OAAO,EAAEH,KAAK,GAAG,EAAE;YACnD,QAAQG,OAAO,EAAE;YACjB,MAAMH,KAAK,IAAI;YACf,aAAaA,KAAK,IAAI;QAC1B;IACJ;AACJ"}
|
|
@@ -3,19 +3,21 @@ import { FileAfterBatchCreateEventHandler } from "@webiny/api-file-manager/featu
|
|
|
3
3
|
import { MetadataWriter } from "./MetadataWriter.js";
|
|
4
4
|
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
5
5
|
class WriteMetadataAfterBatchCreateHandlerImpl {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
await this.metadataWriter.write(files);
|
|
14
|
-
}
|
|
6
|
+
constructor(tenantContext, keyValueStore){
|
|
7
|
+
this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);
|
|
8
|
+
}
|
|
9
|
+
async handle(event) {
|
|
10
|
+
const { files } = event.payload;
|
|
11
|
+
await this.metadataWriter.write(files);
|
|
12
|
+
}
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const WriteMetadataAfterBatchCreateHandler = FileAfterBatchCreateEventHandler.createImplementation({
|
|
15
|
+
implementation: WriteMetadataAfterBatchCreateHandlerImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
TenantContext,
|
|
18
|
+
GlobalKeyValueStore
|
|
19
|
+
]
|
|
19
20
|
});
|
|
21
|
+
export { WriteMetadataAfterBatchCreateHandler };
|
|
20
22
|
|
|
21
23
|
//# sourceMappingURL=WriteMetadataAfterBatchCreateHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js","sources":["../../../src/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { FileAfterBatchCreateEventHandler } from \"@webiny/api-file-manager/features/file/CreateFilesInBatch/events.js\";\nimport { MetadataWriter } from \"./MetadataWriter.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nclass WriteMetadataAfterBatchCreateHandlerImpl\n implements FileAfterBatchCreateEventHandler.Interface\n{\n private readonly metadataWriter: MetadataWriter;\n\n constructor(\n tenantContext: TenantContext.Interface,\n keyValueStore: GlobalKeyValueStore.Interface\n ) {\n this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);\n }\n\n async handle(event: FileAfterBatchCreateEventHandler.Event): Promise<void> {\n const { files } = event.payload;\n await this.metadataWriter.write(files);\n }\n}\n\nexport const WriteMetadataAfterBatchCreateHandler =\n FileAfterBatchCreateEventHandler.createImplementation({\n implementation: WriteMetadataAfterBatchCreateHandlerImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n });\n"],"names":["WriteMetadataAfterBatchCreateHandlerImpl","tenantContext","keyValueStore","MetadataWriter","event","files","WriteMetadataAfterBatchCreateHandler","FileAfterBatchCreateEventHandler","TenantContext","GlobalKeyValueStore"],"mappings":";;;;AAKA,MAAMA;IAKF,YACIC,aAAsC,EACtCC,aAA4C,CAC9C;QACE,IAAI,CAAC,cAAc,GAAG,IAAIC,eAAeF,eAAeC;IAC5D;IAEA,MAAM,OAAOE,KAA6C,EAAiB;QACvE,MAAM,EAAEC,KAAK,EAAE,GAAGD,MAAM,OAAO;QAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAACC;IACpC;AACJ;AAEO,MAAMC,uCACTC,iCAAiC,oBAAoB,CAAC;IAClD,gBAAgBP;IAChB,cAAc;QAACQ;QAAeC;KAAoB;AACtD"}
|
|
@@ -3,19 +3,23 @@ import { MetadataWriter } from "./MetadataWriter.js";
|
|
|
3
3
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
4
|
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
5
5
|
class WriteMetadataAfterCreateHandlerImpl {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
constructor(tenantContext, keyValueStore){
|
|
7
|
+
this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);
|
|
8
|
+
}
|
|
9
|
+
async handle(event) {
|
|
10
|
+
const { file } = event.payload;
|
|
11
|
+
await this.metadataWriter.write([
|
|
12
|
+
file
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const WriteMetadataAfterCreateHandler = FileAfterCreateEventHandler.createImplementation({
|
|
17
|
+
implementation: WriteMetadataAfterCreateHandlerImpl,
|
|
18
|
+
dependencies: [
|
|
19
|
+
TenantContext,
|
|
20
|
+
GlobalKeyValueStore
|
|
21
|
+
]
|
|
19
22
|
});
|
|
23
|
+
export { WriteMetadataAfterCreateHandler };
|
|
20
24
|
|
|
21
25
|
//# sourceMappingURL=WriteMetadataAfterCreateHandler.js.map
|