@lowdefy/plugin-aws 4.0.2 → 4.2.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 +7 -7
- package/dist/blocks/S3UploadButton/S3UploadButton.js +0 -216
- package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.mock.test.js.snap +0 -1597
- package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.test.js.snap +0 -281
- package/dist/blocks/S3UploadButton/examples.yaml +0 -44
- package/dist/blocks/S3UploadButton/schema.json +0 -83
- package/dist/blocks/S3UploadButton/style.less +0 -18
- package/dist/blocks/S3UploadPhoto/S3UploadPhoto.js +0 -221
- package/dist/blocks/S3UploadPhoto/schema.json +0 -63
- package/dist/blocks/S3UploadPhoto/style.less +0 -17
- package/dist/blocks.js +0 -16
- package/dist/connections/AwsS3Bucket/AwsS3Bucket.js +0 -24
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/AwsS3PresignedGetObject.js +0 -41
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/schema.js +0 -64
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/AwsS3PresignedPostPolicy.js +0 -48
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/schema.js +0 -70
- package/dist/connections/AwsS3Bucket/schema.js +0 -80
- package/dist/connections.js +0 -15
- package/dist/types.js +0 -32
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Render default - value[0] 1`] = `
|
|
4
|
-
<span
|
|
5
|
-
class=""
|
|
6
|
-
>
|
|
7
|
-
<div
|
|
8
|
-
class="ant-upload ant-upload-select ant-upload-select-text"
|
|
9
|
-
>
|
|
10
|
-
<span
|
|
11
|
-
class="ant-upload"
|
|
12
|
-
role="button"
|
|
13
|
-
tabindex="0"
|
|
14
|
-
>
|
|
15
|
-
<input
|
|
16
|
-
accept=""
|
|
17
|
-
id="default"
|
|
18
|
-
multiple=""
|
|
19
|
-
style="display: none;"
|
|
20
|
-
type="file"
|
|
21
|
-
/>
|
|
22
|
-
<button
|
|
23
|
-
class="ant-btn emotion-0"
|
|
24
|
-
id="default_button"
|
|
25
|
-
type="button"
|
|
26
|
-
>
|
|
27
|
-
<svg
|
|
28
|
-
class="emotion-1"
|
|
29
|
-
data-testid="AiOutlineExclamationCircle"
|
|
30
|
-
id="default_button_icon"
|
|
31
|
-
/>
|
|
32
|
-
<span
|
|
33
|
-
class="emotion-1"
|
|
34
|
-
>
|
|
35
|
-
Upload
|
|
36
|
-
</span>
|
|
37
|
-
</button>
|
|
38
|
-
</span>
|
|
39
|
-
</div>
|
|
40
|
-
<div
|
|
41
|
-
class="ant-upload-list ant-upload-list-text"
|
|
42
|
-
/>
|
|
43
|
-
</span>
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
exports[`Render properties.accept - value[0] 1`] = `
|
|
47
|
-
<span
|
|
48
|
-
class=""
|
|
49
|
-
>
|
|
50
|
-
<div
|
|
51
|
-
class="ant-upload ant-upload-select ant-upload-select-text"
|
|
52
|
-
>
|
|
53
|
-
<span
|
|
54
|
-
class="ant-upload"
|
|
55
|
-
role="button"
|
|
56
|
-
tabindex="0"
|
|
57
|
-
>
|
|
58
|
-
<input
|
|
59
|
-
accept=".png,.jpg"
|
|
60
|
-
id="properties.accept"
|
|
61
|
-
multiple=""
|
|
62
|
-
style="display: none;"
|
|
63
|
-
type="file"
|
|
64
|
-
/>
|
|
65
|
-
<button
|
|
66
|
-
class="ant-btn emotion-0"
|
|
67
|
-
id="properties.accept_button"
|
|
68
|
-
type="button"
|
|
69
|
-
>
|
|
70
|
-
<svg
|
|
71
|
-
class="emotion-1"
|
|
72
|
-
data-testid="AiOutlineExclamationCircle"
|
|
73
|
-
id="properties.accept_button_icon"
|
|
74
|
-
/>
|
|
75
|
-
<span
|
|
76
|
-
class="emotion-1"
|
|
77
|
-
>
|
|
78
|
-
Upload
|
|
79
|
-
</span>
|
|
80
|
-
</button>
|
|
81
|
-
</span>
|
|
82
|
-
</div>
|
|
83
|
-
<div
|
|
84
|
-
class="ant-upload-list ant-upload-list-text"
|
|
85
|
-
/>
|
|
86
|
-
</span>
|
|
87
|
-
`;
|
|
88
|
-
|
|
89
|
-
exports[`Render properties.button - value[0] 1`] = `
|
|
90
|
-
<span
|
|
91
|
-
class=""
|
|
92
|
-
>
|
|
93
|
-
<div
|
|
94
|
-
class="ant-upload ant-upload-select ant-upload-select-text"
|
|
95
|
-
>
|
|
96
|
-
<span
|
|
97
|
-
class="ant-upload"
|
|
98
|
-
role="button"
|
|
99
|
-
tabindex="0"
|
|
100
|
-
>
|
|
101
|
-
<input
|
|
102
|
-
accept=""
|
|
103
|
-
id="properties.button"
|
|
104
|
-
multiple=""
|
|
105
|
-
style="display: none;"
|
|
106
|
-
type="file"
|
|
107
|
-
/>
|
|
108
|
-
<button
|
|
109
|
-
class="ant-btn ant-btn-primary emotion-0"
|
|
110
|
-
id="properties.button_button"
|
|
111
|
-
type="button"
|
|
112
|
-
>
|
|
113
|
-
<svg
|
|
114
|
-
class="emotion-1"
|
|
115
|
-
data-testid="AiOutlineExclamationCircle"
|
|
116
|
-
id="properties.button_button_icon"
|
|
117
|
-
/>
|
|
118
|
-
<span
|
|
119
|
-
class="emotion-1"
|
|
120
|
-
>
|
|
121
|
-
Upload
|
|
122
|
-
</span>
|
|
123
|
-
</button>
|
|
124
|
-
</span>
|
|
125
|
-
</div>
|
|
126
|
-
<div
|
|
127
|
-
class="ant-upload-list ant-upload-list-text"
|
|
128
|
-
/>
|
|
129
|
-
</span>
|
|
130
|
-
`;
|
|
131
|
-
|
|
132
|
-
exports[`Render properties.disabled - value[0] 1`] = `
|
|
133
|
-
<span
|
|
134
|
-
class=""
|
|
135
|
-
>
|
|
136
|
-
<div
|
|
137
|
-
class="ant-upload ant-upload-select ant-upload-select-text ant-upload-disabled"
|
|
138
|
-
>
|
|
139
|
-
<span
|
|
140
|
-
class="ant-upload ant-upload-disabled"
|
|
141
|
-
role="button"
|
|
142
|
-
>
|
|
143
|
-
<input
|
|
144
|
-
accept=""
|
|
145
|
-
multiple=""
|
|
146
|
-
style="display: none;"
|
|
147
|
-
type="file"
|
|
148
|
-
/>
|
|
149
|
-
<button
|
|
150
|
-
class="ant-btn emotion-0"
|
|
151
|
-
disabled=""
|
|
152
|
-
id="properties.disabled_button"
|
|
153
|
-
type="button"
|
|
154
|
-
>
|
|
155
|
-
<svg
|
|
156
|
-
class="emotion-1"
|
|
157
|
-
data-testid="AiOutlineExclamationCircle"
|
|
158
|
-
id="properties.disabled_button_icon"
|
|
159
|
-
/>
|
|
160
|
-
<span
|
|
161
|
-
class="emotion-1"
|
|
162
|
-
>
|
|
163
|
-
Upload
|
|
164
|
-
</span>
|
|
165
|
-
</button>
|
|
166
|
-
</span>
|
|
167
|
-
</div>
|
|
168
|
-
<div
|
|
169
|
-
class="ant-upload-list ant-upload-list-text"
|
|
170
|
-
/>
|
|
171
|
-
</span>
|
|
172
|
-
`;
|
|
173
|
-
|
|
174
|
-
exports[`Render properties.showUploadList - value[0] 1`] = `
|
|
175
|
-
<span
|
|
176
|
-
class=""
|
|
177
|
-
>
|
|
178
|
-
<div
|
|
179
|
-
class="ant-upload ant-upload-select ant-upload-select-text"
|
|
180
|
-
>
|
|
181
|
-
<span
|
|
182
|
-
class="ant-upload"
|
|
183
|
-
role="button"
|
|
184
|
-
tabindex="0"
|
|
185
|
-
>
|
|
186
|
-
<input
|
|
187
|
-
accept=""
|
|
188
|
-
id="properties.showUploadList"
|
|
189
|
-
multiple=""
|
|
190
|
-
style="display: none;"
|
|
191
|
-
type="file"
|
|
192
|
-
/>
|
|
193
|
-
<button
|
|
194
|
-
class="ant-btn emotion-0"
|
|
195
|
-
id="properties.showUploadList_button"
|
|
196
|
-
type="button"
|
|
197
|
-
>
|
|
198
|
-
<svg
|
|
199
|
-
class="emotion-1"
|
|
200
|
-
data-testid="AiOutlineExclamationCircle"
|
|
201
|
-
id="properties.showUploadList_button_icon"
|
|
202
|
-
/>
|
|
203
|
-
<span
|
|
204
|
-
class="emotion-1"
|
|
205
|
-
>
|
|
206
|
-
Upload
|
|
207
|
-
</span>
|
|
208
|
-
</button>
|
|
209
|
-
</span>
|
|
210
|
-
</div>
|
|
211
|
-
<div
|
|
212
|
-
class="ant-upload-list ant-upload-list-text"
|
|
213
|
-
/>
|
|
214
|
-
</span>
|
|
215
|
-
`;
|
|
216
|
-
|
|
217
|
-
exports[`Render properties.singleFile - value[0] 1`] = `
|
|
218
|
-
<span
|
|
219
|
-
class=""
|
|
220
|
-
>
|
|
221
|
-
<div
|
|
222
|
-
class="ant-upload ant-upload-select ant-upload-select-text"
|
|
223
|
-
>
|
|
224
|
-
<span
|
|
225
|
-
class="ant-upload"
|
|
226
|
-
role="button"
|
|
227
|
-
tabindex="0"
|
|
228
|
-
>
|
|
229
|
-
<input
|
|
230
|
-
accept=""
|
|
231
|
-
id="properties.singleFile"
|
|
232
|
-
style="display: none;"
|
|
233
|
-
type="file"
|
|
234
|
-
/>
|
|
235
|
-
<button
|
|
236
|
-
class="ant-btn emotion-0"
|
|
237
|
-
id="properties.singleFile_button"
|
|
238
|
-
type="button"
|
|
239
|
-
>
|
|
240
|
-
<svg
|
|
241
|
-
class="emotion-1"
|
|
242
|
-
data-testid="AiOutlineExclamationCircle"
|
|
243
|
-
id="properties.singleFile_button_icon"
|
|
244
|
-
/>
|
|
245
|
-
<span
|
|
246
|
-
class="emotion-1"
|
|
247
|
-
>
|
|
248
|
-
Upload
|
|
249
|
-
</span>
|
|
250
|
-
</button>
|
|
251
|
-
</span>
|
|
252
|
-
</div>
|
|
253
|
-
<div
|
|
254
|
-
class="ant-upload-list ant-upload-list-text"
|
|
255
|
-
/>
|
|
256
|
-
</span>
|
|
257
|
-
`;
|
|
258
|
-
|
|
259
|
-
exports[`Test Schema default 1`] = `true`;
|
|
260
|
-
|
|
261
|
-
exports[`Test Schema default 2`] = `null`;
|
|
262
|
-
|
|
263
|
-
exports[`Test Schema properties.accept 1`] = `true`;
|
|
264
|
-
|
|
265
|
-
exports[`Test Schema properties.accept 2`] = `null`;
|
|
266
|
-
|
|
267
|
-
exports[`Test Schema properties.button 1`] = `true`;
|
|
268
|
-
|
|
269
|
-
exports[`Test Schema properties.button 2`] = `null`;
|
|
270
|
-
|
|
271
|
-
exports[`Test Schema properties.disabled 1`] = `true`;
|
|
272
|
-
|
|
273
|
-
exports[`Test Schema properties.disabled 2`] = `null`;
|
|
274
|
-
|
|
275
|
-
exports[`Test Schema properties.showUploadList 1`] = `true`;
|
|
276
|
-
|
|
277
|
-
exports[`Test Schema properties.showUploadList 2`] = `null`;
|
|
278
|
-
|
|
279
|
-
exports[`Test Schema properties.singleFile 1`] = `true`;
|
|
280
|
-
|
|
281
|
-
exports[`Test Schema properties.singleFile 2`] = `null`;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Copyright 2020-2024 Lowdefy, Inc
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
- id: default
|
|
16
|
-
type: S3UploadButton
|
|
17
|
-
properties:
|
|
18
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
19
|
-
- id: properties.accept
|
|
20
|
-
type: S3UploadButton
|
|
21
|
-
properties:
|
|
22
|
-
accept: '.png,.jpg'
|
|
23
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
24
|
-
- id: properties.button
|
|
25
|
-
type: S3UploadButton
|
|
26
|
-
properties:
|
|
27
|
-
button:
|
|
28
|
-
type: primary
|
|
29
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
30
|
-
- id: properties.disabled
|
|
31
|
-
type: S3UploadButton
|
|
32
|
-
properties:
|
|
33
|
-
disabled: true
|
|
34
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
35
|
-
- id: properties.showUploadList
|
|
36
|
-
type: S3UploadButton
|
|
37
|
-
properties:
|
|
38
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
39
|
-
showUploadList: true
|
|
40
|
-
- id: properties.singleFile
|
|
41
|
-
type: S3UploadButton
|
|
42
|
-
properties:
|
|
43
|
-
s3PostPolicyRequestId: s3PostPolicyRequestId
|
|
44
|
-
singleFile: true
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "object",
|
|
3
|
-
"properties": {
|
|
4
|
-
"type": "object",
|
|
5
|
-
"required": ["s3PostPolicyRequestId"],
|
|
6
|
-
"properties": {
|
|
7
|
-
"accept": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "File types accepted by the input. See html file type input accept property at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept."
|
|
10
|
-
},
|
|
11
|
-
"button": {
|
|
12
|
-
"type": "object",
|
|
13
|
-
"description": "Button block properties.",
|
|
14
|
-
"default": {
|
|
15
|
-
"icon": "UploadOutlined",
|
|
16
|
-
"title": "Upload",
|
|
17
|
-
"type": "default"
|
|
18
|
-
},
|
|
19
|
-
"docs": {
|
|
20
|
-
"displayType": "button"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"disabled": {
|
|
24
|
-
"type": "boolean",
|
|
25
|
-
"description": "Disable the file input."
|
|
26
|
-
},
|
|
27
|
-
"s3PostPolicyRequestId": {
|
|
28
|
-
"type": "string",
|
|
29
|
-
"description": "Id of a request of type AwsS3PresignedPostPolicy that defines to which S3 bucket and how the file should be uploaded.",
|
|
30
|
-
"docs": {
|
|
31
|
-
"displayType": "manual",
|
|
32
|
-
"block": {
|
|
33
|
-
"id": "block_properties_s3PostPolicyRequestId",
|
|
34
|
-
"layout": { "_global": "settings_input_layout" },
|
|
35
|
-
"type": "Label",
|
|
36
|
-
"required": true,
|
|
37
|
-
"properties": {
|
|
38
|
-
"title": "s3PostPolicyRequestId",
|
|
39
|
-
"span": 8,
|
|
40
|
-
"align": "right"
|
|
41
|
-
},
|
|
42
|
-
"blocks": [
|
|
43
|
-
{
|
|
44
|
-
"id": "block_properties_s3PostPolicyRequestId_text",
|
|
45
|
-
"type": "Markdown",
|
|
46
|
-
"style": {
|
|
47
|
-
"color": "#8c8c8c"
|
|
48
|
-
},
|
|
49
|
-
"properties": {
|
|
50
|
-
"content": "Id of a request of type AwsS3PresignedPostPolicy that defines to which S3 bucket and how the file should be uploaded."
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
},
|
|
55
|
-
"getter": {}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"showUploadList": {
|
|
59
|
-
"type": "boolean",
|
|
60
|
-
"default": true,
|
|
61
|
-
"description": "Whether to show default upload list."
|
|
62
|
-
},
|
|
63
|
-
"singleFile": {
|
|
64
|
-
"type": "boolean",
|
|
65
|
-
"default": false,
|
|
66
|
-
"description": "Only allow a single file to be uploaded. Only one file can be selected in the prompt and the upload button is disabled after a file is uploaded."
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
"events": {
|
|
71
|
-
"type": "object",
|
|
72
|
-
"properties": {
|
|
73
|
-
"onChange": {
|
|
74
|
-
"type": "array",
|
|
75
|
-
"description": "Triggered when the upload state is changing."
|
|
76
|
-
},
|
|
77
|
-
"onClick": {
|
|
78
|
-
"type": "array",
|
|
79
|
-
"description": "Triggered when the upload button is clicked."
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
@import 'antd/lib/upload/style/index.less';
|
|
18
|
-
@import 'antd/lib/button/style/index.less';
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import React, { useEffect, useState } from 'react';
|
|
16
|
-
import { blockDefaultProps } from '@lowdefy/block-utils';
|
|
17
|
-
import { get } from '@lowdefy/helpers';
|
|
18
|
-
import { Upload } from 'antd';
|
|
19
|
-
const makeFileValue = (file, s3Parameters)=>{
|
|
20
|
-
const { lastModified, name, percent, size, status, type, uid } = file;
|
|
21
|
-
const { bucket, key } = get(s3Parameters, uid, {
|
|
22
|
-
default: {}
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
bucket,
|
|
26
|
-
key,
|
|
27
|
-
lastModified,
|
|
28
|
-
name,
|
|
29
|
-
percent,
|
|
30
|
-
size,
|
|
31
|
-
status,
|
|
32
|
-
type,
|
|
33
|
-
uid
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const makeOnChangeValue = (s3Parameters, changeEvent)=>{
|
|
37
|
-
const { file, fileList } = changeEvent;
|
|
38
|
-
return {
|
|
39
|
-
file: makeFileValue(file, s3Parameters),
|
|
40
|
-
fileList: fileList.map((fl)=>makeFileValue(fl, s3Parameters))
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const getCustomRequest = ({ methods, setS3Parameters, setLoading })=>async ({ file, onError, onProgress, onSuccess })=>{
|
|
44
|
-
let meta;
|
|
45
|
-
try {
|
|
46
|
-
setLoading(true);
|
|
47
|
-
const { name, size, type, uid } = file;
|
|
48
|
-
if (size > 1024 * 1024 * 10) throw new Error('File cannot exceed 10mb.');
|
|
49
|
-
const s3PostPolicyResponse = await methods.triggerEvent({
|
|
50
|
-
name: '__getS3PostPolicy',
|
|
51
|
-
event: {
|
|
52
|
-
filename: name,
|
|
53
|
-
size,
|
|
54
|
-
type,
|
|
55
|
-
uid
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
if (s3PostPolicyResponse.success !== true) {
|
|
59
|
-
throw new Error('S3 post policy request error.');
|
|
60
|
-
}
|
|
61
|
-
const { url, fields } = s3PostPolicyResponse.responses.__getS3PostPolicy.response[0];
|
|
62
|
-
const { bucket, key } = fields;
|
|
63
|
-
meta = {
|
|
64
|
-
bucket,
|
|
65
|
-
key,
|
|
66
|
-
filename: name,
|
|
67
|
-
size,
|
|
68
|
-
type,
|
|
69
|
-
uid
|
|
70
|
-
};
|
|
71
|
-
setS3Parameters((prevState)=>{
|
|
72
|
-
const ret = {
|
|
73
|
-
...prevState
|
|
74
|
-
};
|
|
75
|
-
ret[uid] = {
|
|
76
|
-
bucket,
|
|
77
|
-
key
|
|
78
|
-
};
|
|
79
|
-
return ret;
|
|
80
|
-
});
|
|
81
|
-
// Set 20 % progress on policy is acquired else user waits to long before progress is reported
|
|
82
|
-
onProgress({
|
|
83
|
-
percent: 20
|
|
84
|
-
});
|
|
85
|
-
// Create FormData with all required fields in S3 policy
|
|
86
|
-
const formData = new FormData();
|
|
87
|
-
Object.keys(fields).forEach((field)=>{
|
|
88
|
-
formData.append(field, fields[field]);
|
|
89
|
-
});
|
|
90
|
-
// file needs to be the last field in the form
|
|
91
|
-
formData.append('file', file);
|
|
92
|
-
const xhr = new XMLHttpRequest();
|
|
93
|
-
xhr.upload.onprogress = (event)=>{
|
|
94
|
-
if (event.lengthComputable) {
|
|
95
|
-
onProgress({
|
|
96
|
-
percent: event.loaded / event.total * 80 + 20
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
xhr.addEventListener('error', async (event)=>{
|
|
101
|
-
await methods.triggerEvent({
|
|
102
|
-
name: 'onError',
|
|
103
|
-
event: {
|
|
104
|
-
meta,
|
|
105
|
-
event
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
onError(event);
|
|
109
|
-
});
|
|
110
|
-
xhr.addEventListener('load', async (event)=>{
|
|
111
|
-
await methods.triggerEvent({
|
|
112
|
-
name: 'onSuccess',
|
|
113
|
-
event: {
|
|
114
|
-
meta,
|
|
115
|
-
event
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
onSuccess(event);
|
|
119
|
-
});
|
|
120
|
-
xhr.addEventListener('loadend', async (event)=>{
|
|
121
|
-
await methods.triggerEvent({
|
|
122
|
-
name: 'onDone',
|
|
123
|
-
event: {
|
|
124
|
-
meta,
|
|
125
|
-
event
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
setLoading(false);
|
|
129
|
-
});
|
|
130
|
-
xhr.open('post', url);
|
|
131
|
-
xhr.send(formData);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error(error);
|
|
134
|
-
await methods.triggerEvent({
|
|
135
|
-
name: 'onError',
|
|
136
|
-
event: {
|
|
137
|
-
meta,
|
|
138
|
-
error
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
onError(error);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const S3UploadPhoto = ({ blockId, components: { Icon }, events, methods, properties, value })=>{
|
|
145
|
-
// Use state here because we need to set s3 bucket and key as block value
|
|
146
|
-
// The customRequest function does not have access to the updated block value,
|
|
147
|
-
// so it cannot set the value directly. customRequest sets the parameters to s3Parameters state,
|
|
148
|
-
// and then onChange updates the block value.
|
|
149
|
-
const [s3Parameters, setS3Parameters] = useState(value);
|
|
150
|
-
const [loading, setLoading] = useState(false);
|
|
151
|
-
const customRequest = getCustomRequest({
|
|
152
|
-
methods,
|
|
153
|
-
setS3Parameters,
|
|
154
|
-
setLoading
|
|
155
|
-
});
|
|
156
|
-
useEffect(()=>{
|
|
157
|
-
methods.setValue({
|
|
158
|
-
file: null,
|
|
159
|
-
fileList: []
|
|
160
|
-
});
|
|
161
|
-
methods.registerEvent({
|
|
162
|
-
name: '__getS3PostPolicy',
|
|
163
|
-
actions: [
|
|
164
|
-
{
|
|
165
|
-
id: '__getS3PostPolicy',
|
|
166
|
-
type: 'Request',
|
|
167
|
-
params: [
|
|
168
|
-
properties.s3PostPolicyRequestId
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
}, []);
|
|
174
|
-
return /*#__PURE__*/ React.createElement(Upload, {
|
|
175
|
-
listType: "picture-card",
|
|
176
|
-
className: "avatar-uploader",
|
|
177
|
-
accept: "image/*",
|
|
178
|
-
customRequest: customRequest,
|
|
179
|
-
maxCount: 1,
|
|
180
|
-
id: blockId,
|
|
181
|
-
multiple: !properties.singleFile,
|
|
182
|
-
showUploadList: properties.showUploadList,
|
|
183
|
-
onChange: (event)=>{
|
|
184
|
-
methods.setValue(makeOnChangeValue(s3Parameters, event));
|
|
185
|
-
methods.triggerEvent({
|
|
186
|
-
name: 'onChange'
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}, /*#__PURE__*/ React.createElement("div", null, loading ? /*#__PURE__*/ React.createElement(Icon, {
|
|
190
|
-
blockId: `${blockId}_icon`,
|
|
191
|
-
events: events,
|
|
192
|
-
properties: {
|
|
193
|
-
name: 'AiOutlineLoading',
|
|
194
|
-
size: 24
|
|
195
|
-
}
|
|
196
|
-
}) : /*#__PURE__*/ React.createElement(Icon, {
|
|
197
|
-
blockId: `${blockId}_icon`,
|
|
198
|
-
events: events,
|
|
199
|
-
properties: {
|
|
200
|
-
name: 'AiOutlineCamera',
|
|
201
|
-
size: 24
|
|
202
|
-
}
|
|
203
|
-
}), /*#__PURE__*/ React.createElement("div", {
|
|
204
|
-
style: {
|
|
205
|
-
marginTop: 8
|
|
206
|
-
}
|
|
207
|
-
}, "Upload a photo")));
|
|
208
|
-
};
|
|
209
|
-
S3UploadPhoto.defaultProps = blockDefaultProps;
|
|
210
|
-
S3UploadPhoto.meta = {
|
|
211
|
-
valueType: 'object',
|
|
212
|
-
category: 'input',
|
|
213
|
-
icons: [
|
|
214
|
-
'AiOutlineLoading',
|
|
215
|
-
'AiOutlineCamera'
|
|
216
|
-
],
|
|
217
|
-
styles: [
|
|
218
|
-
'blocks/S3UploadPhoto/style.less'
|
|
219
|
-
]
|
|
220
|
-
};
|
|
221
|
-
export default S3UploadPhoto;
|