@webiny/api-file-manager-s3 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7f63ea0744
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/index.js +0 -5
- package/index.js.map +1 -1
- package/package.json +9 -9
- package/plugins/fileStorageS3.js +4 -17
- package/plugins/fileStorageS3.js.map +1 -1
- package/plugins/graphqlFileStorageS3.js +1 -19
- package/plugins/graphqlFileStorageS3.js.map +1 -1
- package/utils/getPresignedPostPayload.js +2 -18
- package/utils/getPresignedPostPayload.js.map +1 -1
- package/utils/uploadFileToS3.js +6 -11
- package/utils/uploadFileToS3.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _graphqlFileStorageS = _interopRequireDefault(require("./plugins/graphqlFileStorageS3"));
|
|
11
|
-
|
|
12
9
|
var _fileStorageS = _interopRequireDefault(require("./plugins/fileStorageS3"));
|
|
13
|
-
|
|
14
10
|
var _default = () => [(0, _fileStorageS.default)(), _graphqlFileStorageS.default];
|
|
15
|
-
|
|
16
11
|
exports.default = _default;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fileStorageS3","graphqlFileStorageS3"],"sources":["index.ts"],"sourcesContent":["import graphqlFileStorageS3 from \"./plugins/graphqlFileStorageS3\";\nimport fileStorageS3 from \"./plugins/fileStorageS3\";\n\nexport default () => [fileStorageS3(), graphqlFileStorageS3];\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["fileStorageS3","graphqlFileStorageS3"],"sources":["index.ts"],"sourcesContent":["import graphqlFileStorageS3 from \"./plugins/graphqlFileStorageS3\";\nimport fileStorageS3 from \"./plugins/fileStorageS3\";\n\nexport default () => [fileStorageS3(), graphqlFileStorageS3];\n"],"mappings":";;;;;;;AAAA;AACA;AAAoD,eAErC,MAAM,CAAC,IAAAA,qBAAa,GAAE,EAAEC,4BAAoB,CAAC;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-s3",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.7f63ea0744",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/api-file-manager": "0.0.0-unstable.
|
|
14
|
-
"@webiny/error": "0.0.0-unstable.
|
|
15
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
16
|
-
"@webiny/validation": "0.0.0-unstable.
|
|
13
|
+
"@webiny/api-file-manager": "0.0.0-unstable.7f63ea0744",
|
|
14
|
+
"@webiny/error": "0.0.0-unstable.7f63ea0744",
|
|
15
|
+
"@webiny/handler-graphql": "0.0.0-unstable.7f63ea0744",
|
|
16
|
+
"@webiny/validation": "0.0.0-unstable.7f63ea0744",
|
|
17
17
|
"form-data": "4.0.0",
|
|
18
|
-
"node-fetch": "2.6.
|
|
18
|
+
"node-fetch": "2.6.9",
|
|
19
19
|
"sanitize-filename": "1.6.3",
|
|
20
20
|
"uniqid": "5.4.0"
|
|
21
21
|
},
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@babel/cli": "^7.19.3",
|
|
24
24
|
"@babel/core": "^7.19.3",
|
|
25
25
|
"@types/node-fetch": "^2.6.1",
|
|
26
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
27
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
26
|
+
"@webiny/cli": "^0.0.0-unstable.7f63ea0744",
|
|
27
|
+
"@webiny/project-utils": "^0.0.0-unstable.7f63ea0744",
|
|
28
28
|
"rimraf": "^3.0.2",
|
|
29
29
|
"typescript": "4.7.4"
|
|
30
30
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"build": "yarn webiny run build",
|
|
37
37
|
"watch": "yarn webiny run watch"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "7f63ea0744c9e31977e5dabb95538d22b4db585c"
|
|
40
40
|
}
|
package/plugins/fileStorageS3.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
-
|
|
12
9
|
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
13
|
-
|
|
14
10
|
var _getPresignedPostPayload = _interopRequireDefault(require("../utils/getPresignedPostPayload"));
|
|
15
|
-
|
|
16
11
|
var _uploadFileToS = _interopRequireDefault(require("../utils/uploadFileToS3"));
|
|
17
|
-
|
|
18
12
|
var _FilePhysicalStoragePlugin = require("@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin");
|
|
19
|
-
|
|
20
13
|
const _excluded = ["settings", "buffer"];
|
|
21
14
|
const S3_BUCKET = process.env.S3_BUCKET;
|
|
22
|
-
|
|
23
15
|
var _default = () => {
|
|
24
16
|
/**
|
|
25
17
|
* We need to extends the type for FilePhysicalStoragePlugin.
|
|
@@ -28,20 +20,18 @@ var _default = () => {
|
|
|
28
20
|
return new _FilePhysicalStoragePlugin.FilePhysicalStoragePlugin({
|
|
29
21
|
upload: async params => {
|
|
30
22
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
settings,
|
|
24
|
+
buffer
|
|
25
|
+
} = params,
|
|
26
|
+
data = (0, _objectWithoutProperties2.default)(params, _excluded);
|
|
35
27
|
const {
|
|
36
28
|
data: preSignedPostPayload,
|
|
37
29
|
file
|
|
38
30
|
} = await (0, _getPresignedPostPayload.default)(data, settings);
|
|
39
31
|
const response = await (0, _uploadFileToS.default)(buffer, preSignedPostPayload);
|
|
40
|
-
|
|
41
32
|
if (!response.ok) {
|
|
42
33
|
throw Error("Unable to upload file.");
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
return {
|
|
46
36
|
data: preSignedPostPayload,
|
|
47
37
|
file
|
|
@@ -52,11 +42,9 @@ var _default = () => {
|
|
|
52
42
|
key
|
|
53
43
|
} = params;
|
|
54
44
|
const s3 = new _s.default();
|
|
55
|
-
|
|
56
45
|
if (!key || !S3_BUCKET) {
|
|
57
46
|
return;
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
await s3.deleteObject({
|
|
61
49
|
Bucket: S3_BUCKET,
|
|
62
50
|
Key: key
|
|
@@ -64,5 +52,4 @@ var _default = () => {
|
|
|
64
52
|
}
|
|
65
53
|
});
|
|
66
54
|
};
|
|
67
|
-
|
|
68
55
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3_BUCKET","process","env","FilePhysicalStoragePlugin","upload","params","settings","buffer","data","preSignedPostPayload","file","getPresignedPostPayload","response","uploadFileToS3","ok","Error","delete","key","s3","S3","deleteObject","Bucket","Key","promise"],"sources":["fileStorageS3.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport uploadFileToS3 from \"../utils/uploadFileToS3\";\nimport {\n FilePhysicalStoragePlugin,\n FilePhysicalStoragePluginUploadParams\n} from \"@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin\";\nimport { PresignedPostPayloadData } from \"~/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\n\nexport interface S3FilePhysicalStoragePluginUploadParams\n extends FilePhysicalStoragePluginUploadParams,\n PresignedPostPayloadData {}\n\nexport default (): FilePhysicalStoragePlugin => {\n /**\n * We need to extends the type for FilePhysicalStoragePlugin.\n * Otherwise the getPresignedPostPayload does not know it has all required values in params.\n */\n return new FilePhysicalStoragePlugin<S3FilePhysicalStoragePluginUploadParams>({\n upload: async params => {\n const { settings, buffer, ...data } = params;\n\n const { data: preSignedPostPayload, file } = await getPresignedPostPayload(\n data,\n settings\n );\n\n const response = await uploadFileToS3(buffer, preSignedPostPayload);\n if (!response.ok) {\n throw Error(\"Unable to upload file.\");\n }\n\n return {\n data: preSignedPostPayload,\n file\n };\n },\n delete: async params => {\n const { key } = params;\n const s3 = new S3();\n\n if (!key || !S3_BUCKET) {\n return;\n }\n\n await s3\n .deleteObject({\n Bucket: S3_BUCKET,\n Key: key\n })\n .promise();\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["S3_BUCKET","process","env","FilePhysicalStoragePlugin","upload","params","settings","buffer","data","preSignedPostPayload","file","getPresignedPostPayload","response","uploadFileToS3","ok","Error","delete","key","s3","S3","deleteObject","Bucket","Key","promise"],"sources":["fileStorageS3.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport uploadFileToS3 from \"../utils/uploadFileToS3\";\nimport {\n FilePhysicalStoragePlugin,\n FilePhysicalStoragePluginUploadParams\n} from \"@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin\";\nimport { PresignedPostPayloadData } from \"~/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\n\nexport interface S3FilePhysicalStoragePluginUploadParams\n extends FilePhysicalStoragePluginUploadParams,\n PresignedPostPayloadData {}\n\nexport default (): FilePhysicalStoragePlugin => {\n /**\n * We need to extends the type for FilePhysicalStoragePlugin.\n * Otherwise the getPresignedPostPayload does not know it has all required values in params.\n */\n return new FilePhysicalStoragePlugin<S3FilePhysicalStoragePluginUploadParams>({\n upload: async params => {\n const { settings, buffer, ...data } = params;\n\n const { data: preSignedPostPayload, file } = await getPresignedPostPayload(\n data,\n settings\n );\n\n const response = await uploadFileToS3(buffer, preSignedPostPayload);\n if (!response.ok) {\n throw Error(\"Unable to upload file.\");\n }\n\n return {\n data: preSignedPostPayload,\n file\n };\n },\n delete: async params => {\n const { key } = params;\n const s3 = new S3();\n\n if (!key || !S3_BUCKET) {\n return;\n }\n\n await s3\n .deleteObject({\n Bucket: S3_BUCKET,\n Key: key\n })\n .promise();\n }\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAGgF;AAGhF,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AAAC,eAMzB,MAAiC;EAC5C;AACJ;AACA;AACA;EACI,OAAO,IAAIG,oDAAyB,CAA0C;IAC1EC,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;UAAEC,QAAQ;UAAEC;QAAgB,CAAC,GAAGF,MAAM;QAAfG,IAAI,0CAAKH,MAAM;MAE5C,MAAM;QAAEG,IAAI,EAAEC,oBAAoB;QAAEC;MAAK,CAAC,GAAG,MAAM,IAAAC,gCAAuB,EACtEH,IAAI,EACJF,QAAQ,CACX;MAED,MAAMM,QAAQ,GAAG,MAAM,IAAAC,sBAAc,EAACN,MAAM,EAAEE,oBAAoB,CAAC;MACnE,IAAI,CAACG,QAAQ,CAACE,EAAE,EAAE;QACd,MAAMC,KAAK,CAAC,wBAAwB,CAAC;MACzC;MAEA,OAAO;QACHP,IAAI,EAAEC,oBAAoB;QAC1BC;MACJ,CAAC;IACL,CAAC;IACDM,MAAM,EAAE,MAAMX,MAAM,IAAI;MACpB,MAAM;QAAEY;MAAI,CAAC,GAAGZ,MAAM;MACtB,MAAMa,EAAE,GAAG,IAAIC,UAAE,EAAE;MAEnB,IAAI,CAACF,GAAG,IAAI,CAACjB,SAAS,EAAE;QACpB;MACJ;MAEA,MAAMkB,EAAE,CACHE,YAAY,CAAC;QACVC,MAAM,EAAErB,SAAS;QACjBsB,GAAG,EAAEL;MACT,CAAC,CAAC,CACDM,OAAO,EAAE;IAClB;EACJ,CAAC,CAAC;AACN,CAAC;AAAA"}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _responses = require("@webiny/handler-graphql/responses");
|
|
11
|
-
|
|
12
9
|
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-file-manager/plugins/crud/utils/checkBasePermissions"));
|
|
13
|
-
|
|
14
10
|
var _getPresignedPostPayload = _interopRequireDefault(require("../utils/getPresignedPostPayload"));
|
|
15
|
-
|
|
16
11
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
17
|
-
|
|
18
12
|
const BATCH_UPLOAD_MAX_FILES = 20;
|
|
19
13
|
const plugin = {
|
|
20
14
|
type: "graphql-schema",
|
|
21
15
|
name: "graphql-schema-api-file-manager-s3",
|
|
22
16
|
schema: {
|
|
23
|
-
typeDefs:
|
|
24
|
-
/* GraphQL */
|
|
25
|
-
`
|
|
17
|
+
typeDefs: /* GraphQL */`
|
|
26
18
|
input PreSignedPostPayloadInput {
|
|
27
19
|
name: String!
|
|
28
20
|
type: String!
|
|
@@ -72,13 +64,11 @@ const plugin = {
|
|
|
72
64
|
data
|
|
73
65
|
} = args;
|
|
74
66
|
const settings = await context.fileManager.settings.getSettings();
|
|
75
|
-
|
|
76
67
|
if (!settings) {
|
|
77
68
|
throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_SETTINGS_ERROR", {
|
|
78
69
|
file: data
|
|
79
70
|
});
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
const response = await (0, _getPresignedPostPayload.default)(data, settings);
|
|
83
73
|
return new _responses.Response(response);
|
|
84
74
|
} catch (e) {
|
|
@@ -96,43 +86,35 @@ const plugin = {
|
|
|
96
86
|
const {
|
|
97
87
|
data: files
|
|
98
88
|
} = args;
|
|
99
|
-
|
|
100
89
|
if (!Array.isArray(files)) {
|
|
101
90
|
return new _responses.ErrorResponse({
|
|
102
91
|
code: "UPLOAD_FILES_NON_ARRAY",
|
|
103
92
|
message: `"data" argument must be an array.`
|
|
104
93
|
});
|
|
105
94
|
}
|
|
106
|
-
|
|
107
95
|
if (files.length === 0) {
|
|
108
96
|
return new _responses.ErrorResponse({
|
|
109
97
|
code: "UPLOAD_FILES_MIN_FILES",
|
|
110
98
|
message: `"data" argument must contain at least one file.`
|
|
111
99
|
});
|
|
112
100
|
}
|
|
113
|
-
|
|
114
101
|
if (files.length > BATCH_UPLOAD_MAX_FILES) {
|
|
115
102
|
return new _responses.ErrorResponse({
|
|
116
103
|
code: "UPLOAD_FILES_MAX_FILES",
|
|
117
104
|
message: `"data" argument must not contain more than ${BATCH_UPLOAD_MAX_FILES} files.`
|
|
118
105
|
});
|
|
119
106
|
}
|
|
120
|
-
|
|
121
107
|
try {
|
|
122
108
|
const settings = await context.fileManager.settings.getSettings();
|
|
123
|
-
|
|
124
109
|
if (!settings) {
|
|
125
110
|
throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_SETTINGS_ERROR", {
|
|
126
111
|
files
|
|
127
112
|
});
|
|
128
113
|
}
|
|
129
|
-
|
|
130
114
|
const promises = [];
|
|
131
|
-
|
|
132
115
|
for (const item of files) {
|
|
133
116
|
promises.push((0, _getPresignedPostPayload.default)(item, settings));
|
|
134
117
|
}
|
|
135
|
-
|
|
136
118
|
return new _responses.Response(await Promise.all(promises));
|
|
137
119
|
} catch (e) {
|
|
138
120
|
return new _responses.ErrorResponse({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BATCH_UPLOAD_MAX_FILES","plugin","type","name","schema","typeDefs","resolvers","FmQuery","getPreSignedPostPayload","_","args","context","checkBasePermissions","rwd","data","settings","fileManager","getSettings","WebinyError","file","response","getPresignedPostPayload","Response","e","ErrorResponse","message","code","getPreSignedPostPayloads","files","Array","isArray","length","promises","item","push","Promise","all"],"sources":["graphqlFileStorageS3.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql/responses\";\nimport checkBasePermissions from \"@webiny/api-file-manager/plugins/crud/utils/checkBasePermissions\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport WebinyError from \"@webiny/error\";\n\nconst BATCH_UPLOAD_MAX_FILES = 20;\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n name: \"graphql-schema-api-file-manager-s3\",\n schema: {\n typeDefs: /* GraphQL */ `\n input PreSignedPostPayloadInput {\n name: String!\n type: String!\n size: Int!\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type GetPreSignedPostPayloadResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type GetPreSignedPostPayloadResponse {\n error: FileError\n data: GetPreSignedPostPayloadResponseData\n }\n\n type GetPreSignedPostPayloadsResponse {\n error: FileError\n data: [GetPreSignedPostPayloadResponseData]!\n }\n\n extend type FmQuery {\n getPreSignedPostPayload(\n data: PreSignedPostPayloadInput!\n ): GetPreSignedPostPayloadResponse\n getPreSignedPostPayloads(\n data: [PreSignedPostPayloadInput]!\n ): GetPreSignedPostPayloadsResponse\n }\n `,\n resolvers: {\n FmQuery: {\n getPreSignedPostPayload: async (_, args: any, context) => {\n try {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data } = args;\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n file: data\n }\n );\n }\n const response = await getPresignedPostPayload(data, settings);\n\n return new Response(response);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n },\n getPreSignedPostPayloads: async (_, args: any, context) => {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data: files } = args;\n if (!Array.isArray(files)) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_NON_ARRAY\",\n message: `\"data\" argument must be an array.`\n });\n }\n\n if (files.length === 0) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MIN_FILES\",\n message: `\"data\" argument must contain at least one file.`\n });\n }\n\n if (files.length > BATCH_UPLOAD_MAX_FILES) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MAX_FILES\",\n message: `\"data\" argument must not contain more than ${BATCH_UPLOAD_MAX_FILES} files.`\n });\n }\n\n try {\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n files\n }\n );\n }\n\n const promises = [];\n for (const item of files) {\n promises.push(getPresignedPostPayload(item, settings));\n }\n\n return new Response(await Promise.all(promises));\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["BATCH_UPLOAD_MAX_FILES","plugin","type","name","schema","typeDefs","resolvers","FmQuery","getPreSignedPostPayload","_","args","context","checkBasePermissions","rwd","data","settings","fileManager","getSettings","WebinyError","file","response","getPresignedPostPayload","Response","e","ErrorResponse","message","code","getPreSignedPostPayloads","files","Array","isArray","length","promises","item","push","Promise","all"],"sources":["graphqlFileStorageS3.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql/responses\";\nimport checkBasePermissions from \"@webiny/api-file-manager/plugins/crud/utils/checkBasePermissions\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport WebinyError from \"@webiny/error\";\n\nconst BATCH_UPLOAD_MAX_FILES = 20;\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n name: \"graphql-schema-api-file-manager-s3\",\n schema: {\n typeDefs: /* GraphQL */ `\n input PreSignedPostPayloadInput {\n name: String!\n type: String!\n size: Int!\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type GetPreSignedPostPayloadResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type GetPreSignedPostPayloadResponse {\n error: FileError\n data: GetPreSignedPostPayloadResponseData\n }\n\n type GetPreSignedPostPayloadsResponse {\n error: FileError\n data: [GetPreSignedPostPayloadResponseData]!\n }\n\n extend type FmQuery {\n getPreSignedPostPayload(\n data: PreSignedPostPayloadInput!\n ): GetPreSignedPostPayloadResponse\n getPreSignedPostPayloads(\n data: [PreSignedPostPayloadInput]!\n ): GetPreSignedPostPayloadsResponse\n }\n `,\n resolvers: {\n FmQuery: {\n getPreSignedPostPayload: async (_, args: any, context) => {\n try {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data } = args;\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n file: data\n }\n );\n }\n const response = await getPresignedPostPayload(data, settings);\n\n return new Response(response);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n },\n getPreSignedPostPayloads: async (_, args: any, context) => {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data: files } = args;\n if (!Array.isArray(files)) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_NON_ARRAY\",\n message: `\"data\" argument must be an array.`\n });\n }\n\n if (files.length === 0) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MIN_FILES\",\n message: `\"data\" argument must contain at least one file.`\n });\n }\n\n if (files.length > BATCH_UPLOAD_MAX_FILES) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MAX_FILES\",\n message: `\"data\" argument must not contain more than ${BATCH_UPLOAD_MAX_FILES} files.`\n });\n }\n\n try {\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n files\n }\n );\n }\n\n const promises = [];\n for (const item of files) {\n promises.push(getPresignedPostPayload(item, settings));\n }\n\n return new Response(await Promise.all(promises));\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":"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"}
|
|
@@ -1,58 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _uniqid = _interopRequireDefault(require("uniqid"));
|
|
11
|
-
|
|
12
9
|
var _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
|
|
13
|
-
|
|
14
10
|
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
15
|
-
|
|
16
11
|
var _validation = require("@webiny/validation");
|
|
17
|
-
|
|
18
12
|
const S3_BUCKET = process.env.S3_BUCKET;
|
|
19
13
|
const UPLOAD_MAX_FILE_SIZE_DEFAULT = 26214400; // 25MB
|
|
20
14
|
|
|
21
15
|
const sanitizeFileSizeValue = (value, defaultValue) => {
|
|
22
16
|
try {
|
|
23
17
|
_validation.validation.validateSync(value, "required,numeric,gte:0");
|
|
24
|
-
|
|
25
18
|
return value;
|
|
26
19
|
} catch (e) {
|
|
27
20
|
// TODO @ts-refactor No need to log the error?
|
|
28
21
|
return defaultValue;
|
|
29
22
|
}
|
|
30
23
|
};
|
|
31
|
-
|
|
32
24
|
var _default = async (data, settings) => {
|
|
33
25
|
// If type is missing, let's use the default "application/octet-stream" type,
|
|
34
26
|
// which is also the default type that the Amazon S3 would use.
|
|
35
27
|
if (!data.type) {
|
|
36
28
|
data.type = "application/octet-stream";
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
const contentType = data.type;
|
|
40
|
-
|
|
41
31
|
if (!contentType) {
|
|
42
32
|
throw Error(`File's content type could not be resolved.`);
|
|
43
33
|
}
|
|
44
|
-
|
|
45
34
|
let key = (0, _sanitizeFilename.default)(data.name);
|
|
46
|
-
|
|
47
35
|
if (key) {
|
|
48
36
|
key = (0, _uniqid.default)() + "-" + key;
|
|
49
37
|
}
|
|
50
|
-
|
|
51
38
|
if (data.keyPrefix) {
|
|
52
39
|
key = `${(0, _sanitizeFilename.default)(data.keyPrefix)}-${key}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
40
|
+
}
|
|
55
41
|
|
|
42
|
+
// Replace all whitespace.
|
|
56
43
|
key = key.replace(/\s/g, "");
|
|
57
44
|
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
58
45
|
const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
|
|
@@ -66,11 +53,9 @@ var _default = async (data, settings) => {
|
|
|
66
53
|
key
|
|
67
54
|
}
|
|
68
55
|
};
|
|
69
|
-
|
|
70
56
|
if (params.Fields.key.startsWith("/")) {
|
|
71
57
|
params.Fields.key = params.Fields.key.slice(1);
|
|
72
58
|
}
|
|
73
|
-
|
|
74
59
|
const s3 = new _s.default();
|
|
75
60
|
const payload = s3.createPresignedPost(params);
|
|
76
61
|
return {
|
|
@@ -83,5 +68,4 @@ var _default = async (data, settings) => {
|
|
|
83
68
|
}
|
|
84
69
|
};
|
|
85
70
|
};
|
|
86
|
-
|
|
87
71
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","validateSync","e","data","settings","type","contentType","Error","key","sanitizeFilename","name","uniqueId","keyPrefix","replace","uploadMinFileSize","uploadMaxFileSize","params","Expires","Bucket","Conditions","Fields","startsWith","slice","s3","S3","payload","createPresignedPost","file","size"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import uniqueId from \"uniqid\";\nimport sanitizeFilename from \"sanitize-filename\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { validation } from \"@webiny/validation\";\nimport { PresignedPostPayloadData, PresignedPostPayloadDataResponse } from \"~/types\";\nimport { FileManagerSettings } from \"@webiny/api-file-manager/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 26214400; // 25MB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch (e) {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport default async (\n data: PresignedPostPayloadData,\n settings: FileManagerSettings\n): Promise<PresignedPostPayloadDataResponse> => {\n // If type is missing, let's use the default \"application/octet-stream\" type,\n // which is also the default type that the Amazon S3 would use.\n if (!data.type) {\n data.type = \"application/octet-stream\";\n }\n\n const contentType = data.type;\n if (!contentType) {\n throw Error(`File's content type could not be resolved.`);\n }\n\n let key = sanitizeFilename(data.name);\n if (key) {\n key = uniqueId() + \"-\" + key;\n }\n\n if (data.keyPrefix) {\n key = `${sanitizeFilename(data.keyPrefix)}-${key}`;\n }\n\n // Replace all whitespace.\n key = key.replace(/\\s/g, \"\");\n\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const params = {\n Expires: 60,\n Bucket: S3_BUCKET,\n Conditions: [[\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]], // 0 Bytes - 25MB\n Fields: {\n \"Content-Type\": contentType,\n key\n }\n };\n\n if (params.Fields.key.startsWith(\"/\")) {\n params.Fields.key = params.Fields.key.slice(1);\n }\n\n const s3 = new S3();\n const payload = s3.createPresignedPost(params);\n\n return {\n data: payload,\n file: {\n name: key,\n key,\n type: contentType,\n size: data.size\n }\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","validateSync","e","data","settings","type","contentType","Error","key","sanitizeFilename","name","uniqueId","keyPrefix","replace","uploadMinFileSize","uploadMaxFileSize","params","Expires","Bucket","Conditions","Fields","startsWith","slice","s3","S3","payload","createPresignedPost","file","size"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import uniqueId from \"uniqid\";\nimport sanitizeFilename from \"sanitize-filename\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { validation } from \"@webiny/validation\";\nimport { PresignedPostPayloadData, PresignedPostPayloadDataResponse } from \"~/types\";\nimport { FileManagerSettings } from \"@webiny/api-file-manager/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 26214400; // 25MB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch (e) {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport default async (\n data: PresignedPostPayloadData,\n settings: FileManagerSettings\n): Promise<PresignedPostPayloadDataResponse> => {\n // If type is missing, let's use the default \"application/octet-stream\" type,\n // which is also the default type that the Amazon S3 would use.\n if (!data.type) {\n data.type = \"application/octet-stream\";\n }\n\n const contentType = data.type;\n if (!contentType) {\n throw Error(`File's content type could not be resolved.`);\n }\n\n let key = sanitizeFilename(data.name);\n if (key) {\n key = uniqueId() + \"-\" + key;\n }\n\n if (data.keyPrefix) {\n key = `${sanitizeFilename(data.keyPrefix)}-${key}`;\n }\n\n // Replace all whitespace.\n key = key.replace(/\\s/g, \"\");\n\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const params = {\n Expires: 60,\n Bucket: S3_BUCKET,\n Conditions: [[\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]], // 0 Bytes - 25MB\n Fields: {\n \"Content-Type\": contentType,\n key\n }\n };\n\n if (params.Fields.key.startsWith(\"/\")) {\n params.Fields.key = params.Fields.key.slice(1);\n }\n\n const s3 = new S3();\n const payload = s3.createPresignedPost(params);\n\n return {\n data: payload,\n file: {\n name: key,\n key,\n type: contentType,\n size: data.size\n }\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAIA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AACvC,MAAMG,4BAA4B,GAAG,QAAQ,CAAC,CAAC;;AAE/C,MAAMC,qBAAqB,GAAG,CAACC,KAAa,EAAEC,YAAoB,KAAa;EAC3E,IAAI;IACAC,sBAAU,CAACC,YAAY,CAACH,KAAK,EAAE,wBAAwB,CAAC;IACxD,OAAOA,KAAK;EAChB,CAAC,CAAC,OAAOI,CAAC,EAAE;IACR;IACA,OAAOH,YAAY;EACvB;AACJ,CAAC;AAAC,eAEa,OACXI,IAA8B,EAC9BC,QAA6B,KACe;EAC5C;EACA;EACA,IAAI,CAACD,IAAI,CAACE,IAAI,EAAE;IACZF,IAAI,CAACE,IAAI,GAAG,0BAA0B;EAC1C;EAEA,MAAMC,WAAW,GAAGH,IAAI,CAACE,IAAI;EAC7B,IAAI,CAACC,WAAW,EAAE;IACd,MAAMC,KAAK,CAAE,4CAA2C,CAAC;EAC7D;EAEA,IAAIC,GAAG,GAAG,IAAAC,yBAAgB,EAACN,IAAI,CAACO,IAAI,CAAC;EACrC,IAAIF,GAAG,EAAE;IACLA,GAAG,GAAG,IAAAG,eAAQ,GAAE,GAAG,GAAG,GAAGH,GAAG;EAChC;EAEA,IAAIL,IAAI,CAACS,SAAS,EAAE;IAChBJ,GAAG,GAAI,GAAE,IAAAC,yBAAgB,EAACN,IAAI,CAACS,SAAS,CAAE,IAAGJ,GAAI,EAAC;EACtD;;EAEA;EACAA,GAAG,GAAGA,GAAG,CAACK,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAE5B,MAAMC,iBAAiB,GAAGjB,qBAAqB,CAACO,QAAQ,CAACU,iBAAiB,EAAE,CAAC,CAAC;EAC9E,MAAMC,iBAAiB,GAAGlB,qBAAqB,CAC3CO,QAAQ,CAACW,iBAAiB,EAC1BnB,4BAA4B,CAC/B;EAED,MAAMoB,MAAM,GAAG;IACXC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAEzB,SAAS;IACjB0B,UAAU,EAAE,CAAC,CAAC,sBAAsB,EAAEL,iBAAiB,EAAEC,iBAAiB,CAAC,CAAC;IAAE;IAC9EK,MAAM,EAAE;MACJ,cAAc,EAAEd,WAAW;MAC3BE;IACJ;EACJ,CAAC;EAED,IAAIQ,MAAM,CAACI,MAAM,CAACZ,GAAG,CAACa,UAAU,CAAC,GAAG,CAAC,EAAE;IACnCL,MAAM,CAACI,MAAM,CAACZ,GAAG,GAAGQ,MAAM,CAACI,MAAM,CAACZ,GAAG,CAACc,KAAK,CAAC,CAAC,CAAC;EAClD;EAEA,MAAMC,EAAE,GAAG,IAAIC,UAAE,EAAE;EACnB,MAAMC,OAAO,GAAGF,EAAE,CAACG,mBAAmB,CAACV,MAAM,CAAC;EAE9C,OAAO;IACHb,IAAI,EAAEsB,OAAO;IACbE,IAAI,EAAE;MACFjB,IAAI,EAAEF,GAAG;MACTA,GAAG;MACHH,IAAI,EAAEC,WAAW;MACjBsB,IAAI,EAAEzB,IAAI,CAACyB;IACf;EACJ,CAAC;AACL,CAAC;AAAA"}
|
package/utils/uploadFileToS3.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _formData = _interopRequireDefault(require("form-data"));
|
|
11
|
-
|
|
12
9
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
13
|
-
|
|
14
10
|
var _default = async (buffer, preSignedPostPayload) => {
|
|
15
|
-
const formData = new _formData.default();
|
|
16
|
-
|
|
11
|
+
const formData = new _formData.default();
|
|
12
|
+
// Add all pre signed payload field to "FormData".
|
|
17
13
|
Object.keys(preSignedPostPayload.fields).forEach(key => {
|
|
18
14
|
formData.append(key, preSignedPostPayload.fields[key]);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
formData.append("file", buffer);
|
|
22
|
-
|
|
15
|
+
});
|
|
16
|
+
// Add file content to "FormData".
|
|
17
|
+
formData.append("file", buffer);
|
|
18
|
+
// Finally make the upload request to S3.
|
|
23
19
|
return (0, _nodeFetch.default)(preSignedPostPayload.url, {
|
|
24
20
|
method: "POST",
|
|
25
21
|
body: formData
|
|
26
22
|
});
|
|
27
23
|
};
|
|
28
|
-
|
|
29
24
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["buffer","preSignedPostPayload","formData","FormData","Object","keys","fields","forEach","key","append","fetch","url","method","body"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import FormData from \"form-data\";\nimport fetch, { Response } from \"node-fetch\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nexport default async (\n buffer: Buffer,\n preSignedPostPayload: S3.PresignedPost\n): Promise<Response> => {\n const formData = new FormData();\n // Add all pre signed payload field to \"FormData\".\n Object.keys(preSignedPostPayload.fields).forEach(key => {\n formData.append(key, preSignedPostPayload.fields[key]);\n });\n // Add file content to \"FormData\".\n formData.append(\"file\", buffer);\n // Finally make the upload request to S3.\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["buffer","preSignedPostPayload","formData","FormData","Object","keys","fields","forEach","key","append","fetch","url","method","body"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import FormData from \"form-data\";\nimport fetch, { Response } from \"node-fetch\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nexport default async (\n buffer: Buffer,\n preSignedPostPayload: S3.PresignedPost\n): Promise<Response> => {\n const formData = new FormData();\n // Add all pre signed payload field to \"FormData\".\n Object.keys(preSignedPostPayload.fields).forEach(key => {\n formData.append(key, preSignedPostPayload.fields[key]);\n });\n // Add file content to \"FormData\".\n formData.append(\"file\", buffer);\n // Finally make the upload request to S3.\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAA6C,eAG9B,OACXA,MAAc,EACdC,oBAAsC,KAClB;EACpB,MAAMC,QAAQ,GAAG,IAAIC,iBAAQ,EAAE;EAC/B;EACAC,MAAM,CAACC,IAAI,CAACJ,oBAAoB,CAACK,MAAM,CAAC,CAACC,OAAO,CAACC,GAAG,IAAI;IACpDN,QAAQ,CAACO,MAAM,CAACD,GAAG,EAAEP,oBAAoB,CAACK,MAAM,CAACE,GAAG,CAAC,CAAC;EAC1D,CAAC,CAAC;EACF;EACAN,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAET,MAAM,CAAC;EAC/B;EACA,OAAO,IAAAU,kBAAK,EAACT,oBAAoB,CAACU,GAAG,EAAE;IACnCC,MAAM,EAAE,MAAM;IACdC,IAAI,EAAEX;EACV,CAAC,CAAC;AACN,CAAC;AAAA"}
|