@webiny/api-file-manager-s3 6.0.0-beta.0 → 6.0.0-rc.1
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/README.md +11 -1
- package/assetDelivery/assetDeliveryConfig.d.ts +2 -6
- package/assetDelivery/assetDeliveryConfig.js +24 -23
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/createAssetDelivery.d.ts +3 -3
- package/assetDelivery/createAssetDelivery.js +15 -12
- package/assetDelivery/createAssetDelivery.js.map +1 -1
- package/assetDelivery/index.d.ts +8 -9
- package/assetDelivery/index.js +8 -68
- package/assetDelivery/index.js.map +1 -1
- package/assetDelivery/s3/S3AssetResolver.d.ts +8 -5
- package/assetDelivery/s3/S3AssetResolver.js +19 -27
- package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
- package/assetDelivery/s3/S3ContentsReader.d.ts +2 -3
- package/assetDelivery/s3/S3ContentsReader.js +1 -8
- package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
- package/assetDelivery/s3/S3ErrorAssetReply.js +2 -9
- package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3OutputStrategy.d.ts +4 -3
- package/assetDelivery/s3/S3OutputStrategy.js +12 -17
- package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
- package/assetDelivery/s3/S3RedirectAssetReply.js +4 -11
- package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
- package/assetDelivery/s3/S3StreamAssetReply.d.ts +2 -1
- package/assetDelivery/s3/S3StreamAssetReply.js +4 -11
- package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
- package/assetDelivery/s3/SharpTransform.d.ts +2 -2
- package/assetDelivery/s3/SharpTransform.js +63 -37
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.d.ts +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js +3 -12
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
- package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +1 -2
- package/assetDelivery/s3/transformation/CallableContentsReader.js +1 -8
- package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
- package/assetDelivery/s3/transformation/WidthCollection.js +1 -8
- package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
- package/assetDelivery/s3/transformation/utils.d.ts +1 -3
- package/assetDelivery/s3/transformation/utils.js +23 -19
- package/assetDelivery/s3/transformation/utils.js.map +1 -1
- package/assetDelivery/threatDetection/ObjectKey.d.ts +7 -0
- package/assetDelivery/threatDetection/ObjectKey.js +17 -0
- package/assetDelivery/threatDetection/ObjectKey.js.map +1 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +2 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +51 -0
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +2 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +6 -0
- package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -0
- package/assetDelivery/threatDetection/index.d.ts +2 -0
- package/assetDelivery/threatDetection/index.js +4 -0
- package/assetDelivery/threatDetection/index.js.map +1 -0
- package/assetDelivery/threatDetection/processThreatScanResult.d.ts +3 -0
- package/assetDelivery/threatDetection/processThreatScanResult.js +65 -0
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -0
- package/assetDelivery/threatDetection/types.d.ts +9 -0
- package/assetDelivery/threatDetection/types.js +3 -0
- package/assetDelivery/threatDetection/types.js.map +1 -0
- package/assetDelivery/types.d.ts +10 -0
- package/assetDelivery/types.js +3 -0
- package/assetDelivery/types.js.map +1 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +11 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +19 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -0
- package/enterprise/ApplyThreatScanning/feature.d.ts +1 -0
- package/enterprise/ApplyThreatScanning/feature.js +10 -0
- package/enterprise/ApplyThreatScanning/feature.js.map +1 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.d.ts +15 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +36 -0
- package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +31 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +60 -0
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -0
- package/features/DeleteFileFromBucket/feature.d.ts +1 -0
- package/features/DeleteFileFromBucket/feature.js +12 -0
- package/features/DeleteFileFromBucket/feature.js.map +1 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +11 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.js +26 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -0
- package/features/ExtractMetadata/ExtractMetadataTask.d.ts +23 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js +128 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
- package/features/ExtractMetadata/feature.d.ts +1 -0
- package/features/ExtractMetadata/feature.js +12 -0
- package/features/ExtractMetadata/feature.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +12 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +27 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.d.ts +12 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +35 -0
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -0
- package/features/FlushCache/InvalidateCacheTask.d.ts +25 -0
- package/features/FlushCache/InvalidateCacheTask.js +86 -0
- package/features/FlushCache/InvalidateCacheTask.js.map +1 -0
- package/features/FlushCache/feature.d.ts +1 -0
- package/features/FlushCache/feature.js +14 -0
- package/features/FlushCache/feature.js.map +1 -0
- package/features/WriteFileMetadata/MetadataReader.d.ts +14 -0
- package/features/WriteFileMetadata/MetadataReader.js +14 -0
- package/features/WriteFileMetadata/MetadataReader.js.map +1 -0
- package/features/WriteFileMetadata/MetadataWriter.d.ts +10 -0
- package/features/WriteFileMetadata/MetadataWriter.js +28 -0
- package/features/WriteFileMetadata/MetadataWriter.js.map +1 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +12 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +21 -0
- package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +12 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +21 -0
- package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
- package/features/WriteFileMetadata/feature.d.ts +1 -0
- package/features/WriteFileMetadata/feature.js +12 -0
- package/features/WriteFileMetadata/feature.js.map +1 -0
- package/graphql/checkPermissions.d.ts +5 -0
- package/{plugins → graphql}/checkPermissions.js +4 -11
- package/graphql/checkPermissions.js.map +1 -0
- package/graphql/schema.d.ts +1 -0
- package/{plugins/graphqlFileStorageS3.js → graphql/schema.js} +49 -57
- package/graphql/schema.js.map +1 -0
- package/index.d.ts +4 -5
- package/index.js +21 -32
- package/index.js.map +1 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +1 -1
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js +4 -11
- package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
- package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +2 -2
- package/multiPartUpload/CreateMultiPartUploadUseCase.js +3 -10
- package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
- package/package.json +23 -29
- package/types.d.ts +1 -1
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/CdnPathsGenerator.d.ts +3 -0
- package/utils/CdnPathsGenerator.js +7 -0
- package/utils/CdnPathsGenerator.js.map +1 -0
- package/utils/FileExtension.d.ts +1 -1
- package/utils/FileExtension.js +3 -10
- package/utils/FileExtension.js.map +1 -1
- package/utils/FileKey.d.ts +1 -1
- package/utils/FileKey.js +5 -13
- package/utils/FileKey.js.map +1 -1
- package/utils/FileKey.test.js +8 -9
- package/utils/FileKey.test.js.map +1 -1
- package/utils/FileNormalizer.d.ts +2 -2
- package/utils/FileNormalizer.js +5 -12
- package/utils/FileNormalizer.js.map +1 -1
- package/utils/FileUploadModifier.d.ts +1 -1
- package/utils/FileUploadModifier.js +6 -16
- package/utils/FileUploadModifier.js.map +1 -1
- package/utils/createFileNormalizerFromContext.d.ts +2 -2
- package/utils/createFileNormalizerFromContext.js +5 -12
- package/utils/createFileNormalizerFromContext.js.map +1 -1
- package/utils/getPresignedPostPayload.d.ts +4 -3
- package/utils/getPresignedPostPayload.js +10 -15
- package/utils/getPresignedPostPayload.js.map +1 -1
- package/utils/mimeTypes.js +5 -13
- package/utils/mimeTypes.js.map +1 -1
- package/utils/uploadFileToS3.d.ts +1 -3
- package/utils/uploadFileToS3.js +7 -20
- package/utils/uploadFileToS3.js.map +1 -1
- package/assetDelivery/createCustomAssetDelivery.d.ts +0 -12
- package/assetDelivery/createCustomAssetDelivery.js +0 -28
- package/assetDelivery/createCustomAssetDelivery.js.map +0 -1
- package/assetDelivery/customAssets/CustomAsset.d.ts +0 -6
- package/assetDelivery/customAssets/CustomAsset.js +0 -14
- package/assetDelivery/customAssets/CustomAsset.js.map +0 -1
- package/assetDelivery/customAssets/CustomAssetProcessor.d.ts +0 -10
- package/assetDelivery/customAssets/CustomAssetProcessor.js +0 -25
- package/assetDelivery/customAssets/CustomAssetProcessor.js.map +0 -1
- package/assetDelivery/customAssets/S3CustomAssetResolver.d.ts +0 -15
- package/assetDelivery/customAssets/S3CustomAssetResolver.js +0 -90
- package/assetDelivery/customAssets/S3CustomAssetResolver.js.map +0 -1
- package/assetDelivery/customAssets/customAssetDeliveryConfig.d.ts +0 -1
- package/assetDelivery/customAssets/customAssetDeliveryConfig.js +0 -30
- package/assetDelivery/customAssets/customAssetDeliveryConfig.js.map +0 -1
- package/assetDelivery/s3/S3AssetMetadataReader.d.ts +0 -15
- package/assetDelivery/s3/S3AssetMetadataReader.js +0 -36
- package/assetDelivery/s3/S3AssetMetadataReader.js.map +0 -1
- package/assetDelivery/s3/transformation/legacyUtils.d.ts +0 -12
- package/assetDelivery/s3/transformation/legacyUtils.js +0 -34
- package/assetDelivery/s3/transformation/legacyUtils.js.map +0 -1
- package/flushCdnCache/CdnPathsGenerator.d.ts +0 -4
- package/flushCdnCache/CdnPathsGenerator.js +0 -14
- package/flushCdnCache/CdnPathsGenerator.js.map +0 -1
- package/flushCdnCache/InvalidateCacheTask.d.ts +0 -18
- package/flushCdnCache/InvalidateCacheTask.js +0 -78
- package/flushCdnCache/InvalidateCacheTask.js.map +0 -1
- package/flushCdnCache/flushCacheOnFileDelete.d.ts +0 -3
- package/flushCdnCache/flushCacheOnFileDelete.js +0 -34
- package/flushCdnCache/flushCacheOnFileDelete.js.map +0 -1
- package/flushCdnCache/flushCacheOnFileUpdate.d.ts +0 -3
- package/flushCdnCache/flushCacheOnFileUpdate.js +0 -40
- package/flushCdnCache/flushCacheOnFileUpdate.js.map +0 -1
- package/flushCdnCache/index.d.ts +0 -1
- package/flushCdnCache/index.js +0 -15
- package/flushCdnCache/index.js.map +0 -1
- package/flushCdnCache/invalidateCacheTaskDefinition.d.ts +0 -2
- package/flushCdnCache/invalidateCacheTaskDefinition.js +0 -22
- package/flushCdnCache/invalidateCacheTaskDefinition.js.map +0 -1
- package/plugins/addFileMetadata.d.ts +0 -10
- package/plugins/addFileMetadata.js +0 -67
- package/plugins/addFileMetadata.js.map +0 -1
- package/plugins/checkPermissions.d.ts +0 -4
- package/plugins/checkPermissions.js.map +0 -1
- package/plugins/fileStorageS3.d.ts +0 -3
- package/plugins/fileStorageS3.js +0 -60
- package/plugins/fileStorageS3.js.map +0 -1
- package/plugins/graphqlFileStorageS3.d.ts +0 -4
- package/plugins/graphqlFileStorageS3.js.map +0 -1
package/utils/FileKey.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.FileKey = void 0;
|
|
8
|
-
var _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
|
|
9
|
-
var _FileExtension = require("./FileExtension");
|
|
10
|
-
class FileKey {
|
|
1
|
+
import sanitizeFilename from "sanitize-filename";
|
|
2
|
+
import { FileExtension } from "./FileExtension.js";
|
|
3
|
+
export class FileKey {
|
|
11
4
|
constructor(data) {
|
|
12
5
|
this.data = data;
|
|
13
|
-
this.extension = new
|
|
6
|
+
this.extension = new FileExtension(data);
|
|
14
7
|
this.key = this.getSanitizedKey();
|
|
15
8
|
}
|
|
16
9
|
getExtension() {
|
|
@@ -24,10 +17,9 @@ class FileKey {
|
|
|
24
17
|
return [this.data.keyPrefix, this.data.id, this.key].filter(Boolean).join("/");
|
|
25
18
|
}
|
|
26
19
|
getSanitizedKey() {
|
|
27
|
-
const key = (
|
|
20
|
+
const key = sanitizeFilename(this.data.key || this.data.name).replace(/\s/g, "");
|
|
28
21
|
return [key, this.getExtension()].filter(Boolean).join(".");
|
|
29
22
|
}
|
|
30
23
|
}
|
|
31
|
-
exports.FileKey = FileKey;
|
|
32
24
|
|
|
33
25
|
//# sourceMappingURL=FileKey.js.map
|
package/utils/FileKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["sanitizeFilename","FileExtension","FileKey","constructor","data","extension","key","getSanitizedKey","getExtension","getValue","setKey","toString","keyPrefix","id","filter","Boolean","join","name","replace"],"sources":["FileKey.ts"],"sourcesContent":["import sanitizeFilename from \"sanitize-filename\";\nimport type { PresignedPostPayloadData } from \"~/types.js\";\nimport { FileExtension } from \"~/utils/FileExtension.js\";\n\nexport class FileKey {\n private data: PresignedPostPayloadData;\n private extension: FileExtension;\n private key: string;\n\n constructor(data: PresignedPostPayloadData) {\n this.data = data;\n this.extension = new FileExtension(data);\n this.key = this.getSanitizedKey();\n }\n\n getExtension() {\n return this.extension.getValue();\n }\n\n setKey(key: string) {\n this.key = key;\n return this;\n }\n\n toString() {\n return [this.data.keyPrefix, this.data.id, this.key].filter(Boolean).join(\"/\");\n }\n\n private getSanitizedKey() {\n const key = sanitizeFilename(this.data.key || this.data.name).replace(/\\s/g, \"\");\n\n return [key, this.getExtension()].filter(Boolean).join(\".\");\n }\n}\n"],"mappings":"AAAA,OAAOA,gBAAgB,MAAM,mBAAmB;AAEhD,SAASC,aAAa;AAEtB,OAAO,MAAMC,OAAO,CAAC;EAKjBC,WAAWA,CAACC,IAA8B,EAAE;IACxC,IAAI,CAACA,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,SAAS,GAAG,IAAIJ,aAAa,CAACG,IAAI,CAAC;IACxC,IAAI,CAACE,GAAG,GAAG,IAAI,CAACC,eAAe,CAAC,CAAC;EACrC;EAEAC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI,CAACH,SAAS,CAACI,QAAQ,CAAC,CAAC;EACpC;EAEAC,MAAMA,CAACJ,GAAW,EAAE;IAChB,IAAI,CAACA,GAAG,GAAGA,GAAG;IACd,OAAO,IAAI;EACf;EAEAK,QAAQA,CAAA,EAAG;IACP,OAAO,CAAC,IAAI,CAACP,IAAI,CAACQ,SAAS,EAAE,IAAI,CAACR,IAAI,CAACS,EAAE,EAAE,IAAI,CAACP,GAAG,CAAC,CAACQ,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAClF;EAEQT,eAAeA,CAAA,EAAG;IACtB,MAAMD,GAAG,GAAGN,gBAAgB,CAAC,IAAI,CAACI,IAAI,CAACE,GAAG,IAAI,IAAI,CAACF,IAAI,CAACa,IAAI,CAAC,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAEhF,OAAO,CAACZ,GAAG,EAAE,IAAI,CAACE,YAAY,CAAC,CAAC,CAAC,CAACM,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAC/D;AACJ","ignoreList":[]}
|
package/utils/FileKey.test.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _FileKey = require("./FileKey");
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { FileKey } from "./FileKey.js";
|
|
4
3
|
describe("FileKey", () => {
|
|
5
4
|
it("should generate a file key (extension is included in the name)", () => {
|
|
6
|
-
const fileKey = new
|
|
5
|
+
const fileKey = new FileKey({
|
|
7
6
|
size: 1071690,
|
|
8
7
|
name: "image-14.jpg",
|
|
9
8
|
type: "image/jpeg"
|
|
@@ -11,7 +10,7 @@ describe("FileKey", () => {
|
|
|
11
10
|
expect(fileKey.toString()).toEqual("image-14.jpg");
|
|
12
11
|
});
|
|
13
12
|
it("should generate a file key (extension derived from file type)", () => {
|
|
14
|
-
const fileKey = new
|
|
13
|
+
const fileKey = new FileKey({
|
|
15
14
|
size: 1071690,
|
|
16
15
|
name: "image-14",
|
|
17
16
|
type: "image/jpeg"
|
|
@@ -19,7 +18,7 @@ describe("FileKey", () => {
|
|
|
19
18
|
expect(fileKey.toString()).toEqual("image-14.jpeg");
|
|
20
19
|
});
|
|
21
20
|
it("should generate a file key containing id", () => {
|
|
22
|
-
const fileKey = new
|
|
21
|
+
const fileKey = new FileKey({
|
|
23
22
|
size: 1071690,
|
|
24
23
|
name: "image-14.jpeg",
|
|
25
24
|
type: "image/jpeg",
|
|
@@ -28,7 +27,7 @@ describe("FileKey", () => {
|
|
|
28
27
|
expect(fileKey.toString()).toEqual("12345678/image-14.jpeg");
|
|
29
28
|
});
|
|
30
29
|
it("should generate a file key containing prefix", () => {
|
|
31
|
-
const fileKey = new
|
|
30
|
+
const fileKey = new FileKey({
|
|
32
31
|
size: 1071690,
|
|
33
32
|
name: "image-14.jpeg",
|
|
34
33
|
type: "image/jpeg",
|
|
@@ -37,7 +36,7 @@ describe("FileKey", () => {
|
|
|
37
36
|
expect(fileKey.toString()).toEqual("prefix/image-14.jpeg");
|
|
38
37
|
});
|
|
39
38
|
it("should generate a file key containing id and prefix", () => {
|
|
40
|
-
const fileKey = new
|
|
39
|
+
const fileKey = new FileKey({
|
|
41
40
|
size: 1071690,
|
|
42
41
|
name: "image-14.jpeg",
|
|
43
42
|
type: "image/jpeg",
|
|
@@ -47,7 +46,7 @@ describe("FileKey", () => {
|
|
|
47
46
|
expect(fileKey.toString()).toEqual("prefix/12345678/image-14.jpeg");
|
|
48
47
|
});
|
|
49
48
|
it("should use the key defined in the input", () => {
|
|
50
|
-
const fileKey = new
|
|
49
|
+
const fileKey = new FileKey({
|
|
51
50
|
size: 1071690,
|
|
52
51
|
name: "image",
|
|
53
52
|
type: "image/jpeg",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["describe","it","expect","FileKey","fileKey","size","name","type","toString","toEqual","id","keyPrefix","key"],"sources":["FileKey.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { FileKey } from \"./FileKey.js\";\n\ndescribe(\"FileKey\", () => {\n it(\"should generate a file key (extension is included in the name)\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpg\",\n type: \"image/jpeg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpg\");\n });\n\n it(\"should generate a file key (extension derived from file type)\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14\",\n type: \"image/jpeg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpeg\");\n });\n\n it(\"should generate a file key containing id\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n id: \"12345678\"\n });\n\n expect(fileKey.toString()).toEqual(\"12345678/image-14.jpeg\");\n });\n\n it(\"should generate a file key containing prefix\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n keyPrefix: \"prefix\"\n });\n\n expect(fileKey.toString()).toEqual(\"prefix/image-14.jpeg\");\n });\n\n it(\"should generate a file key containing id and prefix\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n id: \"12345678\",\n keyPrefix: \"prefix\"\n });\n\n expect(fileKey.toString()).toEqual(\"prefix/12345678/image-14.jpeg\");\n });\n\n it(\"should use the key defined in the input\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image\",\n type: \"image/jpeg\",\n key: \"image-14.jpg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpg\");\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,QAAQ;AAC7C,SAASC,OAAO;AAEhBH,QAAQ,CAAC,SAAS,EAAE,MAAM;EACtBC,EAAE,CAAC,gEAAgE,EAAE,MAAM;IACvE,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,cAAc;MACpBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFL,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;EAEFR,EAAE,CAAC,+DAA+D,EAAE,MAAM;IACtE,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,UAAU;MAChBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFL,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,eAAe,CAAC;EACvD,CAAC,CAAC;EAEFR,EAAE,CAAC,0CAA0C,EAAE,MAAM;IACjD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBG,EAAE,EAAE;IACR,CAAC,CAAC;IAEFR,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,wBAAwB,CAAC;EAChE,CAAC,CAAC;EAEFR,EAAE,CAAC,8CAA8C,EAAE,MAAM;IACrD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBI,SAAS,EAAE;IACf,CAAC,CAAC;IAEFT,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,sBAAsB,CAAC;EAC9D,CAAC,CAAC;EAEFR,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC5D,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBG,EAAE,EAAE,UAAU;MACdC,SAAS,EAAE;IACf,CAAC,CAAC;IAEFT,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,+BAA+B,CAAC;EACvE,CAAC,CAAC;EAEFR,EAAE,CAAC,yCAAyC,EAAE,MAAM;IAChD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,YAAY;MAClBK,GAAG,EAAE;IACT,CAAC,CAAC;IAEFV,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FileData, PresignedPostPayloadData } from "../types";
|
|
2
|
-
import { FileModifier } from "./FileUploadModifier";
|
|
1
|
+
import type { FileData, PresignedPostPayloadData } from "../types.js";
|
|
2
|
+
import type { FileModifier } from "./FileUploadModifier.js";
|
|
3
3
|
export interface FileToSign {
|
|
4
4
|
name: string;
|
|
5
5
|
key: string;
|
package/utils/FileNormalizer.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FileNormalizer = void 0;
|
|
7
|
-
var _utils = require("@webiny/utils");
|
|
8
|
-
var _FileKey = require("./FileKey");
|
|
1
|
+
import { mdbid } from "@webiny/utils";
|
|
2
|
+
import { FileKey } from "./FileKey.js";
|
|
9
3
|
/**
|
|
10
4
|
* FileNormalizer normalizes file data, before it's signed for upload to S3.
|
|
11
5
|
* It generates a unique file id, and makes sure that the file key includes the unique id.
|
|
12
6
|
*
|
|
13
7
|
*/
|
|
14
|
-
class FileNormalizer {
|
|
8
|
+
export class FileNormalizer {
|
|
15
9
|
constructor(modifier) {
|
|
16
10
|
this.modifier = modifier;
|
|
17
11
|
}
|
|
18
12
|
async normalizeFile(payload) {
|
|
19
13
|
const data = {
|
|
20
14
|
...payload,
|
|
21
|
-
id: payload.id ||
|
|
15
|
+
id: payload.id || mdbid(),
|
|
22
16
|
type: payload.type || "application/octet-stream"
|
|
23
17
|
};
|
|
24
|
-
const key = new
|
|
18
|
+
const key = new FileKey(data);
|
|
25
19
|
const defaultKey = key.toString();
|
|
26
20
|
const file = {
|
|
27
21
|
name: data.name,
|
|
@@ -44,6 +38,5 @@ class FileNormalizer {
|
|
|
44
38
|
};
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
|
-
exports.FileNormalizer = FileNormalizer;
|
|
48
41
|
|
|
49
42
|
//# sourceMappingURL=FileNormalizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["mdbid","FileKey","FileNormalizer","constructor","modifier","normalizeFile","payload","data","id","type","key","defaultKey","toString","file","name","size","Object","assign","setKey"],"sources":["FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { FileData, PresignedPostPayloadData } from \"~/types.js\";\nimport { FileKey } from \"~/utils/FileKey.js\";\nimport type { FileModifier } from \"./FileUploadModifier.js\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\n}\n\n/**\n * FileNormalizer normalizes file data, before it's signed for upload to S3.\n * It generates a unique file id, and makes sure that the file key includes the unique id.\n *\n */\nexport class FileNormalizer {\n private readonly modifier: FileModifier | undefined;\n\n constructor(modifier?: FileModifier) {\n this.modifier = modifier;\n }\n\n async normalizeFile(payload: PresignedPostPayloadData): Promise<FileData> {\n const data = {\n ...payload,\n id: payload.id || mdbid(),\n type: payload.type || \"application/octet-stream\"\n };\n\n const key = new FileKey(data);\n const defaultKey = key.toString();\n\n const file: FileToSign = {\n name: data.name,\n type: data.type,\n key: defaultKey,\n size: data.size\n };\n\n if (this.modifier) {\n Object.assign(file, await this.modifier(file));\n }\n\n if (defaultKey !== file.key) {\n key.setKey(file.key);\n }\n\n return {\n id: data.id,\n key: key.toString(),\n name: file.name,\n size: file.size,\n type: file.type\n };\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,eAAe;AAErC,SAASC,OAAO;AAUhB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,CAAC;EAGxBC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,aAAaA,CAACC,OAAiC,EAAqB;IACtE,MAAMC,IAAI,GAAG;MACT,GAAGD,OAAO;MACVE,EAAE,EAAEF,OAAO,CAACE,EAAE,IAAIR,KAAK,CAAC,CAAC;MACzBS,IAAI,EAAEH,OAAO,CAACG,IAAI,IAAI;IAC1B,CAAC;IAED,MAAMC,GAAG,GAAG,IAAIT,OAAO,CAACM,IAAI,CAAC;IAC7B,MAAMI,UAAU,GAAGD,GAAG,CAACE,QAAQ,CAAC,CAAC;IAEjC,MAAMC,IAAgB,GAAG;MACrBC,IAAI,EAAEP,IAAI,CAACO,IAAI;MACfL,IAAI,EAAEF,IAAI,CAACE,IAAI;MACfC,GAAG,EAAEC,UAAU;MACfI,IAAI,EAAER,IAAI,CAACQ;IACf,CAAC;IAED,IAAI,IAAI,CAACX,QAAQ,EAAE;MACfY,MAAM,CAACC,MAAM,CAACJ,IAAI,EAAE,MAAM,IAAI,CAACT,QAAQ,CAACS,IAAI,CAAC,CAAC;IAClD;IAEA,IAAIF,UAAU,KAAKE,IAAI,CAACH,GAAG,EAAE;MACzBA,GAAG,CAACQ,MAAM,CAACL,IAAI,CAACH,GAAG,CAAC;IACxB;IAEA,OAAO;MACHF,EAAE,EAAED,IAAI,CAACC,EAAE;MACXE,GAAG,EAAEA,GAAG,CAACE,QAAQ,CAAC,CAAC;MACnBE,IAAI,EAAED,IAAI,CAACC,IAAI;MACfC,IAAI,EAAEF,IAAI,CAACE,IAAI;MACfN,IAAI,EAAEI,IAAI,CAACJ;IACf,CAAC;EACL;AACJ","ignoreList":[]}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createModifierFromPlugins = exports.createFileUploadModifier = exports.FileUploadModifierPlugin = void 0;
|
|
8
|
-
var _pReduce = _interopRequireDefault(require("p-reduce"));
|
|
9
|
-
var _plugins = require("@webiny/plugins");
|
|
1
|
+
import pReduce from "p-reduce";
|
|
2
|
+
import { Plugin } from "@webiny/plugins";
|
|
10
3
|
class FileUploadModifier {
|
|
11
4
|
fileSetters = [];
|
|
12
5
|
setFile(setter) {
|
|
13
6
|
this.fileSetters.push(setter);
|
|
14
7
|
}
|
|
15
8
|
execute(file) {
|
|
16
|
-
return (
|
|
9
|
+
return pReduce(this.fileSetters, async (file, setter) => {
|
|
17
10
|
// We need to spread the original file, then add (potentially) partial changes.
|
|
18
11
|
return {
|
|
19
12
|
...file,
|
|
@@ -22,7 +15,7 @@ class FileUploadModifier {
|
|
|
22
15
|
}, file);
|
|
23
16
|
}
|
|
24
17
|
}
|
|
25
|
-
class FileUploadModifierPlugin extends
|
|
18
|
+
export class FileUploadModifierPlugin extends Plugin {
|
|
26
19
|
static type = "fm.s3.uploadModifier";
|
|
27
20
|
constructor(cb) {
|
|
28
21
|
super();
|
|
@@ -32,18 +25,15 @@ class FileUploadModifierPlugin extends _plugins.Plugin {
|
|
|
32
25
|
return this.cb(params);
|
|
33
26
|
}
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
const createFileUploadModifier = cb => {
|
|
28
|
+
export const createFileUploadModifier = cb => {
|
|
37
29
|
return new FileUploadModifierPlugin(cb);
|
|
38
30
|
};
|
|
39
|
-
|
|
40
|
-
const createModifierFromPlugins = (plugins = []) => {
|
|
31
|
+
export const createModifierFromPlugins = (plugins = []) => {
|
|
41
32
|
const modifier = new FileUploadModifier();
|
|
42
33
|
plugins.forEach(pl => pl.execute({
|
|
43
34
|
modifier
|
|
44
35
|
}));
|
|
45
36
|
return file => modifier.execute(file);
|
|
46
37
|
};
|
|
47
|
-
exports.createModifierFromPlugins = createModifierFromPlugins;
|
|
48
38
|
|
|
49
39
|
//# sourceMappingURL=FileUploadModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["pReduce","Plugin","FileUploadModifier","fileSetters","setFile","setter","push","execute","file","FileUploadModifierPlugin","type","constructor","cb","params","createFileUploadModifier","createModifierFromPlugins","plugins","modifier","forEach","pl"],"sources":["FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifier {\n private fileSetters: Setter<FileToSign>[] = [];\n\n setFile(setter: Setter<FileToSign>): void {\n this.fileSetters.push(setter);\n }\n\n execute(file: FileToSign) {\n return pReduce(\n this.fileSetters,\n async (file, setter) => {\n // We need to spread the original file, then add (potentially) partial changes.\n return { ...file, ...(await setter(file)) };\n },\n file\n );\n }\n}\n\ninterface FileUploadModifierCallbackParams {\n modifier: {\n setFile: FileUploadModifier[\"setFile\"];\n };\n}\n\nexport class FileUploadModifierPlugin extends Plugin {\n public static override type = \"fm.s3.uploadModifier\";\n private readonly cb: FileUploadModifierCallable;\n\n constructor(cb: FileUploadModifierCallable) {\n super();\n this.cb = cb;\n }\n\n execute(params: FileUploadModifierCallbackParams) {\n return this.cb(params);\n }\n}\n\ninterface FileUploadModifierCallable {\n (params: FileUploadModifierCallbackParams): void;\n}\n\nexport const createFileUploadModifier = (cb: FileUploadModifierCallable) => {\n return new FileUploadModifierPlugin(cb);\n};\n\nexport interface FileModifier {\n (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;\n}\n\nexport const createModifierFromPlugins = (\n plugins: FileUploadModifierPlugin[] = []\n): FileModifier => {\n const modifier = new FileUploadModifier();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"mappings":"AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,MAAM,QAAQ,iBAAiB;AAOxC,MAAMC,kBAAkB,CAAC;EACbC,WAAW,GAAyB,EAAE;EAE9CC,OAAOA,CAACC,MAA0B,EAAQ;IACtC,IAAI,CAACF,WAAW,CAACG,IAAI,CAACD,MAAM,CAAC;EACjC;EAEAE,OAAOA,CAACC,IAAgB,EAAE;IACtB,OAAOR,OAAO,CACV,IAAI,CAACG,WAAW,EAChB,OAAOK,IAAI,EAAEH,MAAM,KAAK;MACpB;MACA,OAAO;QAAE,GAAGG,IAAI;QAAE,IAAI,MAAMH,MAAM,CAACG,IAAI,CAAC;MAAE,CAAC;IAC/C,CAAC,EACDA,IACJ,CAAC;EACL;AACJ;AAQA,OAAO,MAAMC,wBAAwB,SAASR,MAAM,CAAC;EACjD,OAAuBS,IAAI,GAAG,sBAAsB;EAGpDC,WAAWA,CAACC,EAA8B,EAAE;IACxC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEAL,OAAOA,CAACM,MAAwC,EAAE;IAC9C,OAAO,IAAI,CAACD,EAAE,CAACC,MAAM,CAAC;EAC1B;AACJ;AAMA,OAAO,MAAMC,wBAAwB,GAAIF,EAA8B,IAAK;EACxE,OAAO,IAAIH,wBAAwB,CAACG,EAAE,CAAC;AAC3C,CAAC;AAMD,OAAO,MAAMG,yBAAyB,GAAGA,CACrCC,OAAmC,GAAG,EAAE,KACzB;EACf,MAAMC,QAAQ,GAAG,IAAIf,kBAAkB,CAAC,CAAC;EACzCc,OAAO,CAACE,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACZ,OAAO,CAAC;IAAEU;EAAS,CAAC,CAAC,CAAC;EAE/C,OAAQT,IAAgB,IAAKS,QAAQ,CAACV,OAAO,CAACC,IAAI,CAAC;AACvD,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Context } from "@webiny/api/types";
|
|
2
|
-
import { FileNormalizer } from "
|
|
1
|
+
import type { Context } from "@webiny/api/types.js";
|
|
2
|
+
import { FileNormalizer } from "../utils/FileNormalizer.js";
|
|
3
3
|
export declare const createFileNormalizerFromContext: (context: Context) => FileNormalizer;
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.createFileNormalizerFromContext = void 0;
|
|
7
|
-
var _FileNormalizer = require("./FileNormalizer");
|
|
8
|
-
var _FileUploadModifier = require("./FileUploadModifier");
|
|
9
|
-
const createFileNormalizerFromContext = context => {
|
|
10
|
-
const modifierPlugins = context.plugins.byType(_FileUploadModifier.FileUploadModifierPlugin.type);
|
|
11
|
-
return new _FileNormalizer.FileNormalizer((0, _FileUploadModifier.createModifierFromPlugins)(modifierPlugins));
|
|
1
|
+
import { FileNormalizer } from "./FileNormalizer.js";
|
|
2
|
+
import { createModifierFromPlugins, FileUploadModifierPlugin } from "./FileUploadModifier.js";
|
|
3
|
+
export const createFileNormalizerFromContext = context => {
|
|
4
|
+
const modifierPlugins = context.plugins.byType(FileUploadModifierPlugin.type);
|
|
5
|
+
return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
|
|
12
6
|
};
|
|
13
|
-
exports.createFileNormalizerFromContext = createFileNormalizerFromContext;
|
|
14
7
|
|
|
15
8
|
//# sourceMappingURL=createFileNormalizerFromContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["FileNormalizer","createModifierFromPlugins","FileUploadModifierPlugin","createFileNormalizerFromContext","context","modifierPlugins","plugins","byType","type"],"sources":["createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer.js\";\nimport { createModifierFromPlugins, FileUploadModifierPlugin } from \"~/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n const modifierPlugins = context.plugins.byType<FileUploadModifierPlugin>(\n FileUploadModifierPlugin.type\n );\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"mappings":"AACA,SAASA,cAAc;AACvB,SAASC,yBAAyB,EAAEC,wBAAwB;AAE5D,OAAO,MAAMC,+BAA+B,GAAIC,OAAgB,IAAK;EACjE,MAAMC,eAAe,GAAGD,OAAO,CAACE,OAAO,CAACC,MAAM,CAC1CL,wBAAwB,CAACM,IAC7B,CAAC;EAED,OAAO,IAAIR,cAAc,CAACC,yBAAyB,CAACI,eAAe,CAAC,CAAC;AACzE,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { FileData, PresignedPostPayloadDataResponse } from "../types.js";
|
|
2
|
+
import type { FileManagerSettings } from "@webiny/api-file-manager/domain/settings/types.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
export declare const getPresignedPostPayload: (file: FileData, settings: FileManagerSettings, tenantContext: TenantContext.Interface) => Promise<PresignedPostPayloadDataResponse>;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPresignedPostPayload = void 0;
|
|
7
|
-
var _clientS = require("@webiny/aws-sdk/client-s3");
|
|
8
|
-
var _validation = require("@webiny/validation");
|
|
1
|
+
import { S3Client, createPresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
+
import { validation } from "@webiny/validation";
|
|
9
3
|
const S3_BUCKET = process.env.S3_BUCKET;
|
|
10
4
|
const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB
|
|
11
5
|
|
|
12
6
|
const sanitizeFileSizeValue = (value, defaultValue) => {
|
|
13
7
|
try {
|
|
14
|
-
|
|
8
|
+
validation.validateSync(value, "required,numeric,gte:0");
|
|
15
9
|
return value;
|
|
16
|
-
} catch
|
|
10
|
+
} catch {
|
|
17
11
|
// TODO @ts-refactor No need to log the error?
|
|
18
12
|
return defaultValue;
|
|
19
13
|
}
|
|
20
14
|
};
|
|
21
|
-
const getPresignedPostPayload = async (file, settings) => {
|
|
15
|
+
export const getPresignedPostPayload = async (file, settings, tenantContext) => {
|
|
22
16
|
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
23
17
|
const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
|
|
18
|
+
const tenant = tenantContext.getTenant();
|
|
19
|
+
const storageKey = `tenants/${tenant.id}/files/${file.key}`;
|
|
24
20
|
const params = {
|
|
25
|
-
Key:
|
|
21
|
+
Key: storageKey,
|
|
26
22
|
Expires: 60,
|
|
27
23
|
Bucket: S3_BUCKET,
|
|
28
24
|
Conditions: [["content-length-range", uploadMinFileSize, uploadMaxFileSize]],
|
|
@@ -33,13 +29,12 @@ const getPresignedPostPayload = async (file, settings) => {
|
|
|
33
29
|
if (params.Key.startsWith("/")) {
|
|
34
30
|
params.Key = params.Key.slice(1);
|
|
35
31
|
}
|
|
36
|
-
const s3 = new
|
|
37
|
-
const payload = await
|
|
32
|
+
const s3 = new S3Client();
|
|
33
|
+
const payload = await createPresignedPost(s3, params);
|
|
38
34
|
return {
|
|
39
35
|
data: payload,
|
|
40
36
|
file
|
|
41
37
|
};
|
|
42
38
|
};
|
|
43
|
-
exports.getPresignedPostPayload = getPresignedPostPayload;
|
|
44
39
|
|
|
45
40
|
//# sourceMappingURL=getPresignedPostPayload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["S3Client","createPresignedPost","validation","S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validateSync","getPresignedPostPayload","file","settings","tenantContext","uploadMinFileSize","uploadMaxFileSize","tenant","getTenant","storageKey","id","key","params","Key","Expires","Bucket","Conditions","Fields","type","startsWith","slice","s3","payload","data"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import type { PresignedPostOptions } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { S3Client, createPresignedPost } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { validation } from \"@webiny/validation\";\nimport type { FileData, PresignedPostPayloadDataResponse } from \"~/types.js\";\nimport type { FileManagerSettings } from \"@webiny/api-file-manager/domain/settings/types.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport const getPresignedPostPayload = async (\n file: FileData,\n settings: FileManagerSettings,\n tenantContext: TenantContext.Interface\n): Promise<PresignedPostPayloadDataResponse> => {\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const tenant = tenantContext.getTenant();\n const storageKey = `tenants/${tenant.id}/files/${file.key}`;\n\n const params = {\n Key: storageKey,\n Expires: 60,\n Bucket: S3_BUCKET as string,\n Conditions: [\n [\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]\n ] as PresignedPostOptions[\"Conditions\"],\n Fields: {\n \"Content-Type\": file.type\n }\n };\n\n if (params.Key.startsWith(\"/\")) {\n params.Key = params.Key.slice(1);\n }\n\n const s3 = new S3Client();\n const payload = await createPresignedPost(s3, params);\n\n return {\n data: payload,\n file\n };\n};\n"],"mappings":"AACA,SAASA,QAAQ,EAAEC,mBAAmB,QAAQ,oCAAoC;AAClF,SAASC,UAAU,QAAQ,oBAAoB;AAK/C,MAAMC,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AACvC,MAAMG,4BAA4B,GAAG,aAAa,CAAC,CAAC;;AAEpD,MAAMC,qBAAqB,GAAGA,CAACC,KAAa,EAAEC,YAAoB,KAAa;EAC3E,IAAI;IACAP,UAAU,CAACQ,YAAY,CAACF,KAAK,EAAE,wBAAwB,CAAC;IACxD,OAAOA,KAAK;EAChB,CAAC,CAAC,MAAM;IACJ;IACA,OAAOC,YAAY;EACvB;AACJ,CAAC;AAED,OAAO,MAAME,uBAAuB,GAAG,MAAAA,CACnCC,IAAc,EACdC,QAA6B,EAC7BC,aAAsC,KACM;EAC5C,MAAMC,iBAAiB,GAAGR,qBAAqB,CAACM,QAAQ,CAACE,iBAAiB,EAAE,CAAC,CAAC;EAC9E,MAAMC,iBAAiB,GAAGT,qBAAqB,CAC3CM,QAAQ,CAACG,iBAAiB,EAC1BV,4BACJ,CAAC;EAED,MAAMW,MAAM,GAAGH,aAAa,CAACI,SAAS,CAAC,CAAC;EACxC,MAAMC,UAAU,GAAG,WAAWF,MAAM,CAACG,EAAE,UAAUR,IAAI,CAACS,GAAG,EAAE;EAE3D,MAAMC,MAAM,GAAG;IACXC,GAAG,EAAEJ,UAAU;IACfK,OAAO,EAAE,EAAE;IACXC,MAAM,EAAEtB,SAAmB;IAC3BuB,UAAU,EAAE,CACR,CAAC,sBAAsB,EAAEX,iBAAiB,EAAEC,iBAAiB,CAAC,CAC3B;IACvCW,MAAM,EAAE;MACJ,cAAc,EAAEf,IAAI,CAACgB;IACzB;EACJ,CAAC;EAED,IAAIN,MAAM,CAACC,GAAG,CAACM,UAAU,CAAC,GAAG,CAAC,EAAE;IAC5BP,MAAM,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG,CAACO,KAAK,CAAC,CAAC,CAAC;EACpC;EAEA,MAAMC,EAAE,GAAG,IAAI/B,QAAQ,CAAC,CAAC;EACzB,MAAMgC,OAAO,GAAG,MAAM/B,mBAAmB,CAAC8B,EAAE,EAAET,MAAM,CAAC;EAErD,OAAO;IACHW,IAAI,EAAED,OAAO;IACbpB;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/utils/mimeTypes.js
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.mimeTypes = void 0;
|
|
8
|
-
var _other = _interopRequireDefault(require("mime/types/other"));
|
|
9
|
-
var _standard = _interopRequireDefault(require("mime/types/standard"));
|
|
10
1
|
// @ts-expect-error
|
|
11
|
-
|
|
2
|
+
import vendorTypes from "mime/types/other.js";
|
|
12
3
|
// @ts-expect-error
|
|
4
|
+
import standardTypes from "mime/types/standard.js";
|
|
13
5
|
|
|
14
6
|
/**
|
|
15
7
|
* We need to get all extensions that are defined for a specific content type.
|
|
16
8
|
* This operation is not available via the `mime` package, so we create such an object ourselves.
|
|
17
9
|
*/
|
|
18
|
-
const mimeTypes =
|
|
19
|
-
...
|
|
20
|
-
...
|
|
10
|
+
export const mimeTypes = {
|
|
11
|
+
...vendorTypes,
|
|
12
|
+
...standardTypes
|
|
21
13
|
};
|
|
22
14
|
|
|
23
15
|
//# sourceMappingURL=mimeTypes.js.map
|
package/utils/mimeTypes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["vendorTypes","standardTypes","mimeTypes"],"sources":["mimeTypes.ts"],"sourcesContent":["// @ts-expect-error\nimport vendorTypes from \"mime/types/other.js\";\n// @ts-expect-error\nimport standardTypes from \"mime/types/standard.js\";\n\n/**\n * We need to get all extensions that are defined for a specific content type.\n * This operation is not available via the `mime` package, so we create such an object ourselves.\n */\nexport const mimeTypes: Record<string, string[]> = {\n ...vendorTypes,\n ...standardTypes\n};\n"],"mappings":"AAAA;AACA,OAAOA,WAAW,MAAM,qBAAqB;AAC7C;AACA,OAAOC,aAAa,MAAM,wBAAwB;;AAElD;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAmC,GAAG;EAC/C,GAAGF,WAAW;EACd,GAAGC;AACP,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { Response } from "node-fetch";
|
|
3
|
-
import { PresignedPost } from "@webiny/aws-sdk/client-s3";
|
|
1
|
+
import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
4
2
|
declare const _default: (buffer: Buffer, preSignedPostPayload: PresignedPost) => Promise<Response>;
|
|
5
3
|
export default _default;
|
package/utils/uploadFileToS3.js
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _formData = _interopRequireDefault(require("form-data"));
|
|
9
|
-
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
10
|
-
var _default = async (buffer, preSignedPostPayload) => {
|
|
11
|
-
const formData = new _formData.default();
|
|
12
|
-
// Add all pre signed payload field to "FormData".
|
|
13
|
-
Object.keys(preSignedPostPayload.fields).forEach(key => {
|
|
14
|
-
formData.append(key, preSignedPostPayload.fields[key]);
|
|
15
|
-
});
|
|
16
|
-
// Add file content to "FormData".
|
|
17
|
-
formData.append("file", buffer);
|
|
18
|
-
// Finally make the upload request to S3.
|
|
19
|
-
return (0, _nodeFetch.default)(preSignedPostPayload.url, {
|
|
1
|
+
export default async (buffer, preSignedPostPayload) => {
|
|
2
|
+
const formData = new FormData();
|
|
3
|
+
for (const [key, value] of Object.entries(preSignedPostPayload.fields)) {
|
|
4
|
+
formData.append(key, value);
|
|
5
|
+
}
|
|
6
|
+
formData.append("file", new Blob([Buffer.from(buffer)]));
|
|
7
|
+
return fetch(preSignedPostPayload.url, {
|
|
20
8
|
method: "POST",
|
|
21
9
|
body: formData
|
|
22
10
|
});
|
|
23
11
|
};
|
|
24
|
-
exports.default = _default;
|
|
25
12
|
|
|
26
13
|
//# sourceMappingURL=uploadFileToS3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["buffer","preSignedPostPayload","formData","FormData","key","value","Object","entries","fields","append","Blob","Buffer","from","fetch","url","method","body"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import type { PresignedPost } from \"@webiny/aws-sdk/client-s3/index.js\";\n\nexport default async (buffer: Buffer, preSignedPostPayload: PresignedPost): Promise<Response> => {\n const formData = new FormData();\n\n for (const [key, value] of Object.entries(preSignedPostPayload.fields)) {\n formData.append(key, value);\n }\n\n formData.append(\"file\", new Blob([Buffer.from(buffer)]));\n\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":"AAEA,eAAe,OAAOA,MAAc,EAAEC,oBAAmC,KAAwB;EAC7F,MAAMC,QAAQ,GAAG,IAAIC,QAAQ,CAAC,CAAC;EAE/B,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,oBAAoB,CAACO,MAAM,CAAC,EAAE;IACpEN,QAAQ,CAACO,MAAM,CAACL,GAAG,EAAEC,KAAK,CAAC;EAC/B;EAEAH,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAE,IAAIC,IAAI,CAAC,CAACC,MAAM,CAACC,IAAI,CAACZ,MAAM,CAAC,CAAC,CAAC,CAAC;EAExD,OAAOa,KAAK,CAACZ,oBAAoB,CAACa,GAAG,EAAE;IACnCC,MAAM,EAAE,MAAM;IACdC,IAAI,EAAEd;EACV,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* !! EXPERIMENTAL !!
|
|
3
|
-
*
|
|
4
|
-
* This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.
|
|
5
|
-
* These are usually files that go through background processing, video transcoding, image optimization, etc.
|
|
6
|
-
* Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able
|
|
7
|
-
* to resolve them.
|
|
8
|
-
*
|
|
9
|
-
* With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder
|
|
10
|
-
* it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.
|
|
11
|
-
*/
|
|
12
|
-
export declare const createCustomAssetDelivery: () => import("@webiny/plugins/types").PluginFactory;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createCustomAssetDelivery = void 0;
|
|
7
|
-
var _apiFileManager = require("@webiny/api-file-manager");
|
|
8
|
-
/**
|
|
9
|
-
* !! EXPERIMENTAL !!
|
|
10
|
-
*
|
|
11
|
-
* This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.
|
|
12
|
-
* These are usually files that go through background processing, video transcoding, image optimization, etc.
|
|
13
|
-
* Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able
|
|
14
|
-
* to resolve them.
|
|
15
|
-
*
|
|
16
|
-
* With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder
|
|
17
|
-
* it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.
|
|
18
|
-
*/
|
|
19
|
-
const createCustomAssetDelivery = () => {
|
|
20
|
-
return (0, _apiFileManager.createAssetDeliveryPluginLoader)(async () => {
|
|
21
|
-
return import( /* webpackChunkName: "customAssetDelivery" */"./customAssets/customAssetDeliveryConfig").then(({
|
|
22
|
-
customAssetDeliveryConfig
|
|
23
|
-
}) => customAssetDeliveryConfig());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
exports.createCustomAssetDelivery = createCustomAssetDelivery;
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=createCustomAssetDelivery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EACT,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,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CustomAsset = void 0;
|
|
7
|
-
var _apiFileManager = require("@webiny/api-file-manager");
|
|
8
|
-
/**
|
|
9
|
-
* This class is used to differentiate between regular and custom assets.
|
|
10
|
-
*/
|
|
11
|
-
class CustomAsset extends _apiFileManager.Asset {}
|
|
12
|
-
exports.CustomAsset = CustomAsset;
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=CustomAsset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
1
|
-
import { Asset, AssetProcessor, AssetRequest } from "@webiny/api-file-manager";
|
|
2
|
-
/**
|
|
3
|
-
* We don't want to run any kind of transformations on custom assets.
|
|
4
|
-
* Custom assets are usually pre-processed and ready to be delivered to the client.
|
|
5
|
-
*/
|
|
6
|
-
export declare class CustomAssetProcessor implements AssetProcessor {
|
|
7
|
-
private assetProcessor;
|
|
8
|
-
constructor(assetProcessor: AssetProcessor);
|
|
9
|
-
process(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
10
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CustomAssetProcessor = void 0;
|
|
7
|
-
var _CustomAsset = require("./CustomAsset");
|
|
8
|
-
/**
|
|
9
|
-
* We don't want to run any kind of transformations on custom assets.
|
|
10
|
-
* Custom assets are usually pre-processed and ready to be delivered to the client.
|
|
11
|
-
*/
|
|
12
|
-
class CustomAssetProcessor {
|
|
13
|
-
constructor(assetProcessor) {
|
|
14
|
-
this.assetProcessor = assetProcessor;
|
|
15
|
-
}
|
|
16
|
-
async process(assetRequest, asset) {
|
|
17
|
-
if (asset instanceof _CustomAsset.CustomAsset) {
|
|
18
|
-
return asset;
|
|
19
|
-
}
|
|
20
|
-
return this.assetProcessor.process(assetRequest, asset);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.CustomAssetProcessor = CustomAssetProcessor;
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=CustomAssetProcessor.js.map
|