@webiny/app-file-manager-s3 0.0.0-mt-2 → 0.0.0-unstable.1145e7667f
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 +68 -71
- package/index.js.map +1 -0
- package/package.json +10 -10
- package/types.d.ts +2 -0
- package/types.js +5 -1
- package/types.js.map +1 -0
package/index.js
CHANGED
|
@@ -1,89 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
1
|
+
"use strict";
|
|
3
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
4
12
|
var _templateObject;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import gql from "graphql-tag";
|
|
8
|
-
var GET_PRE_SIGNED_POST_PAYLOAD = gql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\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"])));
|
|
9
|
-
export default (function () {
|
|
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"])));
|
|
14
|
+
var _default = function _default() {
|
|
10
15
|
return {
|
|
11
16
|
type: "app-file-manager-storage",
|
|
12
17
|
name: "app-file-manager-storage",
|
|
13
18
|
upload: function () {
|
|
14
|
-
var _upload =
|
|
15
|
-
var apolloClient, response, getPreSignedPostPayload;
|
|
16
|
-
return
|
|
17
|
-
while (1) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: file.type
|
|
30
|
-
}
|
|
19
|
+
var _upload = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(file, _ref) {
|
|
20
|
+
var apolloClient, onProgress, response, getPreSignedPostPayload;
|
|
21
|
+
return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
|
|
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
|
|
31
34
|
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
case 3:
|
|
35
|
-
response = _context.sent;
|
|
36
|
-
getPreSignedPostPayload = response.data.fileManager.getPreSignedPostPayload;
|
|
37
|
-
|
|
38
|
-
if (!getPreSignedPostPayload.error) {
|
|
39
|
-
_context.next = 8;
|
|
40
|
-
break;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
xhr.open("POST", getPreSignedPostPayload.data.data.url, true);
|
|
59
|
-
xhr.send(formData);
|
|
60
|
-
|
|
61
|
-
xhr.onload = function () {
|
|
62
|
-
if (this.status === 204) {
|
|
63
|
-
resolve(getPreSignedPostPayload.data.file);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
reject(this.responseText);
|
|
68
|
-
};
|
|
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]);
|
|
69
52
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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();
|
|
78
76
|
}
|
|
79
77
|
}, _callee);
|
|
80
78
|
}));
|
|
81
|
-
|
|
82
79
|
function upload(_x, _x2) {
|
|
83
80
|
return _upload.apply(this, arguments);
|
|
84
81
|
}
|
|
85
|
-
|
|
86
82
|
return upload;
|
|
87
83
|
}()
|
|
88
84
|
};
|
|
89
|
-
}
|
|
85
|
+
};
|
|
86
|
+
exports.default = _default;
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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;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,CAACN,uBAAuB,CAACH,IAAI,CAACN,IAAI,CAAC;oBAC1C;kBACJ;kBAEAgB,MAAM,CAAC,IAAI,CAACsB,YAAY,CAAC;gBAC7B,CAAC;cACL,CAAC,CAAC;YAAA;cAAA;YAAA;YAAA;cAAA;UAAA;QAAA;MAAA,CACL;MAAA;QAAA;MAAA;MAAA;IAAA;EACL,CAAC;AAAA,CAA4B;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-file-manager-s3",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.1145e7667f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/plugins": "0.0.0-
|
|
13
|
+
"@webiny/plugins": "0.0.0-unstable.1145e7667f",
|
|
14
14
|
"apollo-client": "2.6.10",
|
|
15
|
-
"graphql": "
|
|
16
|
-
"graphql-tag": "2.12.
|
|
15
|
+
"graphql": "15.8.0",
|
|
16
|
+
"graphql-tag": "2.12.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/cli": "^7.
|
|
20
|
-
"@babel/core": "^7.
|
|
21
|
-
"@webiny/cli": "^0.0.0-
|
|
22
|
-
"@webiny/project-utils": "^0.0.0-
|
|
19
|
+
"@babel/cli": "^7.19.3",
|
|
20
|
+
"@babel/core": "^7.19.3",
|
|
21
|
+
"@webiny/cli": "^0.0.0-unstable.1145e7667f",
|
|
22
|
+
"@webiny/project-utils": "^0.0.0-unstable.1145e7667f",
|
|
23
23
|
"rimraf": "^3.0.2",
|
|
24
|
-
"typescript": "
|
|
24
|
+
"typescript": "4.7.4"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"build": "yarn webiny run build",
|
|
32
32
|
"watch": "yarn webiny run watch"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1145e7667ffd3d18bfea1e73d6078cd6a35c1038"
|
|
35
35
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
1
2
|
import { Plugin } from "@webiny/plugins/types";
|
|
2
3
|
import { ApolloClient } from "apollo-client";
|
|
3
4
|
export declare type AppFileManagerStorageS3 = Plugin & {
|
|
@@ -5,5 +6,6 @@ export declare type AppFileManagerStorageS3 = Plugin & {
|
|
|
5
6
|
name: "app-file-manager-storage";
|
|
6
7
|
upload(file: File, options: {
|
|
7
8
|
apolloClient: ApolloClient<Record<string, any>>;
|
|
9
|
+
onProgress?: (progress: number) => void;
|
|
8
10
|
}): Promise<any>;
|
|
9
11
|
};
|
package/types.js
CHANGED
package/types.js.map
ADDED
|
@@ -0,0 +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(\n file: File,\n options: {\n apolloClient: ApolloClient<Record<string, any>>;\n onProgress?: (progress: number) => void;\n }\n ): Promise<any>;\n};\n"],"mappings":""}
|