@webiny/api-file-manager-s3 5.35.0-beta.2 → 5.35.1-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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-s3",
|
|
3
|
-
"version": "5.35.
|
|
3
|
+
"version": "5.35.1-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/api-file-manager": "5.35.
|
|
14
|
-
"@webiny/api-security": "5.35.
|
|
15
|
-
"@webiny/error": "5.35.
|
|
16
|
-
"@webiny/handler-graphql": "5.35.
|
|
17
|
-
"@webiny/validation": "5.35.
|
|
13
|
+
"@webiny/api-file-manager": "^5.35.1-beta.0",
|
|
14
|
+
"@webiny/api-security": "^5.35.1-beta.0",
|
|
15
|
+
"@webiny/error": "^5.35.1-beta.0",
|
|
16
|
+
"@webiny/handler-graphql": "^5.35.1-beta.0",
|
|
17
|
+
"@webiny/validation": "^5.35.1-beta.0",
|
|
18
18
|
"form-data": "4.0.0",
|
|
19
19
|
"mdbid": "1.0.0",
|
|
20
20
|
"mime": "3.0.0",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"sanitize-filename": "1.6.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@babel/cli": "
|
|
26
|
-
"@babel/core": "
|
|
27
|
-
"@types/node-fetch": "
|
|
28
|
-
"@webiny/cli": "^5.35.
|
|
29
|
-
"@webiny/project-utils": "^5.35.
|
|
30
|
-
"rimraf": "
|
|
25
|
+
"@babel/cli": "7.20.7",
|
|
26
|
+
"@babel/core": "7.20.12",
|
|
27
|
+
"@types/node-fetch": "2.6.2",
|
|
28
|
+
"@webiny/cli": "^5.35.1-beta.0",
|
|
29
|
+
"@webiny/project-utils": "^5.35.1-beta.0",
|
|
30
|
+
"rimraf": "3.0.2",
|
|
31
31
|
"typescript": "4.7.4"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"build": "yarn webiny run build",
|
|
39
39
|
"watch": "yarn webiny run watch"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "d6a257ebbb9e7aeccfaa33a7f83301cf1919b082"
|
|
42
42
|
}
|
|
@@ -50,7 +50,9 @@ const getPresignedPostPayload = (data, settings) => {
|
|
|
50
50
|
|
|
51
51
|
// Make sure file key contains a file extension
|
|
52
52
|
const extensions = _mimeTypes.mimeTypes[contentType];
|
|
53
|
-
|
|
53
|
+
// We only need this variable to compare extensions in a case-insensitive way.
|
|
54
|
+
const lowerKey = key.toLowerCase();
|
|
55
|
+
if (!extensions.some(ext => lowerKey.endsWith(`.${ext}`))) {
|
|
54
56
|
key = key + `.${extensions[0]}`;
|
|
55
57
|
}
|
|
56
58
|
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
@@ -1 +1 @@
|
|
|
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 =>
|
|
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","lowerKey","toLowerCase","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 // We only need this variable to compare extensions in a case-insensitive way.\n const lowerKey = key.toLowerCase();\n if (!extensions.some(ext => lowerKey.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;;E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