@webiny/app-file-manager-s3 0.0.0-ee-vpcs.549378cf03
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/LICENSE +21 -0
- package/README.md +1 -0
- package/index.d.ts +3 -0
- package/index.js +103 -0
- package/index.js.map +1 -0
- package/package.json +35 -0
- package/types.d.ts +10 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @webiny/app-file-manager-s3
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
15
|
+
|
|
16
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
17
|
+
|
|
18
|
+
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
|
+
|
|
22
|
+
var _default = function _default() {
|
|
23
|
+
return {
|
|
24
|
+
type: "app-file-manager-storage",
|
|
25
|
+
name: "app-file-manager-storage",
|
|
26
|
+
upload: function () {
|
|
27
|
+
var _upload = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(file, _ref) {
|
|
28
|
+
var apolloClient, response, getPreSignedPostPayload;
|
|
29
|
+
return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
|
|
30
|
+
while (1) {
|
|
31
|
+
switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
apolloClient = _ref.apolloClient;
|
|
34
|
+
_context.next = 3;
|
|
35
|
+
return apolloClient.query({
|
|
36
|
+
query: GET_PRE_SIGNED_POST_PAYLOAD,
|
|
37
|
+
fetchPolicy: "no-cache",
|
|
38
|
+
variables: {
|
|
39
|
+
data: {
|
|
40
|
+
size: file.size,
|
|
41
|
+
name: file.name,
|
|
42
|
+
type: file.type
|
|
43
|
+
}
|
|
44
|
+
}
|
|
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
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(getPreSignedPostPayload); // eslint-disable-line
|
|
57
|
+
|
|
58
|
+
return _context.abrupt("return");
|
|
59
|
+
|
|
60
|
+
case 8:
|
|
61
|
+
_context.next = 10;
|
|
62
|
+
return new Promise(function (resolve, reject) {
|
|
63
|
+
var formData = new window.FormData();
|
|
64
|
+
Object.keys(getPreSignedPostPayload.data.data.fields).forEach(function (key) {
|
|
65
|
+
formData.append(key, getPreSignedPostPayload.data.data.fields[key]);
|
|
66
|
+
});
|
|
67
|
+
formData.append("file", file);
|
|
68
|
+
var xhr = new window.XMLHttpRequest(); // eslint-disable-line
|
|
69
|
+
|
|
70
|
+
xhr.open("POST", getPreSignedPostPayload.data.data.url, true);
|
|
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
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
case 10:
|
|
84
|
+
return _context.abrupt("return", _context.sent);
|
|
85
|
+
|
|
86
|
+
case 11:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, _callee);
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
function upload(_x, _x2) {
|
|
95
|
+
return _upload.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return upload;
|
|
99
|
+
}()
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
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","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(); // eslint-disable-line\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;;;;AAGA,IAAMA,2BAA2B,OAAGC,mBAAH,kkBAAjC;;eAqBe;EAAA,OACV;IACGC,IAAI,EAAE,0BADT;IAEGC,IAAI,EAAE,0BAFT;IAGGC,MAAM;MAAA,qGAAE,iBAAOC,IAAP;QAAA;QAAA;UAAA;YAAA;cAAA;gBAAqBC,YAArB,QAAqBA,YAArB;gBAAA;gBAAA,OAEmBA,YAAY,CAACC,KAAb,CAAmB;kBACtCA,KAAK,EAAEP,2BAD+B;kBAEtCQ,WAAW,EAAE,UAFyB;kBAGtCC,SAAS,EAAE;oBACPC,IAAI,EAAE;sBAAEC,IAAI,EAAEN,IAAI,CAACM,IAAb;sBAAmBR,IAAI,EAAEE,IAAI,CAACF,IAA9B;sBAAoCD,IAAI,EAAEG,IAAI,CAACH;oBAA/C;kBADC;gBAH2B,CAAnB,CAFnB;;cAAA;gBAEEU,QAFF;gBAUIC,uBAVJ,GAUgCD,QAAQ,CAACF,IAAT,CAAcI,WAV9C,CAUID,uBAVJ;;gBAAA,KAWAA,uBAAuB,CAACE,KAXxB;kBAAA;kBAAA;gBAAA;;gBAYAC,OAAO,CAACC,GAAR,CAAYJ,uBAAZ,EAZA,CAYsC;;gBAZtC;;cAAA;gBAAA;gBAAA,OAgBS,IAAIK,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;kBAC1C,IAAMC,QAAQ,GAAG,IAAIC,MAAM,CAACC,QAAX,EAAjB;kBACAC,MAAM,CAACC,IAAP,CAAYZ,uBAAuB,CAACH,IAAxB,CAA6BA,IAA7B,CAAkCgB,MAA9C,EAAsDC,OAAtD,CAA8D,UAAAC,GAAG,EAAI;oBACjEP,QAAQ,CAACQ,MAAT,CAAgBD,GAAhB,EAAqBf,uBAAuB,CAACH,IAAxB,CAA6BA,IAA7B,CAAkCgB,MAAlC,CAAyCE,GAAzC,CAArB;kBACH,CAFD;kBAIAP,QAAQ,CAACQ,MAAT,CAAgB,MAAhB,EAAwBxB,IAAxB;kBAEA,IAAMyB,GAAG,GAAG,IAAIR,MAAM,CAACS,cAAX,EAAZ,CAR0C,CAQD;;kBACzCD,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBnB,uBAAuB,CAACH,IAAxB,CAA6BA,IAA7B,CAAkCuB,GAAnD,EAAwD,IAAxD;kBACAH,GAAG,CAACI,IAAJ,CAASb,QAAT;;kBACAS,GAAG,CAACK,MAAJ,GAAa,YAAY;oBACrB,IAAI,KAAKC,MAAL,KAAgB,GAApB,EAAyB;sBACrBjB,OAAO,CAACN,uBAAuB,CAACH,IAAxB,CAA6BL,IAA9B,CAAP;sBACA;oBACH;;oBAEDe,MAAM,CAAC,KAAKiB,YAAN,CAAN;kBACH,CAPD;gBAQH,CAnBY,CAhBT;;cAAA;gBAAA;;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CAAF;;MAAA;QAAA;MAAA;;MAAA;IAAA;EAHT,CADU;AAAA,C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/app-file-manager-s3",
|
|
3
|
+
"version": "0.0.0-ee-vpcs.549378cf03",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "App File storage S3 plugin for the @webiny/app-file-manager client.",
|
|
10
|
+
"author": "Webiny Ltd",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@webiny/plugins": "0.0.0-ee-vpcs.549378cf03",
|
|
14
|
+
"apollo-client": "2.6.10",
|
|
15
|
+
"graphql": "15.8.0",
|
|
16
|
+
"graphql-tag": "2.12.6"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/cli": "^7.19.3",
|
|
20
|
+
"@babel/core": "^7.19.3",
|
|
21
|
+
"@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
|
|
22
|
+
"@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
|
|
23
|
+
"rimraf": "^3.0.2",
|
|
24
|
+
"typescript": "4.7.4"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"directory": "dist"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "yarn webiny run build",
|
|
32
|
+
"watch": "yarn webiny run watch"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
|
|
35
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
2
|
+
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
+
import { ApolloClient } from "apollo-client";
|
|
4
|
+
export declare type AppFileManagerStorageS3 = Plugin & {
|
|
5
|
+
type: "app-file-manager-storage";
|
|
6
|
+
name: "app-file-manager-storage";
|
|
7
|
+
upload(file: File, options: {
|
|
8
|
+
apolloClient: ApolloClient<Record<string, any>>;
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
};
|
package/types.js
ADDED
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(file: File, options: { apolloClient: ApolloClient<Record<string, any>> }): Promise<any>;\n};\n"],"mappings":""}
|