@webiny/api-file-manager-s3 5.34.8 → 5.35.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("@webiny/api-file-manager/types").FileManagerContext> | import("@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin").FilePhysicalStoragePlugin<import("@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin").FilePhysicalStoragePluginUploadParams, import("@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin").FilePhysicalStoragePluginDeleteParams>)[];
1
+ declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("@webiny/api-file-manager/types").FileManagerContext> | import("@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePlugin<import("@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginUploadParams, import("@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginDeleteParams>)[];
2
2
  export default _default;
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":";;;;;;;;;AAAA;;AACA;;eAEe,MAAM,CAAC,IAAAA,qBAAA,GAAD,EAAkBC,4BAAlB,C"}
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": "5.34.8",
3
+ "version": "5.35.0-beta.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,21 +10,23 @@
10
10
  "author": "Webiny Ltd",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@webiny/api-file-manager": "5.34.8",
14
- "@webiny/error": "5.34.8",
15
- "@webiny/handler-graphql": "5.34.8",
16
- "@webiny/validation": "5.34.8",
13
+ "@webiny/api-file-manager": "5.35.0-beta.0",
14
+ "@webiny/api-security": "5.35.0-beta.0",
15
+ "@webiny/error": "5.35.0-beta.0",
16
+ "@webiny/handler-graphql": "5.35.0-beta.0",
17
+ "@webiny/validation": "5.35.0-beta.0",
17
18
  "form-data": "4.0.0",
18
- "node-fetch": "2.6.7",
19
- "sanitize-filename": "1.6.3",
20
- "uniqid": "5.4.0"
19
+ "mdbid": "1.0.0",
20
+ "mime": "3.0.0",
21
+ "node-fetch": "2.6.9",
22
+ "sanitize-filename": "1.6.3"
21
23
  },
22
24
  "devDependencies": {
23
25
  "@babel/cli": "^7.19.3",
24
26
  "@babel/core": "^7.19.3",
25
27
  "@types/node-fetch": "^2.6.1",
26
- "@webiny/cli": "^5.34.8",
27
- "@webiny/project-utils": "^5.34.8",
28
+ "@webiny/cli": "^5.35.0-beta.0",
29
+ "@webiny/project-utils": "^5.35.0-beta.0",
28
30
  "rimraf": "^3.0.2",
29
31
  "typescript": "4.7.4"
30
32
  },
@@ -36,5 +38,5 @@
36
38
  "build": "yarn webiny run build",
37
39
  "watch": "yarn webiny run watch"
38
40
  },
39
- "gitHead": "6e77eebaac687279fe82ea04f667b7e84214b96a"
41
+ "gitHead": "8acc9e8892842cabb3980ce0b6432fde55968d5b"
40
42
  }
