@webiny/api-file-manager-s3 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.eb81deee7e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FileManagerS3Feature.d.ts +9 -0
- package/FileManagerS3Feature.js +27 -0
- package/FileManagerS3Feature.js.map +1 -0
- package/assetDelivery/abstractions.d.ts +11 -0
- package/assetDelivery/abstractions.js +7 -0
- package/assetDelivery/abstractions.js.map +1 -0
- package/assetDelivery/assetDeliveryConfig.d.ts +1 -1
- package/assetDelivery/assetDeliveryConfig.js +10 -44
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/createAssetDelivery.js +5 -19
- package/assetDelivery/createAssetDelivery.js.map +1 -1
- package/assetDelivery/feature.d.ts +5 -0
- package/assetDelivery/feature.js +36 -0
- package/assetDelivery/feature.js.map +1 -0
- package/assetDelivery/index.js +0 -2
- package/assetDelivery/s3/LazySharpTransform.d.ts +34 -0
- package/assetDelivery/s3/LazySharpTransform.js +34 -0
- package/assetDelivery/s3/LazySharpTransform.js.map +1 -0
- package/assetDelivery/s3/S3AssetResolver.d.ts +3 -0
- package/assetDelivery/s3/S3AssetResolver.js +32 -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.d.ts +5 -5
- package/assetDelivery/s3/S3OutputStrategy.js +33 -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.d.ts +21 -13
- package/assetDelivery/s3/SharpTransform.js +164 -173
- 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.d.ts +21 -1
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +46 -44
- 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 +51 -55
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
- package/assetDelivery/threatDetection/types.js +0 -3
- package/assetDelivery/types.d.ts +3 -0
- package/assetDelivery/types.js +0 -3
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +3 -1
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +22 -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.d.ts +9 -4
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +49 -53
- 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.d.ts +11 -6
- package/features/ExtractMetadata/ExtractMetadataTask.js +86 -116
- 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.d.ts +11 -6
- package/features/FlushCache/InvalidateCacheTask.js +75 -78
- 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/{GetFileContents → GetFileContentsById}/feature.d.ts +1 -1
- 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 +25 -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/S3GraphQLSchema.d.ts +10 -0
- package/graphql/S3GraphQLSchema.js +233 -0
- package/graphql/S3GraphQLSchema.js.map +1 -0
- package/graphql/checkPermissions.js +17 -32
- package/graphql/checkPermissions.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +1 -25
- 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 +27 -23
- package/types.d.ts +1 -1
- package/types.js +1 -3
- 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 +31 -46
- package/utils/FileNormalizer.js.map +1 -1
- package/utils/FileUploadModifier.d.ts +8 -2
- package/utils/FileUploadModifier.js +35 -33
- 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.d.ts +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/features/GetFileContents/GetFileContentsUseCase.d.ts +0 -13
- package/features/GetFileContents/GetFileContentsUseCase.js +0 -41
- package/features/GetFileContents/GetFileContentsUseCase.js.map +0 -1
- package/features/GetFileContents/feature.js +0 -10
- package/features/GetFileContents/feature.js.map +0 -1
- package/graphql/schema.d.ts +0 -1
- package/graphql/schema.js +0 -204
- package/graphql/schema.js.map +0 -1
- package/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p_reduce from "p-reduce";
|
|
2
2
|
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
4
|
+
class FileUploadModifierBuilder {
|
|
5
|
+
setFile(setter) {
|
|
6
|
+
this.fileSetters.push(setter);
|
|
7
|
+
}
|
|
8
|
+
execute(file) {
|
|
9
|
+
return p_reduce(this.fileSetters, async (file, setter)=>({
|
|
10
|
+
...file,
|
|
11
|
+
...await setter(file)
|
|
12
|
+
}), file);
|
|
13
|
+
}
|
|
14
|
+
constructor(){
|
|
15
|
+
this.fileSetters = [];
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
class FileUploadModifierPlugin extends Plugin {
|
|
19
|
+
static{
|
|
20
|
+
this.type = "fm.s3.uploadModifier";
|
|
21
|
+
}
|
|
22
|
+
constructor(cb){
|
|
23
|
+
super();
|
|
24
|
+
this.cb = cb;
|
|
25
|
+
}
|
|
26
|
+
execute(params) {
|
|
27
|
+
return this.cb(params);
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return file => modifier.execute(file);
|
|
30
|
+
const createFileUploadModifier = (cb)=>new FileUploadModifierPlugin(cb);
|
|
31
|
+
const FileUploadModifier = createAbstraction("FileUploadModifier");
|
|
32
|
+
const createModifierFromPlugins = (plugins = [])=>{
|
|
33
|
+
const modifier = new FileUploadModifierBuilder();
|
|
34
|
+
plugins.forEach((pl)=>pl.execute({
|
|
35
|
+
modifier
|
|
36
|
+
}));
|
|
37
|
+
return (file)=>modifier.execute(file);
|
|
37
38
|
};
|
|
39
|
+
export { FileUploadModifier, FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
|
|
38
40
|
|
|
39
41
|
//# sourceMappingURL=FileUploadModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/FileUploadModifier.js","sources":["../../src/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifierBuilder {\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: FileUploadModifierBuilder[\"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\n/**\n * DI multiple-abstraction for file-upload modifiers. Replaces the old\n * `context.plugins.byType(FileUploadModifierPlugin.type)` lookup in createFileNormalizerFromContext.\n * Extensions register modifiers via `container.registerInstance(FileUploadModifier, createFileUploadModifier(cb))`.\n */\nexport const FileUploadModifier = createAbstraction<FileUploadModifierPlugin>(\"FileUploadModifier\");\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 FileUploadModifierBuilder();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"names":["FileUploadModifierBuilder","setter","file","pReduce","FileUploadModifierPlugin","Plugin","cb","params","createFileUploadModifier","FileUploadModifier","createAbstraction","createModifierFromPlugins","plugins","modifier","pl"],"mappings":";;;AASA,MAAMA;IAGF,QAAQC,MAA0B,EAAQ;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAACA;IAC1B;IAEA,QAAQC,IAAgB,EAAE;QACtB,OAAOC,SACH,IAAI,CAAC,WAAW,EAChB,OAAOD,MAAMD,SAEF;gBAAE,GAAGC,IAAI;gBAAE,GAAI,MAAMD,OAAOC,KAAK;YAAE,IAE9CA;IAER;;aAfQ,WAAW,GAAyB,EAAE;;AAgBlD;AAQO,MAAME,iCAAiCC;;aACnB,IAAI,GAAG;;IAG9B,YAAYC,EAA8B,CAAE;QACxC,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,QAAQC,MAAwC,EAAE;QAC9C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAMO,MAAMC,2BAA2B,CAACF,KAC9B,IAAIF,yBAAyBE;AAQjC,MAAMG,qBAAqBC,kBAA4C;AAMvE,MAAMC,4BAA4B,CACrCC,UAAsC,EAAE;IAExC,MAAMC,WAAW,IAAIb;IACrBY,QAAQ,OAAO,CAACE,CAAAA,KAAMA,GAAG,OAAO,CAAC;YAAED;QAAS;IAE5C,OAAO,CAACX,OAAqBW,SAAS,OAAO,CAACX;AAClD"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FileNormalizer } from "./FileNormalizer.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { FileUploadModifier, createModifierFromPlugins } from "./FileUploadModifier.js";
|
|
3
|
+
const createFileNormalizerFromContext = (context)=>{
|
|
4
|
+
const modifierPlugins = context.container.resolveAll(FileUploadModifier);
|
|
5
|
+
return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
|
|
6
6
|
};
|
|
7
|
+
export { createFileNormalizerFromContext };
|
|
7
8
|
|
|
8
9
|
//# sourceMappingURL=createFileNormalizerFromContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/createFileNormalizerFromContext.js","sources":["../../src/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer.js\";\nimport { createModifierFromPlugins, FileUploadModifier } from \"~/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n // Modifiers are registered as DI instances (FileUploadModifier) — was\n // context.plugins.byType(FileUploadModifierPlugin.type).\n const modifierPlugins = context.container.resolveAll(FileUploadModifier);\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifier","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAIO,MAAMA,kCAAkC,CAACC;IAG5C,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,UAAU,CAACE;IAErD,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
|
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
import { S3Client, createPresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
2
|
import { validation } from "@webiny/validation";
|
|
3
3
|
const S3_BUCKET = process.env.S3_BUCKET;
|
|
4
|
-
const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// TODO @ts-refactor No need to log the error?
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export const getPresignedPostPayload = async (file, settings, tenantContext) => {
|
|
16
|
-
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
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}`;
|
|
20
|
-
const params = {
|
|
21
|
-
Key: storageKey,
|
|
22
|
-
Expires: 60,
|
|
23
|
-
Bucket: S3_BUCKET,
|
|
24
|
-
Conditions: [["content-length-range", uploadMinFileSize, uploadMaxFileSize]],
|
|
25
|
-
Fields: {
|
|
26
|
-
"Content-Type": file.type
|
|
4
|
+
const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776;
|
|
5
|
+
const sanitizeFileSizeValue = (value, defaultValue)=>{
|
|
6
|
+
try {
|
|
7
|
+
validation.validateSync(value, "required,numeric,gte:0");
|
|
8
|
+
return value;
|
|
9
|
+
} catch {
|
|
10
|
+
return defaultValue;
|
|
27
11
|
}
|
|
28
|
-
};
|
|
29
|
-
if (params.Key.startsWith("/")) {
|
|
30
|
-
params.Key = params.Key.slice(1);
|
|
31
|
-
}
|
|
32
|
-
const s3 = new S3Client();
|
|
33
|
-
const payload = await createPresignedPost(s3, params);
|
|
34
|
-
return {
|
|
35
|
-
data: payload,
|
|
36
|
-
file
|
|
37
|
-
};
|
|
38
12
|
};
|
|
13
|
+
const getPresignedPostPayload = async (file, settings, tenantContext)=>{
|
|
14
|
+
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
15
|
+
const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
|
|
16
|
+
const tenant = tenantContext.getTenant();
|
|
17
|
+
const storageKey = `tenants/${tenant.id}/files/${file.key}`;
|
|
18
|
+
const params = {
|
|
19
|
+
Key: storageKey,
|
|
20
|
+
Expires: 60,
|
|
21
|
+
Bucket: S3_BUCKET,
|
|
22
|
+
Conditions: [
|
|
23
|
+
[
|
|
24
|
+
"content-length-range",
|
|
25
|
+
uploadMinFileSize,
|
|
26
|
+
uploadMaxFileSize
|
|
27
|
+
]
|
|
28
|
+
],
|
|
29
|
+
Fields: {
|
|
30
|
+
"Content-Type": file.type
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
if (params.Key.startsWith("/")) params.Key = params.Key.slice(1);
|
|
34
|
+
const s3 = new S3Client();
|
|
35
|
+
const payload = await createPresignedPost(s3, params);
|
|
36
|
+
return {
|
|
37
|
+
data: payload,
|
|
38
|
+
file
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export { getPresignedPostPayload };
|
|
39
42
|
|
|
40
43
|
//# sourceMappingURL=getPresignedPostPayload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/getPresignedPostPayload.js","sources":["../../src/utils/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"],"names":["S3_BUCKET","process","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","getPresignedPostPayload","file","settings","tenantContext","uploadMinFileSize","uploadMaxFileSize","tenant","storageKey","params","s3","S3Client","payload","createPresignedPost"],"mappings":";;AAOA,MAAMA,YAAYC,QAAQ,GAAG,CAAC,SAAS;AACvC,MAAMC,+BAA+B;AAErC,MAAMC,wBAAwB,CAACC,OAAeC;IAC1C,IAAI;QACAC,WAAW,YAAY,CAACF,OAAO;QAC/B,OAAOA;IACX,EAAE,OAAM;QAEJ,OAAOC;IACX;AACJ;AAEO,MAAME,0BAA0B,OACnCC,MACAC,UACAC;IAEA,MAAMC,oBAAoBR,sBAAsBM,SAAS,iBAAiB,EAAE;IAC5E,MAAMG,oBAAoBT,sBACtBM,SAAS,iBAAiB,EAC1BP;IAGJ,MAAMW,SAASH,cAAc,SAAS;IACtC,MAAMI,aAAa,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAEL,KAAK,GAAG,EAAE;IAE3D,MAAMO,SAAS;QACX,KAAKD;QACL,SAAS;QACT,QAAQd;QACR,YAAY;YACR;gBAAC;gBAAwBW;gBAAmBC;aAAkB;SACjE;QACD,QAAQ;YACJ,gBAAgBJ,KAAK,IAAI;QAC7B;IACJ;IAEA,IAAIO,OAAO,GAAG,CAAC,UAAU,CAAC,MACtBA,OAAO,GAAG,GAAGA,OAAO,GAAG,CAAC,KAAK,CAAC;IAGlC,MAAMC,KAAK,IAAIC;IACf,MAAMC,UAAU,MAAMC,oBAAoBH,IAAID;IAE9C,OAAO;QACH,MAAMG;QACNV;IACJ;AACJ"}
|
package/utils/mimeTypes.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* This operation is not available via the `mime` package, so we create such an object ourselves.
|
|
7
|
-
*/
|
|
8
|
-
export const mimeTypes = {
|
|
9
|
-
...vendorTypes,
|
|
10
|
-
...standardTypes
|
|
1
|
+
import other from "mime/types/other.js";
|
|
2
|
+
import standard from "mime/types/standard.js";
|
|
3
|
+
const mimeTypes_mimeTypes = {
|
|
4
|
+
...other,
|
|
5
|
+
...standard
|
|
11
6
|
};
|
|
7
|
+
export { mimeTypes_mimeTypes as mimeTypes };
|
|
12
8
|
|
|
13
9
|
//# sourceMappingURL=mimeTypes.js.map
|
package/utils/mimeTypes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/mimeTypes.js","sources":["../../src/utils/mimeTypes.ts"],"sourcesContent":["import vendorTypes from \"mime/types/other.js\";\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"],"names":["mimeTypes","vendorTypes","standardTypes"],"mappings":";;AAOO,MAAMA,sBAAsC;IAC/C,GAAGC,KAAW;IACd,GAAGC,QAAa;AACpB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
-
declare const _default: (buffer: Buffer, preSignedPostPayload: PresignedPost) => Promise<Response>;
|
|
3
2
|
export default _default;
|
|
3
|
+
declare function _default(buffer: Buffer, preSignedPostPayload: PresignedPost): Promise<Response>;
|
package/utils/uploadFileToS3.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
formData.append(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const uploadFileToS3 = async (buffer, preSignedPostPayload)=>{
|
|
2
|
+
const formData = new FormData();
|
|
3
|
+
for (const [key, value] of Object.entries(preSignedPostPayload.fields))formData.append(key, value);
|
|
4
|
+
formData.append("file", new Blob([
|
|
5
|
+
Buffer.from(buffer)
|
|
6
|
+
]));
|
|
7
|
+
return fetch(preSignedPostPayload.url, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
body: formData
|
|
10
|
+
});
|
|
11
11
|
};
|
|
12
|
+
export default uploadFileToS3;
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=uploadFileToS3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/uploadFileToS3.js","sources":["../../src/utils/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"],"names":["buffer","preSignedPostPayload","formData","FormData","key","value","Object","Blob","Buffer","fetch"],"mappings":"AAEA,uBAAe,OAAOA,QAAgBC;IAClC,MAAMC,WAAW,IAAIC;IAErB,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACL,qBAAqB,MAAM,EACjEC,SAAS,MAAM,CAACE,KAAKC;IAGzBH,SAAS,MAAM,CAAC,QAAQ,IAAIK,KAAK;QAACC,OAAO,IAAI,CAACR;KAAQ;IAEtD,OAAOS,MAAMR,qBAAqB,GAAG,EAAE;QACnC,QAAQ;QACR,MAAMC;IACV;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["S3AssetResolver","S3OutputStrategy","S3ContentsReader","S3ErrorAssetReply","S3RedirectAssetReply","S3StreamAssetReply","SharpTransform","CallableContentsReader"],"sources":["index.ts"],"sourcesContent":["export { S3AssetResolver } from \"./s3/S3AssetResolver.js\";\nexport { S3OutputStrategy } from \"./s3/S3OutputStrategy.js\";\nexport { S3ContentsReader } from \"./s3/S3ContentsReader.js\";\nexport { S3ErrorAssetReply } from \"./s3/S3ErrorAssetReply.js\";\nexport { S3RedirectAssetReply } from \"./s3/S3RedirectAssetReply.js\";\nexport { S3StreamAssetReply } from \"./s3/S3StreamAssetReply.js\";\nexport { SharpTransform } from \"./s3/SharpTransform.js\";\nexport { CallableContentsReader } from \"./s3/transformation/CallableContentsReader.js\";\n"],"mappings":"AAAA,SAASA,eAAe;AACxB,SAASC,gBAAgB;AACzB,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAC1B,SAASC,oBAAoB;AAC7B,SAASC,kBAAkB;AAC3B,SAASC,cAAc;AACvB,SAASC,sBAAsB","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createThreatDetectionEventHandler.js\";\nexport * from \"./createThreatDetectionPluginLoader.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export type GuardDutyEvent = {\n scanResultDetails: {\n scanResultStatus:\n | \"UNSUPPORTED\"\n | \"FAILED\"\n | \"ACCESS_DENIED\"\n | \"THREATS_FOUND\"\n | \"NO_THREATS_FOUND\";\n };\n s3ObjectDetails: {\n bucketName: string;\n objectKey: string;\n };\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export type AssetDeliveryParams = {\n imageResizeWidths?: number[];\n /**\n * BE CAREFUL!\n * Setting this to more than 1 hour may cause your URLs to still expire before the desired expiration time.\n * @see https://repost.aws/knowledge-center/presigned-url-s3-bucket-expiration\n */\n presignedUrlTtl?: number;\n assetStreamingMaxSize?: number;\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
-
import { GetFileContentsUseCase } from "@webiny/api-file-manager/features/file/GetFileContents/index.js";
|
|
4
|
-
import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContents/index.js";
|
|
5
|
-
declare class GetFileContentsUseCaseImpl implements GetFileContentsUseCase.Interface {
|
|
6
|
-
private metadataReader;
|
|
7
|
-
constructor(keyValueStore: GlobalKeyValueStore.Interface);
|
|
8
|
-
execute(fileId: string): Promise<Result<FileContents, GetFileContentsUseCase.Error>>;
|
|
9
|
-
}
|
|
10
|
-
export declare const GetFileContentsUseCaseImplementation: typeof GetFileContentsUseCaseImpl & {
|
|
11
|
-
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContents/abstractions").IGetFileContentsUseCase>;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
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 { GetFileContentsUseCase } from "@webiny/api-file-manager/features/file/GetFileContents/index.js";
|
|
5
|
-
import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
|
|
6
|
-
import { MetadataReader } from "../WriteFileMetadata/MetadataReader.js";
|
|
7
|
-
class GetFileContentsUseCaseImpl {
|
|
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) {
|
|
14
|
-
return Result.fail(new FileNotFoundError(fileId));
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const s3 = new S3();
|
|
18
|
-
const bucket = String(process.env.S3_BUCKET);
|
|
19
|
-
const response = await s3.getObject({
|
|
20
|
-
Bucket: bucket,
|
|
21
|
-
Key: metadata.bucketKey
|
|
22
|
-
});
|
|
23
|
-
if (!response.Body) {
|
|
24
|
-
return Result.fail(new FileNotFoundError(fileId));
|
|
25
|
-
}
|
|
26
|
-
const buffer = Buffer.from(await response.Body.transformToByteArray());
|
|
27
|
-
return Result.ok({
|
|
28
|
-
buffer,
|
|
29
|
-
contentType: metadata.contentType
|
|
30
|
-
});
|
|
31
|
-
} catch (error) {
|
|
32
|
-
return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export const GetFileContentsUseCaseImplementation = GetFileContentsUseCase.createImplementation({
|
|
37
|
-
implementation: GetFileContentsUseCaseImpl,
|
|
38
|
-
dependencies: [GlobalKeyValueStore]
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=GetFileContentsUseCase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Result","S3","GlobalKeyValueStore","GetFileContentsUseCase","FileNotFoundError","FilePersistenceError","MetadataReader","GetFileContentsUseCaseImpl","constructor","keyValueStore","metadataReader","execute","fileId","metadata","read","fail","s3","bucket","String","process","env","S3_BUCKET","response","getObject","Bucket","Key","bucketKey","Body","buffer","Buffer","from","transformToByteArray","ok","contentType","error","Error","GetFileContentsUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["GetFileContentsUseCase.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 { GetFileContentsUseCase } from \"@webiny/api-file-manager/features/file/GetFileContents/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContents/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 GetFileContentsUseCaseImpl implements GetFileContentsUseCase.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, GetFileContentsUseCase.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 GetFileContentsUseCaseImplementation = GetFileContentsUseCase.createImplementation({\n implementation: GetFileContentsUseCaseImpl,\n dependencies: [GlobalKeyValueStore]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,EAAE,QAAQ,oCAAoC;AACvD,SAASC,mBAAmB,QAAQ,kDAAkD;AACtF,SAASC,sBAAsB,QAAQ,iEAAiE;AAExG,SACIC,iBAAiB,EACjBC,oBAAoB,QACjB,gDAAgD;AACvD,SAASC,cAAc;AAEvB,MAAMC,0BAA0B,CAA6C;EAGzEC,WAAWA,CAACC,aAA4C,EAAE;IACtD,IAAI,CAACC,cAAc,GAAG,IAAIJ,cAAc,CAACG,aAAa,CAAC;EAC3D;EAEA,MAAME,OAAOA,CAACC,MAAc,EAA+D;IACvF,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACH,cAAc,CAACI,IAAI,CAACF,MAAM,CAAC;IACvD,IAAI,CAACC,QAAQ,EAAE;MACX,OAAOb,MAAM,CAACe,IAAI,CAAC,IAAIX,iBAAiB,CAACQ,MAAM,CAAC,CAAC;IACrD;IAEA,IAAI;MACA,MAAMI,EAAE,GAAG,IAAIf,EAAE,CAAC,CAAC;MACnB,MAAMgB,MAAM,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,SAAS,CAAC;MAC5C,MAAMC,QAAQ,GAAG,MAAMN,EAAE,CAACO,SAAS,CAAC;QAAEC,MAAM,EAAEP,MAAM;QAAEQ,GAAG,EAAEZ,QAAQ,CAACa;MAAU,CAAC,CAAC;MAEhF,IAAI,CAACJ,QAAQ,CAACK,IAAI,EAAE;QAChB,OAAO3B,MAAM,CAACe,IAAI,CAAC,IAAIX,iBAAiB,CAACQ,MAAM,CAAC,CAAC;MACrD;MAEA,MAAMgB,MAAM,GAAGC,MAAM,CAACC,IAAI,CAAC,MAAMR,QAAQ,CAACK,IAAI,CAACI,oBAAoB,CAAC,CAAC,CAAC;MACtE,OAAO/B,MAAM,CAACgC,EAAE,CAAC;QAAEJ,MAAM;QAAEK,WAAW,EAAEpB,QAAQ,CAACoB;MAAY,CAAC,CAAC;IACnE,CAAC,CAAC,OAAOC,KAAK,EAAE;MACZ,OAAOlC,MAAM,CAACe,IAAI,CACd,IAAIV,oBAAoB,CAAC6B,KAAK,YAAYC,KAAK,GAAGD,KAAK,GAAG,IAAIC,KAAK,CAACjB,MAAM,CAACgB,KAAK,CAAC,CAAC,CACtF,CAAC;IACL;EACJ;AACJ;AAEA,OAAO,MAAME,oCAAoC,GAAGjC,sBAAsB,CAACkC,oBAAoB,CAAC;EAC5FC,cAAc,EAAE/B,0BAA0B;EAC1CgC,YAAY,EAAE,CAACrC,mBAAmB;AACtC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api";
|
|
2
|
-
import { GetFileContentsUseCaseImplementation } from "./GetFileContentsUseCase.js";
|
|
3
|
-
export const GetFileContentsFeature = createFeature({
|
|
4
|
-
name: "FileManagerS3/GetFileContents",
|
|
5
|
-
register(container) {
|
|
6
|
-
container.register(GetFileContentsUseCaseImplementation);
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","GetFileContentsUseCaseImplementation","GetFileContentsFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsUseCaseImplementation } from \"./GetFileContentsUseCase.js\";\n\nexport const GetFileContentsFeature = createFeature({\n name: \"FileManagerS3/GetFileContents\",\n register(container) {\n container.register(GetFileContentsUseCaseImplementation);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,oCAAoC;AAE7C,OAAO,MAAMC,sBAAsB,GAAGF,aAAa,CAAC;EAChDG,IAAI,EAAE,+BAA+B;EACrCC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,oCAAoC,CAAC;EAC5D;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/graphql/schema.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createS3GraphQLSchema: () => import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("@webiny/api/types.js").Context>;
|
package/graphql/schema.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import pMap from "p-map";
|
|
2
|
-
import { createGraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
3
|
-
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
-
import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
5
|
-
import { ErrorResponse, Response } from "@webiny/handler-graphql/responses.js";
|
|
6
|
-
import { getPresignedPostPayload } from "../utils/getPresignedPostPayload.js";
|
|
7
|
-
import { checkPermissions } from "./checkPermissions.js";
|
|
8
|
-
import { CreateMultiPartUploadUseCase } from "../multiPartUpload/CreateMultiPartUploadUseCase.js";
|
|
9
|
-
import { CompleteMultiPartUploadUseCase } from "../multiPartUpload/CompleteMultiPartUploadUseCase.js";
|
|
10
|
-
import { createFileNormalizerFromContext } from "../utils/createFileNormalizerFromContext.js";
|
|
11
|
-
import { GetSettingsUseCase } from "@webiny/api-file-manager/features/settings/GetSettings/abstractions.js";
|
|
12
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
13
|
-
export const createS3GraphQLSchema = () => {
|
|
14
|
-
return createGraphQLSchemaPlugin({
|
|
15
|
-
typeDefs: /* GraphQL */`
|
|
16
|
-
type UploadFileResponseDataFile {
|
|
17
|
-
id: ID!
|
|
18
|
-
name: String!
|
|
19
|
-
type: String!
|
|
20
|
-
size: Long!
|
|
21
|
-
key: String!
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
input PreSignedPostPayloadInput {
|
|
25
|
-
id: ID
|
|
26
|
-
name: String!
|
|
27
|
-
type: String!
|
|
28
|
-
size: Long!
|
|
29
|
-
key: String
|
|
30
|
-
keyPrefix: String
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type GetPreSignedPostPayloadResponseDataFile {
|
|
34
|
-
id: ID!
|
|
35
|
-
name: String!
|
|
36
|
-
type: String!
|
|
37
|
-
size: Long!
|
|
38
|
-
key: String!
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type GetPreSignedPostPayloadResponseData {
|
|
42
|
-
# Contains data that is necessary for initiating a file upload.
|
|
43
|
-
data: JSON!
|
|
44
|
-
file: UploadFileResponseDataFile!
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type GetPreSignedPostPayloadResponse {
|
|
48
|
-
error: FmError
|
|
49
|
-
data: GetPreSignedPostPayloadResponseData
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type MultiPartUploadFilePart {
|
|
53
|
-
partNumber: Int!
|
|
54
|
-
url: String!
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type CreateMultiPartUploadResponseData {
|
|
58
|
-
file: GetPreSignedPostPayloadResponseDataFile!
|
|
59
|
-
uploadId: String!
|
|
60
|
-
parts: [MultiPartUploadFilePart!]!
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
type CompleteMultiPartUploadResponse {
|
|
64
|
-
data: Boolean
|
|
65
|
-
error: FmError
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type GetPreSignedPostPayloadsResponse {
|
|
69
|
-
error: FmError
|
|
70
|
-
data: [GetPreSignedPostPayloadResponseData!]!
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
extend type FmQuery {
|
|
74
|
-
getPreSignedPostPayload(
|
|
75
|
-
data: PreSignedPostPayloadInput!
|
|
76
|
-
): GetPreSignedPostPayloadResponse
|
|
77
|
-
getPreSignedPostPayloads(
|
|
78
|
-
data: [PreSignedPostPayloadInput]!
|
|
79
|
-
): GetPreSignedPostPayloadsResponse
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
type CreateMultiPartUploadResponse {
|
|
83
|
-
data: CreateMultiPartUploadResponseData
|
|
84
|
-
error: FmError
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
input MultiPartUploadFilePartInput {
|
|
88
|
-
partNumber: Int!
|
|
89
|
-
etag: String!
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
extend type FmMutation {
|
|
93
|
-
createMultiPartUpload(
|
|
94
|
-
data: PreSignedPostPayloadInput!
|
|
95
|
-
numberOfParts: Number!
|
|
96
|
-
): CreateMultiPartUploadResponse
|
|
97
|
-
|
|
98
|
-
completeMultiPartUpload(
|
|
99
|
-
fileKey: String!
|
|
100
|
-
uploadId: String!
|
|
101
|
-
): CompleteMultiPartUploadResponse
|
|
102
|
-
}
|
|
103
|
-
`,
|
|
104
|
-
resolvers: {
|
|
105
|
-
FmQuery: {
|
|
106
|
-
getPreSignedPostPayload: async (_, args, context) => {
|
|
107
|
-
const identityContext = context.container.resolve(IdentityContext);
|
|
108
|
-
const getSettings = context.container.resolve(GetSettingsUseCase);
|
|
109
|
-
try {
|
|
110
|
-
await checkPermissions(identityContext, {
|
|
111
|
-
rwd: "w"
|
|
112
|
-
});
|
|
113
|
-
const data = args.data;
|
|
114
|
-
const settingsResult = await getSettings.execute();
|
|
115
|
-
const settings = settingsResult.value;
|
|
116
|
-
const normalizer = createFileNormalizerFromContext(context);
|
|
117
|
-
const presignedPayload = await getPresignedPostPayload(await normalizer.normalizeFile(data), settings, context.container.resolve(TenantContext));
|
|
118
|
-
return new Response(presignedPayload);
|
|
119
|
-
} catch (e) {
|
|
120
|
-
return new ErrorResponse({
|
|
121
|
-
message: e.message,
|
|
122
|
-
code: e.code,
|
|
123
|
-
data: e.data
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
getPreSignedPostPayloads: async (_, args, context) => {
|
|
128
|
-
const identityContext = context.container.resolve(IdentityContext);
|
|
129
|
-
const getSettings = context.container.resolve(GetSettingsUseCase);
|
|
130
|
-
await checkPermissions(identityContext, {
|
|
131
|
-
rwd: "w"
|
|
132
|
-
});
|
|
133
|
-
const files = args.data;
|
|
134
|
-
try {
|
|
135
|
-
const settingsResult = await getSettings.execute();
|
|
136
|
-
const settings = settingsResult.value;
|
|
137
|
-
const normalizer = createFileNormalizerFromContext(context);
|
|
138
|
-
const presignedPayloads = await pMap(files, async data => {
|
|
139
|
-
return getPresignedPostPayload(await normalizer.normalizeFile(data), settings, context.container.resolve(TenantContext));
|
|
140
|
-
});
|
|
141
|
-
return new Response(presignedPayloads);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
return new ErrorResponse({
|
|
144
|
-
message: e.message,
|
|
145
|
-
code: e.code,
|
|
146
|
-
data: e.data
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
FmMutation: {
|
|
152
|
-
createMultiPartUpload: async (_, args, context) => {
|
|
153
|
-
const identityContext = context.container.resolve(IdentityContext);
|
|
154
|
-
await checkPermissions(identityContext, {
|
|
155
|
-
rwd: "w"
|
|
156
|
-
});
|
|
157
|
-
const s3Client = new S3({
|
|
158
|
-
region: process.env.AWS_REGION
|
|
159
|
-
});
|
|
160
|
-
try {
|
|
161
|
-
const useCase = new CreateMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
162
|
-
const normalizer = createFileNormalizerFromContext(context);
|
|
163
|
-
const multiPartUpload = await useCase.execute({
|
|
164
|
-
file: await normalizer.normalizeFile(args.data),
|
|
165
|
-
numberOfParts: args.numberOfParts
|
|
166
|
-
});
|
|
167
|
-
return new Response(multiPartUpload);
|
|
168
|
-
} catch (e) {
|
|
169
|
-
return new ErrorResponse({
|
|
170
|
-
message: e.message,
|
|
171
|
-
code: e.code,
|
|
172
|
-
data: e.data
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
completeMultiPartUpload: async (_, args, context) => {
|
|
177
|
-
const identityContext = context.container.resolve(IdentityContext);
|
|
178
|
-
await checkPermissions(identityContext, {
|
|
179
|
-
rwd: "w"
|
|
180
|
-
});
|
|
181
|
-
const s3Client = new S3({
|
|
182
|
-
region: process.env.AWS_REGION
|
|
183
|
-
});
|
|
184
|
-
try {
|
|
185
|
-
const useCase = new CompleteMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
186
|
-
await useCase.execute({
|
|
187
|
-
fileKey: args.fileKey,
|
|
188
|
-
uploadId: args.uploadId
|
|
189
|
-
});
|
|
190
|
-
return new Response(true);
|
|
191
|
-
} catch (e) {
|
|
192
|
-
return new ErrorResponse({
|
|
193
|
-
message: e.message,
|
|
194
|
-
code: e.code,
|
|
195
|
-
data: e.data
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
//# sourceMappingURL=schema.js.map
|