@webiny/app-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.js +53 -70
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/types.d.ts +1 -0
- package/types.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,103 +1,86 @@
|
|
|
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 _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
11
|
-
|
|
12
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
15
|
-
|
|
16
11
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
17
|
-
|
|
18
12
|
var _templateObject;
|
|
19
|
-
|
|
20
|
-
var GET_PRE_SIGNED_POST_PAYLOAD = (0, _graphqlTag.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n query getPreSignedPostPayload($data: PreSignedPostPayloadInput!) {\n fileManager {\n getPreSignedPostPayload(data: $data) {\n data {\n data\n file {\n type\n name\n size\n key\n }\n }\n error {\n message\n }\n }\n }\n }\n"])));
|
|
21
|
-
|
|
13
|
+
var GET_PRE_SIGNED_POST_PAYLOAD = (0, _graphqlTag.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n query getPreSignedPostPayload($data: PreSignedPostPayloadInput!) {\n fileManager {\n getPreSignedPostPayload(data: $data) {\n data {\n data\n file {\n id\n type\n name\n size\n key\n }\n }\n error {\n message\n }\n }\n }\n }\n"])));
|
|
22
14
|
var _default = function _default() {
|
|
23
15
|
return {
|
|
24
16
|
type: "app-file-manager-storage",
|
|
25
17
|
name: "app-file-manager-storage",
|
|
26
18
|
upload: function () {
|
|
27
19
|
var _upload = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(file, _ref) {
|
|
28
|
-
var apolloClient, response, getPreSignedPostPayload;
|
|
20
|
+
var apolloClient, onProgress, response, getPreSignedPostPayload;
|
|
29
21
|
return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
|
|
30
|
-
while (1) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type: file.type
|
|
43
|
-
}
|
|
22
|
+
while (1) switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
apolloClient = _ref.apolloClient, onProgress = _ref.onProgress;
|
|
25
|
+
_context.next = 3;
|
|
26
|
+
return apolloClient.query({
|
|
27
|
+
query: GET_PRE_SIGNED_POST_PAYLOAD,
|
|
28
|
+
fetchPolicy: "no-cache",
|
|
29
|
+
variables: {
|
|
30
|
+
data: {
|
|
31
|
+
size: file.size,
|
|
32
|
+
name: file.name,
|
|
33
|
+
type: file.type
|
|
44
34
|
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
case 3:
|
|
48
|
-
response = _context.sent;
|
|
49
|
-
getPreSignedPostPayload = response.data.fileManager.getPreSignedPostPayload;
|
|
50
|
-
|
|
51
|
-
if (!getPreSignedPostPayload.error) {
|
|
52
|
-
_context.next = 8;
|
|
53
|
-
break;
|
|
54
35
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
xhr.send(formData);
|
|
72
|
-
|
|
73
|
-
xhr.onload = function () {
|
|
74
|
-
if (this.status === 204) {
|
|
75
|
-
resolve(getPreSignedPostPayload.data.file);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
reject(this.responseText);
|
|
80
|
-
};
|
|
36
|
+
});
|
|
37
|
+
case 3:
|
|
38
|
+
response = _context.sent;
|
|
39
|
+
getPreSignedPostPayload = response.data.fileManager.getPreSignedPostPayload;
|
|
40
|
+
if (!getPreSignedPostPayload.error) {
|
|
41
|
+
_context.next = 8;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
console.log(getPreSignedPostPayload); // eslint-disable-line
|
|
45
|
+
return _context.abrupt("return");
|
|
46
|
+
case 8:
|
|
47
|
+
_context.next = 10;
|
|
48
|
+
return new Promise(function (resolve, reject) {
|
|
49
|
+
var formData = new window.FormData();
|
|
50
|
+
Object.keys(getPreSignedPostPayload.data.data.fields).forEach(function (key) {
|
|
51
|
+
formData.append(key, getPreSignedPostPayload.data.data.fields[key]);
|
|
81
52
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
53
|
+
formData.append("file", file);
|
|
54
|
+
var xhr = new window.XMLHttpRequest();
|
|
55
|
+
xhr.upload.addEventListener("progress", function (event) {
|
|
56
|
+
var percent = 100 * event.loaded / event.total;
|
|
57
|
+
if (onProgress) {
|
|
58
|
+
onProgress(percent);
|
|
59
|
+
}
|
|
60
|
+
}, false);
|
|
61
|
+
xhr.open("POST", getPreSignedPostPayload.data.data.url, true);
|
|
62
|
+
xhr.send(formData);
|
|
63
|
+
xhr.onload = function () {
|
|
64
|
+
if (this.status === 204) {
|
|
65
|
+
resolve(getPreSignedPostPayload.data.file);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
reject(this.responseText);
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
case 10:
|
|
72
|
+
return _context.abrupt("return", _context.sent);
|
|
73
|
+
case 11:
|
|
74
|
+
case "end":
|
|
75
|
+
return _context.stop();
|
|
90
76
|
}
|
|
91
77
|
}, _callee);
|
|
92
78
|
}));
|
|
93
|
-
|
|
94
79
|
function upload(_x, _x2) {
|
|
95
80
|
return _upload.apply(this, arguments);
|
|
96
81
|
}
|
|
97
|
-
|
|
98
82
|
return upload;
|
|
99
83
|
}()
|
|
100
84
|
};
|
|
101
85
|
};
|
|
102
|
-
|
|
103
86
|
exports.default = _default;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GET_PRE_SIGNED_POST_PAYLOAD","gql","type","name","upload","file","apolloClient","query","fetchPolicy","variables","data","size","response","getPreSignedPostPayload","fileManager","error","console","log","Promise","resolve","reject","formData","window","FormData","Object","keys","fields","forEach","key","append","xhr","XMLHttpRequest","open","url","send","onload","status","responseText"],"sources":["index.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { AppFileManagerStorageS3 } from \"./types\";\n\nconst GET_PRE_SIGNED_POST_PAYLOAD = gql`\n query getPreSignedPostPayload($data: PreSignedPostPayloadInput!) {\n fileManager {\n getPreSignedPostPayload(data: $data) {\n data {\n data\n file {\n type\n name\n size\n key\n }\n }\n error {\n message\n }\n }\n }\n }\n`;\n\nexport default () =>\n ({\n type: \"app-file-manager-storage\",\n name: \"app-file-manager-storage\",\n upload: async (file: File, { apolloClient }) => {\n // 1. GET PreSignedPostPayload\n const response = await apolloClient.query({\n query: GET_PRE_SIGNED_POST_PAYLOAD,\n fetchPolicy: \"no-cache\",\n variables: {\n data: { size: file.size, name: file.name, type: file.type }\n }\n });\n\n const { getPreSignedPostPayload } = response.data.fileManager;\n if (getPreSignedPostPayload.error) {\n console.log(getPreSignedPostPayload); // eslint-disable-line\n return;\n }\n // 2. upload file to S3\n return await new Promise((resolve, reject) => {\n const formData = new window.FormData();\n Object.keys(getPreSignedPostPayload.data.data.fields).forEach(key => {\n formData.append(key, getPreSignedPostPayload.data.data.fields[key]);\n });\n\n formData.append(\"file\", file);\n\n const xhr = new window.XMLHttpRequest()
|
|
1
|
+
{"version":3,"names":["GET_PRE_SIGNED_POST_PAYLOAD","gql","type","name","upload","file","apolloClient","onProgress","query","fetchPolicy","variables","data","size","response","getPreSignedPostPayload","fileManager","error","console","log","Promise","resolve","reject","formData","window","FormData","Object","keys","fields","forEach","key","append","xhr","XMLHttpRequest","addEventListener","event","percent","loaded","total","open","url","send","onload","status","responseText"],"sources":["index.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { AppFileManagerStorageS3 } from \"./types\";\n\nconst GET_PRE_SIGNED_POST_PAYLOAD = gql`\n query getPreSignedPostPayload($data: PreSignedPostPayloadInput!) {\n fileManager {\n getPreSignedPostPayload(data: $data) {\n data {\n data\n file {\n id\n type\n name\n size\n key\n }\n }\n error {\n message\n }\n }\n }\n }\n`;\n\nexport default () =>\n ({\n type: \"app-file-manager-storage\",\n name: \"app-file-manager-storage\",\n upload: async (file: File, { apolloClient, onProgress }) => {\n // 1. GET PreSignedPostPayload\n const response = await apolloClient.query({\n query: GET_PRE_SIGNED_POST_PAYLOAD,\n fetchPolicy: \"no-cache\",\n variables: {\n data: { size: file.size, name: file.name, type: file.type }\n }\n });\n\n const { getPreSignedPostPayload } = response.data.fileManager;\n if (getPreSignedPostPayload.error) {\n console.log(getPreSignedPostPayload); // eslint-disable-line\n return;\n }\n // 2. upload file to S3\n return await new Promise((resolve, reject) => {\n const formData = new window.FormData();\n Object.keys(getPreSignedPostPayload.data.data.fields).forEach(key => {\n formData.append(key, getPreSignedPostPayload.data.data.fields[key]);\n });\n\n formData.append(\"file\", file);\n\n const xhr = new window.XMLHttpRequest();\n xhr.upload.addEventListener(\n \"progress\",\n event => {\n const percent = (100 * event.loaded) / event.total;\n if (onProgress) {\n onProgress(percent);\n }\n },\n false\n );\n xhr.open(\"POST\", getPreSignedPostPayload.data.data.url, true);\n xhr.send(formData);\n xhr.onload = function () {\n if (this.status === 204) {\n resolve(getPreSignedPostPayload.data.file);\n return;\n }\n\n reject(this.responseText);\n };\n });\n }\n } as AppFileManagerStorageS3);\n"],"mappings":";;;;;;;;;;AAAA;AAA8B;AAG9B,IAAMA,2BAA2B,OAAGC,mBAAG,8lBAoBtC;AAAC,eAEa;EAAA,OACV;IACGC,IAAI,EAAE,0BAA0B;IAChCC,IAAI,EAAE,0BAA0B;IAChCC,MAAM;MAAA,qGAAE,iBAAOC,IAAU;QAAA;QAAA;UAAA;YAAA;cAAIC,YAAY,QAAZA,YAAY,EAAEC,UAAU,QAAVA,UAAU;cAAA;cAAA,OAE1BD,YAAY,CAACE,KAAK,CAAC;gBACtCA,KAAK,EAAER,2BAA2B;gBAClCS,WAAW,EAAE,UAAU;gBACvBC,SAAS,EAAE;kBACPC,IAAI,EAAE;oBAAEC,IAAI,EAAEP,IAAI,CAACO,IAAI;oBAAET,IAAI,EAAEE,IAAI,CAACF,IAAI;oBAAED,IAAI,EAAEG,IAAI,CAACH;kBAAK;gBAC9D;cACJ,CAAC,CAAC;YAAA;cANIW,QAAQ;cAQNC,uBAAuB,GAAKD,QAAQ,CAACF,IAAI,CAACI,WAAW,CAArDD,uBAAuB;cAAA,KAC3BA,uBAAuB,CAACE,KAAK;gBAAA;gBAAA;cAAA;cAC7BC,OAAO,CAACC,GAAG,CAACJ,uBAAuB,CAAC,CAAC,CAAC;cAAA;YAAA;cAAA;cAAA,OAI7B,IAAIK,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;gBAC1C,IAAMC,QAAQ,GAAG,IAAIC,MAAM,CAACC,QAAQ,EAAE;gBACtCC,MAAM,CAACC,IAAI,CAACZ,uBAAuB,CAACH,IAAI,CAACA,IAAI,CAACgB,MAAM,CAAC,CAACC,OA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
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/plugins": "5.
|
|
13
|
+
"@webiny/plugins": "5.35.0-beta.0",
|
|
14
14
|
"apollo-client": "2.6.10",
|
|
15
15
|
"graphql": "15.8.0",
|
|
16
16
|
"graphql-tag": "2.12.6"
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@babel/cli": "^7.19.3",
|
|
20
20
|
"@babel/core": "^7.19.3",
|
|
21
|
-
"@webiny/cli": "^5.
|
|
22
|
-
"@webiny/project-utils": "^5.
|
|
21
|
+
"@webiny/cli": "^5.35.0-beta.0",
|
|
22
|
+
"@webiny/project-utils": "^5.35.0-beta.0",
|
|
23
23
|
"rimraf": "^3.0.2",
|
|
24
24
|
"typescript": "4.7.4"
|
|
25
25
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"build": "yarn webiny run build",
|
|
32
32
|
"watch": "yarn webiny run watch"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8acc9e8892842cabb3980ce0b6432fde55968d5b"
|
|
35
35
|
}
|
package/types.d.ts
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\nimport { ApolloClient } from \"apollo-client\";\n\nexport type AppFileManagerStorageS3 = Plugin & {\n type: \"app-file-manager-storage\";\n name: \"app-file-manager-storage\";\n upload(file: File
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\nimport { ApolloClient } from \"apollo-client\";\n\nexport type AppFileManagerStorageS3 = Plugin & {\n type: \"app-file-manager-storage\";\n name: \"app-file-manager-storage\";\n upload(\n file: File,\n options: {\n apolloClient: ApolloClient<Record<string, any>>;\n onProgress?: (progress: number) => void;\n }\n ): Promise<any>;\n};\n"],"mappings":""}
|