@@ -0,0 +1,5 @@
1
+ import { GetPermission } from "@webiny/api-security/types";
2
+ import { FilePermission } from "@webiny/api-file-manager/types";
3
+ export declare const checkBasePermissions: (getPermission: GetPermission, check?: {
4
+ rwd?: string;
5
+ }) => Promise<FilePermission>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.checkBasePermissions = void 0;
7
+ var _apiSecurity = require("@webiny/api-security");
8
+ const checkBasePermissions = async (getPermission, check = {}) => {
9
+ const filePermission = await getPermission("fm.file");
10
+ if (!filePermission) {
11
+ throw new _apiSecurity.NotAuthorizedError();
12
+ }
13
+ if (check.rwd && !hasRwd(filePermission, check.rwd)) {
14
+ throw new _apiSecurity.NotAuthorizedError();
15
+ }
16
+ return filePermission;
17
+ };
18
+ exports.checkBasePermissions = checkBasePermissions;
19
+ const hasRwd = (filesFilePermission, rwd) => {
20
+ if (typeof filesFilePermission.rwd !== "string") {
21
+ return true;
22
+ }
23
+ return filesFilePermission.rwd.includes(rwd);
24
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"names":["checkBasePermissions","getPermission","check","filePermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkBasePermissions.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { GetPermission } from \"@webiny/api-security/types\";\nimport { FilePermission } from \"@webiny/api-file-manager/types\";\n\nexport const checkBasePermissions = async (\n getPermission: GetPermission,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n const filePermission = await getPermission<FilePermission>(\"fm.file\");\n\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"],"mappings":";;;;;;AAAA;AAIO,MAAMA,oBAAoB,GAAG,OAChCC,aAA4B,EAC5BC,KAAuB,GAAG,CAAC,CAAC,KACF;EAC1B,MAAMC,cAAc,GAAG,MAAMF,aAAa,CAAiB,SAAS,CAAC;EAErE,IAAI,CAACE,cAAc,EAAE;IACjB,MAAM,IAAIC,+BAAkB,EAAE;EAClC;EACA,IAAIF,KAAK,CAACG,GAAG,IAAI,CAACC,MAAM,CAACH,cAAc,EAAED,KAAK,CAACG,GAAG,CAAC,EAAE;IACjD,MAAM,IAAID,+BAAkB,EAAE;EAClC;EAEA,OAAOD,cAAc;AACzB,CAAC;AAAC;AAEF,MAAMG,MAAM,GAAG,CAACC,mBAAmC,EAAEF,GAAW,KAAc;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAAG,KAAK,QAAQ,EAAE;IAC7C,OAAO,IAAI;EACf;EAEA,OAAOE,mBAAmB,CAACF,GAAG,CAACG,QAAQ,CAACH,GAAG,CAAC;AAChD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { FileManagerContext, FilePermission } from "@webiny/api-file-manager/types";
2
+ export declare const checkPermission: (context: FileManagerContext, check?: {
3
+ rwd?: string;
4
+ }) => Promise<FilePermission>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.checkPermission = void 0;
7
+ var _apiSecurity = require("@webiny/api-security");
8
+ const checkPermission = async (context, check = {}) => {
9
+ await context.i18n.checkI18NContentPermission();
10
+ const filePermission = await context.security.getPermission("fm.file");
11
+ if (!filePermission) {
12
+ throw new _apiSecurity.NotAuthorizedError();
13
+ }
14
+ if (check.rwd && !hasRwd(filePermission, check.rwd)) {
15
+ throw new _apiSecurity.NotAuthorizedError();
16
+ }
17
+ return filePermission;
18
+ };
19
+ exports.checkPermission = checkPermission;
20
+ const hasRwd = (filesFilePermission, rwd) => {
21
+ if (typeof filesFilePermission.rwd !== "string") {
22
+ return true;
23
+ }
24
+ return filesFilePermission.rwd.includes(rwd);
25
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"names":["checkPermission","context","check","i18n","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkPermission.ts"],"sourcesContent":["import { FileManagerContext, FilePermission } from \"@webiny/api-file-manager/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const checkPermission = async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n) => {\n await context.i18n.checkI18NContentPermission();\n\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"],"mappings":";;;;;;AACA;AAEO,MAAMA,eAAe,GAAG,OAC3BC,OAA2B,EAC3BC,KAAuB,GAAG,CAAC,CAAC,KAC3B;EACD,MAAMD,OAAO,CAACE,IAAI,CAACC,0BAA0B,EAAE;EAE/C,MAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAQ,CAACC,aAAa,CAAiB,SAAS,CAAC;EAEtF,IAAI,CAACF,cAAc,EAAE;IACjB,MAAM,IAAIG,+BAAkB,EAAE;EAClC;EACA,IAAIN,KAAK,CAACO,GAAG,IAAI,CAACC,MAAM,CAACL,cAAc,EAAEH,KAAK,CAACO,GAAG,CAAC,EAAE;IACjD,MAAM,IAAID,+BAAkB,EAAE;EAClC;EAEA,OAAOH,cAAc;AACzB,CAAC;AAAC;AAEF,MAAMK,MAAM,GAAG,CAACC,mBAAmC,EAAEF,GAAW,KAAc;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAAG,KAAK,QAAQ,EAAE;IAC7C,OAAO,IAAI;EACf;EAEA,OAAOE,mBAAmB,CAACF,GAAG,CAACG,QAAQ,CAACH,GAAG,CAAC;AAChD,CAAC"}
@@ -1,6 +1,3 @@
1
- import { FilePhysicalStoragePlugin, FilePhysicalStoragePluginUploadParams } from "@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin";
2
- import { PresignedPostPayloadData } from "../types";
3
- export interface S3FilePhysicalStoragePluginUploadParams extends FilePhysicalStoragePluginUploadParams, PresignedPostPayloadData {
4
- }
1
+ import { FilePhysicalStoragePlugin } from "@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin";
5
2
  declare const _default: () => FilePhysicalStoragePlugin;
6
3
  export default _default;
@@ -1,47 +1,37 @@
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
- var _getPresignedPostPayload = _interopRequireDefault(require("../utils/getPresignedPostPayload"));
15
-
10
+ var _getPresignedPostPayload = require("../utils/getPresignedPostPayload");
16
11
  var _uploadFileToS = _interopRequireDefault(require("../utils/uploadFileToS3"));
17
-
18
- var _FilePhysicalStoragePlugin = require("@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin");
19
-
12
+ var _FilePhysicalStoragePlugin = require("@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin");
20
13
  const _excluded = ["settings", "buffer"];
21
14
  const S3_BUCKET = process.env.S3_BUCKET;
22
-
23
15
  var _default = () => {
24
16
  /**
25
- * We need to extends the type for FilePhysicalStoragePlugin.
26
- * Otherwise the getPresignedPostPayload does not know it has all required values in params.
17
+ * We need to extend the type for FilePhysicalStoragePlugin.
18
+ * Otherwise, the `getPresignedPostPayload` doesn't know it has all required values in params.
27
19
  */
28
20
  return new _FilePhysicalStoragePlugin.FilePhysicalStoragePlugin({
29
21
  upload: async params => {
30
22
  const {
31
- settings,
32
- buffer
33
- } = params,
34
- data = (0, _objectWithoutProperties2.default)(params, _excluded);
23
+ settings,
24
+ buffer
25
+ } = params,
26
+ data = (0, _objectWithoutProperties2.default)(params, _excluded);
35
27
  const {
36
28
  data: preSignedPostPayload,
37
29
  file
38
- } = await (0, _getPresignedPostPayload.default)(data, settings);
30
+ } = await (0, _getPresignedPostPayload.getPresignedPostPayload)(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":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;AAMA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAR,CAAYF,SAA9B;;eAMe,MAAiC;EAC5C;AACJ;AACA;AACA;EACI,OAAO,IAAIG,oDAAJ,CAAuE;IAC1EC,MAAM,EAAE,MAAMC,MAAN,IAAgB;MACpB,MAAM;QAAEC,QAAF;QAAYC;MAAZ,IAAgCF,MAAtC;MAAA,MAA6BG,IAA7B,0CAAsCH,MAAtC;MAEA,MAAM;QAAEG,IAAI,EAAEC,oBAAR;QAA8BC;MAA9B,IAAuC,MAAM,IAAAC,gCAAA,EAC/CH,IAD+C,EAE/CF,QAF+C,CAAnD;MAKA,MAAMM,QAAQ,GAAG,MAAM,IAAAC,sBAAA,EAAeN,MAAf,EAAuBE,oBAAvB,CAAvB;;MACA,IAAI,CAACG,QAAQ,CAACE,EAAd,EAAkB;QACd,MAAMC,KAAK,CAAC,wBAAD,CAAX;MACH;;MAED,OAAO;QACHP,IAAI,EAAEC,oBADH;QAEHC;MAFG,CAAP;IAIH,CAlByE;IAmB1EM,MAAM,EAAE,MAAMX,MAAN,IAAgB;MACpB,MAAM;QAAEY;MAAF,IAAUZ,MAAhB;MACA,MAAMa,EAAE,GAAG,IAAIC,UAAJ,EAAX;;MAEA,IAAI,CAACF,GAAD,IAAQ,CAACjB,SAAb,EAAwB;QACpB;MACH;;MAED,MAAMkB,EAAE,CACHE,YADC,CACY;QACVC,MAAM,EAAErB,SADE;QAEVsB,GAAG,EAAEL;MAFK,CADZ,EAKDM,OALC,EAAN;IAMH;EAjCyE,CAAvE,CAAP;AAmCH,C"}
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 { FilePhysicalStoragePlugin } from \"@webiny/api-file-manager/plugins/FilePhysicalStoragePlugin\";\nimport { PresignedPostPayloadData } from \"~/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\n\nexport default (): FilePhysicalStoragePlugin => {\n /**\n * We need to extend the type for FilePhysicalStoragePlugin.\n * Otherwise, the `getPresignedPostPayload` doesn't know it has all required values in params.\n */\n return new FilePhysicalStoragePlugin({\n upload: async params => {\n const { settings, buffer, ...data } = params;\n\n const { data: preSignedPostPayload, file } = await getPresignedPostPayload(\n data as PresignedPostPayloadData,\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;AAAuG;AAGvG,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AAAC,eAEzB,MAAiC;EAC5C;AACJ;AACA;AACA;EACI,OAAO,IAAIG,oDAAyB,CAAC;IACjCC,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,gDAAuB,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,19 @@
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
- var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-file-manager/plugins/crud/utils/checkBasePermissions"));
13
-
14
- var _getPresignedPostPayload = _interopRequireDefault(require("../utils/getPresignedPostPayload"));
15
-
9
+ var _getPresignedPostPayload = require("../utils/getPresignedPostPayload");
16
10
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
- const BATCH_UPLOAD_MAX_FILES = 20;
11
+ var _checkPermission = require("./checkPermission");
19
12
  const plugin = {
20
13
  type: "graphql-schema",
21
14
  name: "graphql-schema-api-file-manager-s3",
22
15
  schema: {
23
- typeDefs:
24
- /* GraphQL */
25
- `
16
+ typeDefs: /* GraphQL */`
26
17
  input PreSignedPostPayloadInput {
27
18
  name: String!
28
19
  type: String!
@@ -30,16 +21,17 @@ const plugin = {
30
21
  }
31
22
 
32
23
  type GetPreSignedPostPayloadResponseDataFile {
33
- name: String
34
- type: String
35
- size: Long
36
- key: String
24
+ id: ID!
25
+ name: String!
26
+ type: String!
27
+ size: Long!
28
+ key: String!
37
29
  }
38
30
 
39
31
  type GetPreSignedPostPayloadResponseData {
40
32
  # Contains data that is necessary for initiating a file upload.
41
- data: JSON
42
- file: UploadFileResponseDataFile
33
+ data: JSON!
34
+ file: UploadFileResponseDataFile!
43
35
  }
44
36
 
45
37
  type GetPreSignedPostPayloadResponse {
@@ -49,7 +41,7 @@ const plugin = {
49
41
 
50
42
  type GetPreSignedPostPayloadsResponse {
51
43
  error: FileError
52
- data: [GetPreSignedPostPayloadResponseData]!
44
+ data: [GetPreSignedPostPayloadResponseData!]!
53
45
  }
54
46
 
55
47
  extend type FmQuery {
@@ -65,22 +57,17 @@ const plugin = {
65
57
  FmQuery: {
66
58
  getPreSignedPostPayload: async (_, args, context) => {
67
59
  try {
68
- await (0, _checkBasePermissions.default)(context, {
60
+ await (0, _checkPermission.checkPermission)(context, {
69
61
  rwd: "w"
70
62
  });
71
- const {
72
- data
73
- } = args;
74
- const settings = await context.fileManager.settings.getSettings();
75
-
63
+ const file = args.data;
64
+ const settings = await context.fileManager.getSettings();
76
65
  if (!settings) {
77
66
  throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_SETTINGS_ERROR", {
78
- file: data
67
+ file
79
68
  });
80
69
  }
81
-
82
- const response = await (0, _getPresignedPostPayload.default)(data, settings);
83
- return new _responses.Response(response);
70
+ return new _responses.Response((0, _getPresignedPostPayload.getPresignedPostPayload)(file, settings));
84
71
  } catch (e) {
85
72
  return new _responses.ErrorResponse({
86
73
  message: e.message,
@@ -90,50 +77,21 @@ const plugin = {
90
77
  }
91
78
  },
92
79
  getPreSignedPostPayloads: async (_, args, context) => {
93
- await (0, _checkBasePermissions.default)(context, {
80
+ await (0, _checkPermission.checkPermission)(context, {
94
81
  rwd: "w"
95
82
  });
96
- const {
97
- data: files
98
- } = args;
99
-
100
- if (!Array.isArray(files)) {
101
- return new _responses.ErrorResponse({
102
- code: "UPLOAD_FILES_NON_ARRAY",
103
- message: `"data" argument must be an array.`
104
- });
105
- }
106
-
107
- if (files.length === 0) {
108
- return new _responses.ErrorResponse({
109
- code: "UPLOAD_FILES_MIN_FILES",
110
- message: `"data" argument must contain at least one file.`
111
- });
112
- }
113
-
114
- if (files.length > BATCH_UPLOAD_MAX_FILES) {
115
- return new _responses.ErrorResponse({
116
- code: "UPLOAD_FILES_MAX_FILES",
117
- message: `"data" argument must not contain more than ${BATCH_UPLOAD_MAX_FILES} files.`
118
- });
119
- }
120
-
83
+ const files = args.data;
121
84
  try {
122
- const settings = await context.fileManager.settings.getSettings();
123
-
85
+ const settings = await context.fileManager.getSettings();
124
86
  if (!settings) {
125
87
  throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_SETTINGS_ERROR", {
126
88
  files
127
89
  });
128
90
  }
129
-
130
- const promises = [];
131
-
132
- for (const item of files) {
133
- promises.push((0, _getPresignedPostPayload.default)(item, settings));
134
- }
135
-
136
- return new _responses.Response(await Promise.all(promises));
91
+ const presignedPayloads = files.map(file => {
92
+ return (0, _getPresignedPostPayload.getPresignedPostPayload)(file, settings);
93
+ });
94
+ return new _responses.Response(presignedPayloads);
137
95
  } catch (e) {
138
96
  return new _responses.ErrorResponse({
139
97
  message: e.message,
@@ -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: Long!\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n name: String\n type: String\n size: Long\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
+ {"version":3,"names":["plugin","type","name","schema","typeDefs","resolvers","FmQuery","getPreSignedPostPayload","_","args","context","checkPermission","rwd","file","data","settings","fileManager","getSettings","WebinyError","Response","getPresignedPostPayload","e","ErrorResponse","message","code","getPreSignedPostPayloads","files","presignedPayloads","map"],"sources":["graphqlFileStorageS3.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql/responses\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getPresignedPostPayload } from \"~/utils/getPresignedPostPayload\";\nimport WebinyError from \"@webiny/error\";\nimport { checkPermission } from \"~/plugins/checkPermission\";\nimport { PresignedPostPayloadData } from \"~/types\";\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: Long!\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n id: ID!\n name: String!\n type: String!\n size: Long!\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 checkPermission(context, { rwd: \"w\" });\n\n const file = args.data as PresignedPostPayloadData;\n\n const settings = await context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n { file }\n );\n }\n\n return new Response(getPresignedPostPayload(file, settings));\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, context) => {\n await checkPermission(context, { rwd: \"w\" });\n\n const files = args.data as PresignedPostPayloadData[];\n\n try {\n const settings = await context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n { files }\n );\n }\n\n const presignedPayloads = files.map(file => {\n return getPresignedPostPayload(file, settings);\n });\n\n return new Response(presignedPayloads);\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":";;;;;;;AACA;AAEA;AACA;AACA;AAGA,MAAMA,MAA+C,GAAG;EACpDC,IAAI,EAAE,gBAAgB;EACtBC,IAAI,EAAE,oCAAoC;EAC1CC,MAAM,EAAE;IACJC,QAAQ,EAAE,aAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,EAAE;MACPC,OAAO,EAAE;QACLC,uBAAuB,EAAE,OAAOC,CAAC,EAAEC,IAAS,EAAEC,OAAO,KAAK;UACtD,IAAI;YACA,MAAM,IAAAC,gCAAe,EAACD,OAAO,EAAE;cAAEE,GAAG,EAAE;YAAI,CAAC,CAAC;YAE5C,MAAMC,IAAI,GAAGJ,IAAI,CAACK,IAAgC;YAElD,MAAMC,QAAQ,GAAG,MAAML,OAAO,CAACM,WAAW,CAACC,WAAW,EAAE;YACxD,IAAI,CAACF,QAAQ,EAAE;cACX,MAAM,IAAIG,cAAW,CACjB,gCAAgC,EAChC,6BAA6B,EAC7B;gBAAEL;cAAK,CAAC,CACX;YACL;YAEA,OAAO,IAAIM,mBAAQ,CAAC,IAAAC,gDAAuB,EAACP,IAAI,EAAEE,QAAQ,CAAC,CAAC;UAChE,CAAC,CAAC,OAAOM,CAAC,EAAE;YACR,OAAO,IAAIC,wBAAa,CAAC;cACrBC,OAAO,EAAEF,CAAC,CAACE,OAAO;cAClBC,IAAI,EAAEH,CAAC,CAACG,IAAI;cACZV,IAAI,EAAEO,CAAC,CAACP;YACZ,CAAC,CAAC;UACN;QACJ,CAAC;QACDW,wBAAwB,EAAE,OAAOjB,CAAC,EAAEC,IAAI,EAAEC,OAAO,KAAK;UAClD,MAAM,IAAAC,gCAAe,EAACD,OAAO,EAAE;YAAEE,GAAG,EAAE;UAAI,CAAC,CAAC;UAE5C,MAAMc,KAAK,GAAGjB,IAAI,CAACK,IAAkC;UAErD,IAAI;YACA,MAAMC,QAAQ,GAAG,MAAML,OAAO,CAACM,WAAW,CAACC,WAAW,EAAE;YACxD,IAAI,CAACF,QAAQ,EAAE;cACX,MAAM,IAAIG,cAAW,CACjB,gCAAgC,EAChC,6BAA6B,EAC7B;gBAAEQ;cAAM,CAAC,CACZ;YACL;YAEA,MAAMC,iBAAiB,GAAGD,KAAK,CAACE,GAAG,CAACf,IAAI,IAAI;cACxC,OAAO,IAAAO,gDAAuB,EAACP,IAAI,EAAEE,QAAQ,CAAC;YAClD,CAAC,CAAC;YAEF,OAAO,IAAII,mBAAQ,CAACQ,iBAAiB,CAAC;UAC1C,CAAC,CAAC,OAAON,CAAC,EAAE;YACR,OAAO,IAAIC,wBAAa,CAAC;cACrBC,OAAO,EAAEF,CAAC,CAACE,OAAO;cAClBC,IAAI,EAAEH,CAAC,CAACG,IAAI;cACZV,IAAI,EAAEO,CAAC,CAACP;YACZ,CAAC,CAAC;UACN;QACJ;MACJ;IACJ;EACJ;AACJ,CAAC;AAAC,eAEad,MAAM;AAAA"}
package/types.d.ts CHANGED
@@ -3,11 +3,14 @@ export interface PresignedPostPayloadData {
3
3
  name: string;
4
4
  type: string;
5
5
  size: number;
6
- keyPrefix: string;
6
+ id?: string;
7
+ key?: string;
8
+ keyPrefix?: string;
7
9
  }
8
10
  export interface PresignedPostPayloadDataResponse {
9
11
  data: S3.PresignedPost;
10
12
  file: {
13
+ id: string;
11
14
  name: string;
12
15
  key: string;
13
16
  type: string;
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\n\nexport interface PresignedPostPayloadData {\n name: string;\n type: string;\n size: number;\n keyPrefix: string;\n}\n\nexport interface PresignedPostPayloadDataResponse {\n data: S3.PresignedPost;\n file: {\n name: string;\n key: string;\n type: string;\n size: number;\n };\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\n\nexport interface PresignedPostPayloadData {\n name: string;\n type: string;\n size: number;\n id?: string;\n key?: string;\n keyPrefix?: string;\n}\n\nexport interface PresignedPostPayloadDataResponse {\n data: S3.PresignedPost;\n file: {\n id: string;\n name: string;\n key: string;\n type: string;\n size: number;\n };\n}\n"],"mappings":""}
@@ -1,4 +1,3 @@
1
1
  import { PresignedPostPayloadData, PresignedPostPayloadDataResponse } from "../types";
2
2
  import { FileManagerSettings } from "@webiny/api-file-manager/types";
3
- declare const _default: (data: PresignedPostPayloadData, settings: FileManagerSettings) => Promise<PresignedPostPayloadDataResponse>;
4
- export default _default;
3
+ export declare const getPresignedPostPayload: (data: PresignedPostPayloadData, settings: FileManagerSettings) => PresignedPostPayloadDataResponse;
@@ -1,87 +1,83 @@
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
- exports.default = void 0;
9
-
10
- var _uniqid = _interopRequireDefault(require("uniqid"));
11
-
7
+ exports.getPresignedPostPayload = void 0;
8
+ var _mdbid = _interopRequireDefault(require("mdbid"));
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");
12
+ var _mimeTypes = require("./mimeTypes");
13
+ // @ts-ignore `mdbid` has no type declarations
17
14
 
18
15
  const S3_BUCKET = process.env.S3_BUCKET;
19
- const UPLOAD_MAX_FILE_SIZE_DEFAULT = 26214400; // 25MB
16
+ const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB
20
17
 
21
18
  const sanitizeFileSizeValue = (value, defaultValue) => {
22
19
  try {
23
20
  _validation.validation.validateSync(value, "required,numeric,gte:0");
24
-
25
21
  return value;
26
22
  } catch (e) {
27
23
  // TODO @ts-refactor No need to log the error?
28
24
  return defaultValue;
29
25
  }
30
26
  };
31
-
32
- var _default = async (data, settings) => {
27
+ const getPresignedPostPayload = (data, settings) => {
33
28
  // If type is missing, let's use the default "application/octet-stream" type,
34
29
  // which is also the default type that the Amazon S3 would use.
35
30
  if (!data.type) {
36
31
  data.type = "application/octet-stream";
37
32
  }
38
-
39
33
  const contentType = data.type;
40
-
41
34
  if (!contentType) {
42
35
  throw Error(`File's content type could not be resolved.`);
43
36
  }
37
+ const id = data.id || (0, _mdbid.default)();
38
+ let key = data.key || (0, _sanitizeFilename.default)(data.name);
44
39
 
45
- let key = (0, _sanitizeFilename.default)(data.name);
46
-
47
- if (key) {
48
- key = (0, _uniqid.default)() + "-" + key;
40
+ // We must prefix file key with file ID.
41
+ if (!key.startsWith(id)) {
42
+ key = id + "/" + key;
49
43
  }
50
-
51
44
  if (data.keyPrefix) {
52
- key = `${(0, _sanitizeFilename.default)(data.keyPrefix)}-${key}`;
53
- } // Replace all whitespace.
54
-
45
+ key = data.keyPrefix + key;
46
+ }
55
47
 
48
+ // Replace all whitespace.
56
49
  key = key.replace(/\s/g, "");
50
+
51
+ // Make sure file key contains a file extension
52
+ const extensions = _mimeTypes.mimeTypes[contentType];
53
+ if (!extensions.some(ext => key.endsWith(`.${ext}`))) {
54
+ key = key + `.${extensions[0]}`;
55
+ }
57
56
  const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
58
57
  const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
59
58
  const params = {
60
59
  Expires: 60,
61
60
  Bucket: S3_BUCKET,
62
61
  Conditions: [["content-length-range", uploadMinFileSize, uploadMaxFileSize]],
63
- // 0 Bytes - 25MB
64
62
  Fields: {
65
63
  "Content-Type": contentType,
66
64
  key
67
65
  }
68
66
  };
69
-
70
67
  if (params.Fields.key.startsWith("/")) {
71
68
  params.Fields.key = params.Fields.key.slice(1);
72
69
  }
73
-
74
70
  const s3 = new _s.default();
75
71
  const payload = s3.createPresignedPost(params);
76
72
  return {
77
73
  data: payload,
78
74
  file: {
79
- name: key,
75
+ id,
76
+ name: data.name,
80
77
  key,
81
78
  type: contentType,
82
79
  size: data.size
83
80
  }
84
81
  };
85
82
  };
86
-
87
- exports.default = _default;
83
+ exports.getPresignedPostPayload = getPresignedPostPayload;
@@ -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":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAIA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAR,CAAYF,SAA9B;AACA,MAAMG,4BAA4B,GAAG,QAArC,C,CAA+C;;AAE/C,MAAMC,qBAAqB,GAAG,CAACC,KAAD,EAAgBC,YAAhB,KAAiD;EAC3E,IAAI;IACAC,sBAAA,CAAWC,YAAX,CAAwBH,KAAxB,EAA+B,wBAA/B;;IACA,OAAOA,KAAP;EACH,CAHD,CAGE,OAAOI,CAAP,EAAU;IACR;IACA,OAAOH,YAAP;EACH;AACJ,CARD;;eAUe,OACXI,IADW,EAEXC,QAFW,KAGiC;EAC5C;EACA;EACA,IAAI,CAACD,IAAI,CAACE,IAAV,EAAgB;IACZF,IAAI,CAACE,IAAL,GAAY,0BAAZ;EACH;;EAED,MAAMC,WAAW,GAAGH,IAAI,CAACE,IAAzB;;EACA,IAAI,CAACC,WAAL,EAAkB;IACd,MAAMC,KAAK,CAAE,4CAAF,CAAX;EACH;;EAED,IAAIC,GAAG,GAAG,IAAAC,yBAAA,EAAiBN,IAAI,CAACO,IAAtB,CAAV;;EACA,IAAIF,GAAJ,EAAS;IACLA,GAAG,GAAG,IAAAG,eAAA,MAAa,GAAb,GAAmBH,GAAzB;EACH;;EAED,IAAIL,IAAI,CAACS,SAAT,EAAoB;IAChBJ,GAAG,GAAI,GAAE,IAAAC,yBAAA,EAAiBN,IAAI,CAACS,SAAtB,CAAiC,IAAGJ,GAAI,EAAjD;EACH,CAnB2C,CAqB5C;;;EACAA,GAAG,GAAGA,GAAG,CAACK,OAAJ,CAAY,KAAZ,EAAmB,EAAnB,CAAN;EAEA,MAAMC,iBAAiB,GAAGjB,qBAAqB,CAACO,QAAQ,CAACU,iBAAV,EAA6B,CAA7B,CAA/C;EACA,MAAMC,iBAAiB,GAAGlB,qBAAqB,CAC3CO,QAAQ,CAACW,iBADkC,EAE3CnB,4BAF2C,CAA/C;EAKA,MAAMoB,MAAM,GAAG;IACXC,OAAO,EAAE,EADE;IAEXC,MAAM,EAAEzB,SAFG;IAGX0B,UAAU,EAAE,CAAC,CAAC,sBAAD,EAAyBL,iBAAzB,EAA4CC,iBAA5C,CAAD,CAHD;IAGmE;IAC9EK,MAAM,EAAE;MACJ,gBAAgBd,WADZ;MAEJE;IAFI;EAJG,CAAf;;EAUA,IAAIQ,MAAM,CAACI,MAAP,CAAcZ,GAAd,CAAkBa,UAAlB,CAA6B,GAA7B,CAAJ,EAAuC;IACnCL,MAAM,CAACI,MAAP,CAAcZ,GAAd,GAAoBQ,MAAM,CAACI,MAAP,CAAcZ,GAAd,CAAkBc,KAAlB,CAAwB,CAAxB,CAApB;EACH;;EAED,MAAMC,EAAE,GAAG,IAAIC,UAAJ,EAAX;EACA,MAAMC,OAAO,GAAGF,EAAE,CAACG,mBAAH,CAAuBV,MAAvB,CAAhB;EAEA,OAAO;IACHb,IAAI,EAAEsB,OADH;IAEHE,IAAI,EAAE;MACFjB,IAAI,EAAEF,GADJ;MAEFA,GAFE;MAGFH,IAAI,EAAEC,WAHJ;MAIFsB,IAAI,EAAEzB,IAAI,CAACyB;IAJT;EAFH,CAAP;AASH,C"}
1
+ {"version":3,"names":["S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","validateSync","e","getPresignedPostPayload","data","settings","type","contentType","Error","id","mdbid","key","sanitizeFilename","name","startsWith","keyPrefix","replace","extensions","mimeTypes","some","ext","endsWith","uploadMinFileSize","uploadMaxFileSize","params","Expires","Bucket","Conditions","Fields","slice","s3","S3","payload","createPresignedPost","file","size"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["// @ts-ignore `mdbid` has no type declarations\nimport mdbid from \"mdbid\";\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\";\nimport { mimeTypes } from \"./mimeTypes\";\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 (e) {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport const getPresignedPostPayload = (\n data: PresignedPostPayloadData,\n settings: FileManagerSettings\n): 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 const id = data.id || mdbid();\n let key = data.key || sanitizeFilename(data.name);\n\n // We must prefix file key with file ID.\n if (!key.startsWith(id)) {\n key = id + \"/\" + key;\n }\n\n if (data.keyPrefix) {\n key = data.keyPrefix + key;\n }\n\n // Replace all whitespace.\n key = key.replace(/\\s/g, \"\");\n\n // Make sure file key contains a file extension\n const extensions = mimeTypes[contentType];\n if (!extensions.some(ext => key.endsWith(`.${ext}`))) {\n key = key + `.${extensions[0]}`;\n }\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]],\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 id,\n name: data.name,\n key,\n type: contentType,\n size: data.size\n }\n };\n};\n"],"mappings":";;;;;;;AACA;AACA;AACA;AACA;AAGA;AAPA;;AASA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AACvC,MAAMG,4BAA4B,GAAG,aAAa,CAAC,CAAC;;AAEpD,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;AAEM,MAAMI,uBAAuB,GAAG,CACnCC,IAA8B,EAC9BC,QAA6B,KACM;EACnC;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,MAAMC,EAAE,GAAGL,IAAI,CAACK,EAAE,IAAI,IAAAC,cAAK,GAAE;EAC7B,IAAIC,GAAG,GAAGP,IAAI,CAACO,GAAG,IAAI,IAAAC,yBAAgB,EAACR,IAAI,CAACS,IAAI,CAAC;;EAEjD;EACA,IAAI,CAACF,GAAG,CAACG,UAAU,CAACL,EAAE,CAAC,EAAE;IACrBE,GAAG,GAAGF,EAAE,GAAG,GAAG,GAAGE,GAAG;EACxB;EAEA,IAAIP,IAAI,CAACW,SAAS,EAAE;IAChBJ,GAAG,GAAGP,IAAI,CAACW,SAAS,GAAGJ,GAAG;EAC9B;;EAEA;EACAA,GAAG,GAAGA,GAAG,CAACK,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;;EAE5B;EACA,MAAMC,UAAU,GAAGC,oBAAS,CAACX,WAAW,CAAC;EACzC,IAAI,CAACU,UAAU,CAACE,IAAI,CAACC,GAAG,IAAIT,GAAG,CAACU,QAAQ,CAAE,IAAGD,GAAI,EAAC,CAAC,CAAC,EAAE;IAClDT,GAAG,GAAGA,GAAG,GAAI,IAAGM,UAAU,CAAC,CAAC,CAAE,EAAC;EACnC;EAEA,MAAMK,iBAAiB,GAAGzB,qBAAqB,CAACQ,QAAQ,CAACiB,iBAAiB,EAAE,CAAC,CAAC;EAC9E,MAAMC,iBAAiB,GAAG1B,qBAAqB,CAC3CQ,QAAQ,CAACkB,iBAAiB,EAC1B3B,4BAA4B,CAC/B;EAED,MAAM4B,MAAM,GAAG;IACXC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAEjC,SAAS;IACjBkC,UAAU,EAAE,CAAC,CAAC,sBAAsB,EAAEL,iBAAiB,EAAEC,iBAAiB,CAAC,CAAC;IAC5EK,MAAM,EAAE;MACJ,cAAc,EAAErB,WAAW;MAC3BI;IACJ;EACJ,CAAC;EAED,IAAIa,MAAM,CAACI,MAAM,CAACjB,GAAG,CAACG,UAAU,CAAC,GAAG,CAAC,EAAE;IACnCU,MAAM,CAACI,MAAM,CAACjB,GAAG,GAAGa,MAAM,CAACI,MAAM,CAACjB,GAAG,CAACkB,KAAK,CAAC,CAAC,CAAC;EAClD;EAEA,MAAMC,EAAE,GAAG,IAAIC,UAAE,EAAE;EACnB,MAAMC,OAAO,GAAGF,EAAE,CAACG,mBAAmB,CAACT,MAAM,CAAC;EAE9C,OAAO;IACHpB,IAAI,EAAE4B,OAAO;IACbE,IAAI,EAAE;MACFzB,EAAE;MACFI,IAAI,EAAET,IAAI,CAACS,IAAI;MACfF,GAAG;MACHL,IAAI,EAAEC,WAAW;MACjB4B,IAAI,EAAE/B,IAAI,CAAC+B;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * We need to get all extensions that are defined for a specific content type.
3
+ * This operation is not available via the `mime` package, so we create such an object ourselves.
4
+ */
5
+ export declare const mimeTypes: Record<string, string[]>;
@@ -0,0 +1,20 @@
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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _other = _interopRequireDefault(require("mime/types/other"));
10
+ var _standard = _interopRequireDefault(require("mime/types/standard"));
11
+ // @ts-ignore
12
+
13
+ // @ts-ignore
14
+
15
+ /**
16
+ * We need to get all extensions that are defined for a specific content type.
17
+ * This operation is not available via the `mime` package, so we create such an object ourselves.
18
+ */
19
+ const mimeTypes = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _other.default), _standard.default);
20
+ exports.mimeTypes = mimeTypes;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mimeTypes","vendorTypes","standardTypes"],"sources":["mimeTypes.ts"],"sourcesContent":["// @ts-ignore\nimport vendorTypes from \"mime/types/other\";\n// @ts-ignore\nimport standardTypes from \"mime/types/standard\";\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":";;;;;;;;AACA;AAEA;AAHA;;AAEA;;AAGA;AACA;AACA;AACA;AACO,MAAMA,SAAmC,+DACzCC,cAAW,GACXC,iBAAa,CACnB;AAAC"}
@@ -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(); // Add all pre signed payload field to "FormData".
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
- }); // Add file content to "FormData".
20
-
21
- formData.append("file", buffer); // Finally make the upload request to S3.
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":";;;;;;;;;AAAA;;AACA;;eAGe,OACXA,MADW,EAEXC,oBAFW,KAGS;EACpB,MAAMC,QAAQ,GAAG,IAAIC,iBAAJ,EAAjB,CADoB,CAEpB;;EACAC,MAAM,CAACC,IAAP,CAAYJ,oBAAoB,CAACK,MAAjC,EAAyCC,OAAzC,CAAiDC,GAAG,IAAI;IACpDN,QAAQ,CAACO,MAAT,CAAgBD,GAAhB,EAAqBP,oBAAoB,CAACK,MAArB,CAA4BE,GAA5B,CAArB;EACH,CAFD,EAHoB,CAMpB;;EACAN,QAAQ,CAACO,MAAT,CAAgB,MAAhB,EAAwBT,MAAxB,EAPoB,CAQpB;;EACA,OAAO,IAAAU,kBAAA,EAAMT,oBAAoB,CAACU,GAA3B,EAAgC;IACnCC,MAAM,EAAE,MAD2B;IAEnCC,IAAI,EAAEX;EAF6B,CAAhC,CAAP;AAIH,C"}
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"}