@lowdefy/plugin-aws 4.2.0 → 4.2.1
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/dist/blocks/S3Download/S3Download.js +70 -0
- package/dist/blocks/S3Download/schema.json +85 -0
- package/dist/blocks/S3Download/style.less +17 -0
- package/dist/blocks/S3UploadButton/S3UploadButton.js +97 -0
- package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.mock.test.js.snap +1597 -0
- package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.test.js.snap +281 -0
- package/dist/blocks/S3UploadButton/examples.yaml +44 -0
- package/dist/blocks/S3UploadButton/schema.json +87 -0
- package/dist/blocks/S3UploadButton/style.less +18 -0
- package/dist/blocks/S3UploadDragger/S3UploadDragger.js +101 -0
- package/dist/blocks/S3UploadDragger/schema.json +81 -0
- package/dist/blocks/S3UploadDragger/style.less +17 -0
- package/dist/blocks/S3UploadPhoto/S3UploadPhoto.js +114 -0
- package/dist/blocks/S3UploadPhoto/schema.json +79 -0
- package/dist/blocks/S3UploadPhoto/style.less +17 -0
- package/dist/blocks/utils/getOnPaste.js +48 -0
- package/dist/blocks/utils/getS3Upload.js +81 -0
- package/dist/blocks/utils/useFileList.js +115 -0
- package/dist/blocks.js +18 -0
- package/dist/connections/AwsS3Bucket/AwsS3Bucket.js +24 -0
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/AwsS3PresignedGetObject.js +41 -0
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/schema.js +64 -0
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/AwsS3PresignedPostPolicy.js +57 -0
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/schema.js +70 -0
- package/dist/connections/AwsS3Bucket/schema.js +80 -0
- package/dist/connections.js +15 -0
- package/dist/types.js +32 -0
- package/package.json +7 -7
|
@@ -0,0 +1,70 @@
|
|
|
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 } from 'react';
|
|
16
|
+
import { Upload } from 'antd';
|
|
17
|
+
import { blockDefaultProps } from '@lowdefy/block-utils';
|
|
18
|
+
const downloadFile = async ({ file, methods })=>{
|
|
19
|
+
const s3DownloadPolicy = await methods.triggerEvent({
|
|
20
|
+
name: '__getS3DownloadPolicy',
|
|
21
|
+
event: {
|
|
22
|
+
file
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
window.open(s3DownloadPolicy?.responses?.__getS3DownloadPolicy?.response?.[0]);
|
|
26
|
+
};
|
|
27
|
+
const S3Download = ({ blockId, methods, properties })=>{
|
|
28
|
+
useEffect(()=>{
|
|
29
|
+
methods.registerEvent({
|
|
30
|
+
name: '__getS3DownloadPolicy',
|
|
31
|
+
actions: [
|
|
32
|
+
{
|
|
33
|
+
id: '__getS3DownloadPolicy',
|
|
34
|
+
type: 'Request',
|
|
35
|
+
params: [
|
|
36
|
+
properties.s3GetPolicyRequestId
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
}, []);
|
|
42
|
+
return /*#__PURE__*/ React.createElement(Upload, {
|
|
43
|
+
id: blockId,
|
|
44
|
+
className: methods.makeCssClass([
|
|
45
|
+
properties.style
|
|
46
|
+
]),
|
|
47
|
+
fileList: properties.fileList ?? [],
|
|
48
|
+
onPreview: async (file)=>await downloadFile({
|
|
49
|
+
file,
|
|
50
|
+
methods
|
|
51
|
+
}),
|
|
52
|
+
showUploadList: {
|
|
53
|
+
showRemoveIcon: false,
|
|
54
|
+
showDownloadIcon: true
|
|
55
|
+
},
|
|
56
|
+
onDownload: async (file)=>await downloadFile({
|
|
57
|
+
file,
|
|
58
|
+
methods
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
S3Download.defaultProps = blockDefaultProps;
|
|
63
|
+
S3Download.meta = {
|
|
64
|
+
category: 'display',
|
|
65
|
+
icons: [],
|
|
66
|
+
styles: [
|
|
67
|
+
'blocks/S3Download/style.less'
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
export default S3Download;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"properties": {
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["s3GetPolicyRequestId"],
|
|
6
|
+
"properties": {
|
|
7
|
+
"fileList": {
|
|
8
|
+
"type": "array",
|
|
9
|
+
"description": "List of files to be downloaded. If files were uploaded using an S3Upload block, the fileList value can just be mapped to this field.",
|
|
10
|
+
"items": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"required": ["key"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"key": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "S3 file key."
|
|
17
|
+
},
|
|
18
|
+
"lastModified": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "File last modified date."
|
|
21
|
+
},
|
|
22
|
+
"name": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "File name."
|
|
25
|
+
},
|
|
26
|
+
"size": {
|
|
27
|
+
"type": "number",
|
|
28
|
+
"description": "File size in bytes."
|
|
29
|
+
},
|
|
30
|
+
"type": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "File MIME type."
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"s3GetPolicyRequestId": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Id of a request of type s3GetPolicyRequestId that defines to which S3 bucket and what file should be downloaded.",
|
|
40
|
+
"docs": {
|
|
41
|
+
"displayType": "manual",
|
|
42
|
+
"block": {
|
|
43
|
+
"id": "block_properties_s3GetPolicyRequestId",
|
|
44
|
+
"layout": { "_global": "settings_input_layout" },
|
|
45
|
+
"type": "Label",
|
|
46
|
+
"required": true,
|
|
47
|
+
"properties": {
|
|
48
|
+
"title": "s3GetPolicyRequestId",
|
|
49
|
+
"span": 8,
|
|
50
|
+
"align": "right"
|
|
51
|
+
},
|
|
52
|
+
"blocks": [
|
|
53
|
+
{
|
|
54
|
+
"id": "block_properties_s3GetPolicyRequestId_text",
|
|
55
|
+
"type": "Markdown",
|
|
56
|
+
"style": {
|
|
57
|
+
"color": "#8c8c8c"
|
|
58
|
+
},
|
|
59
|
+
"properties": {
|
|
60
|
+
"content": "Id of a request of type AwsS3PresignedGetPolicy that defines to which S3 bucket and what file should be downloaded."
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"style": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"description": "Css style object to applied to download component.",
|
|
70
|
+
"docs": {
|
|
71
|
+
"displayType": "yaml"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"events": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"properties": {
|
|
79
|
+
"onChange": {
|
|
80
|
+
"type": "array",
|
|
81
|
+
"description": "Triggered when the upload state is changing."
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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';
|
|
@@ -0,0 +1,97 @@
|
|
|
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 } from 'react';
|
|
16
|
+
import { blockDefaultProps } from '@lowdefy/block-utils';
|
|
17
|
+
import { Button } from '@lowdefy/blocks-antd/blocks';
|
|
18
|
+
import { Upload } from 'antd';
|
|
19
|
+
import useFileList from '../utils/useFileList.js';
|
|
20
|
+
import getS3Upload from '../utils/getS3Upload.js';
|
|
21
|
+
const S3UploadButtonBlock = ({ blockId, components, events, methods, properties, value })=>{
|
|
22
|
+
const [state, loadFileList, setFileList, removeFile, setValue] = useFileList({
|
|
23
|
+
properties,
|
|
24
|
+
methods,
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
const s3UploadRequest = getS3Upload({
|
|
28
|
+
methods,
|
|
29
|
+
setFileList
|
|
30
|
+
});
|
|
31
|
+
useEffect(()=>{
|
|
32
|
+
methods.setValue({
|
|
33
|
+
file: null,
|
|
34
|
+
fileList: []
|
|
35
|
+
});
|
|
36
|
+
methods.registerEvent({
|
|
37
|
+
name: '__getS3PostPolicy',
|
|
38
|
+
actions: [
|
|
39
|
+
{
|
|
40
|
+
id: '__getS3PostPolicy',
|
|
41
|
+
type: 'Request',
|
|
42
|
+
params: [
|
|
43
|
+
properties.s3PostPolicyRequestId
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
}, []);
|
|
49
|
+
useEffect(()=>{
|
|
50
|
+
if (JSON.stringify(value) !== JSON.stringify(state)) {
|
|
51
|
+
setValue(value);
|
|
52
|
+
}
|
|
53
|
+
}, [
|
|
54
|
+
value
|
|
55
|
+
]);
|
|
56
|
+
return /*#__PURE__*/ React.createElement(Upload, {
|
|
57
|
+
accept: properties.accept ?? '*',
|
|
58
|
+
beforeUpload: loadFileList,
|
|
59
|
+
customRequest: s3UploadRequest,
|
|
60
|
+
disabled: properties.disabled,
|
|
61
|
+
fileList: state.fileList,
|
|
62
|
+
id: blockId,
|
|
63
|
+
maxCount: properties.maxCount,
|
|
64
|
+
multiple: !properties.singleFile,
|
|
65
|
+
onRemove: removeFile,
|
|
66
|
+
showUploadList: properties.showUploadList,
|
|
67
|
+
onChange: ()=>{
|
|
68
|
+
methods.triggerEvent({
|
|
69
|
+
name: 'onChange'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/ React.createElement(Button, {
|
|
73
|
+
blockId: `${blockId}_button`,
|
|
74
|
+
components: components,
|
|
75
|
+
events: events,
|
|
76
|
+
properties: {
|
|
77
|
+
disabled: properties.disabled,
|
|
78
|
+
icon: 'AiOutlineUpload',
|
|
79
|
+
title: 'Upload',
|
|
80
|
+
type: 'default',
|
|
81
|
+
...properties.button
|
|
82
|
+
},
|
|
83
|
+
methods: methods
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
86
|
+
S3UploadButtonBlock.defaultProps = blockDefaultProps;
|
|
87
|
+
S3UploadButtonBlock.meta = {
|
|
88
|
+
valueType: 'object',
|
|
89
|
+
category: 'input',
|
|
90
|
+
icons: [
|
|
91
|
+
'AiOutlineUpload'
|
|
92
|
+
],
|
|
93
|
+
styles: [
|
|
94
|
+
'blocks/S3UploadButton/style.less'
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
export default S3UploadButtonBlock;
|