@experium/findy-form 1.2.44 → 1.2.48
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.
|
@@ -35,6 +35,8 @@ var _reactI18next = require("react-i18next");
|
|
|
35
35
|
|
|
36
36
|
var _getusermedia = _interopRequireDefault(require("getusermedia"));
|
|
37
37
|
|
|
38
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
39
|
+
|
|
38
40
|
var _withFieldWrapper = _interopRequireDefault(require("../hocs/withFieldWrapper"));
|
|
39
41
|
|
|
40
42
|
var _ImageFile = _interopRequireDefault(require("./ImageFile"));
|
|
@@ -179,9 +181,12 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
179
181
|
var type = (0, _ramda.prop)('type', settings);
|
|
180
182
|
var fd = new FormData();
|
|
181
183
|
var fileExtenstion = (0, _ramda.last)("".concat(file.name).split('.'));
|
|
184
|
+
var fileType = file.type || (0, _ramda.path)([type, fileExtenstion], _allowFileExtensions.defaultAllowFileExtensions);
|
|
182
185
|
var validFileType = (0, _validation.checkFileType)(type, file.type, fileExtenstion, allowFileExtensions);
|
|
186
|
+
file.type = fileType;
|
|
183
187
|
fd.append('file', file);
|
|
184
188
|
fd.append('name', file.name);
|
|
189
|
+
fd.append('mimetype', fileType);
|
|
185
190
|
|
|
186
191
|
if (validFileType) {
|
|
187
192
|
_this.setState({
|
|
@@ -190,16 +195,13 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
190
195
|
});
|
|
191
196
|
|
|
192
197
|
setInputError(undefined);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (!response.ok && response.status !== 400) {
|
|
198
|
-
throw new Error();
|
|
199
|
-
} else {
|
|
200
|
-
return response.json();
|
|
198
|
+
|
|
199
|
+
_axios["default"].post(postFileUrl, fd, {
|
|
200
|
+
headers: {
|
|
201
|
+
'Content-Type': 'multipart/form-data'
|
|
201
202
|
}
|
|
202
|
-
}).then(function (
|
|
203
|
+
}).then(function (response) {
|
|
204
|
+
var data = response.data;
|
|
203
205
|
var name = _this.props.input.name;
|
|
204
206
|
var fileName = data.filename;
|
|
205
207
|
|
|
@@ -228,7 +230,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
228
230
|
url: url,
|
|
229
231
|
text: fileName,
|
|
230
232
|
extenstion: fileExtenstion,
|
|
231
|
-
contentType:
|
|
233
|
+
contentType: fileType,
|
|
232
234
|
type: type
|
|
233
235
|
};
|
|
234
236
|
|
|
@@ -248,7 +250,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
248
250
|
onChange(fileItem);
|
|
249
251
|
}
|
|
250
252
|
})["catch"](function (error) {
|
|
251
|
-
setInputError((0, _file.getFileErrorText)(error));
|
|
253
|
+
setInputError((0, _file.getFileErrorText)((0, _ramda.pathOr)('', ['response', 'data', 'message'], error)));
|
|
252
254
|
|
|
253
255
|
_this.setState({
|
|
254
256
|
error: true
|
|
@@ -258,7 +260,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
258
260
|
var fileItem = {
|
|
259
261
|
text: file.name,
|
|
260
262
|
extenstion: fileExtenstion,
|
|
261
|
-
contentType:
|
|
263
|
+
contentType: fileType,
|
|
262
264
|
type: type
|
|
263
265
|
};
|
|
264
266
|
setInputError((0, _validation.getFileTypeMessage)(type, allowFileExtensions));
|
|
@@ -451,7 +453,6 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
451
453
|
className: styles.fileInput,
|
|
452
454
|
id: name,
|
|
453
455
|
type: "file",
|
|
454
|
-
value: "",
|
|
455
456
|
onChange: this.onChange,
|
|
456
457
|
accept: this.getAccept(type),
|
|
457
458
|
disabled: disabled || loading && !error
|
package/lib/utils/validation.js
CHANGED
|
@@ -44,7 +44,7 @@ var checkFileType = function checkFileType(fileType, mimeType, extenstion) {
|
|
|
44
44
|
return allowFileTypes ? (0, _ramda.contains)(mimeType, (0, _ramda.split)(',', (0, _ramda.replace)(/\s/g, '', allowFileTypes))) : true;
|
|
45
45
|
|
|
46
46
|
default:
|
|
47
|
-
return allowFileTypes ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType];
|
|
47
|
+
return !fileType || (allowFileTypes ? allowFileExtensions[fileType][extenstion] : _allowFileExtensions.defaultAllowFileExtensions[fileType][extenstion]);
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@experium/findy-form",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.48",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"homepage": "https://experium.github.io/findy-form",
|
|
6
6
|
"repository": "https://github.com/experium/findy-form",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@ant-design/icons": "^4.2.2",
|
|
13
|
+
"axios": "^0.26.0",
|
|
13
14
|
"class-validator": "^0.12.2",
|
|
14
15
|
"classnames": "^2.2.6",
|
|
15
16
|
"final-form": "^4.20.2",
|
|
@@ -3,6 +3,7 @@ import { prop, append, remove, isEmpty, path, pathOr, join, values, keys, last }
|
|
|
3
3
|
import Modal from 'react-responsive-modal';
|
|
4
4
|
import { withTranslation } from 'react-i18next';
|
|
5
5
|
import getusermedia from 'getusermedia';
|
|
6
|
+
import axios from 'axios';
|
|
6
7
|
|
|
7
8
|
import withFieldWrapper from '../hocs/withFieldWrapper';
|
|
8
9
|
import ImageFile from './ImageFile';
|
|
@@ -12,7 +13,7 @@ import styles from '../../styles/index.module.css';
|
|
|
12
13
|
import formStyles from '../../styles/index.module.css';
|
|
13
14
|
import Spinner from './Spinner';
|
|
14
15
|
import { getFileErrorText } from '../../utils/file';
|
|
15
|
-
import { TYPES } from '../../constants/allowFileExtensions';
|
|
16
|
+
import { TYPES, defaultAllowFileExtensions } from '../../constants/allowFileExtensions';
|
|
16
17
|
import { checkFileType, getFileTypeMessage } from '../../utils/validation';
|
|
17
18
|
|
|
18
19
|
const FILE_TYPES = {
|
|
@@ -56,27 +57,25 @@ class File extends Component {
|
|
|
56
57
|
const type = prop('type', settings);
|
|
57
58
|
const fd = new FormData();
|
|
58
59
|
const fileExtenstion = last(`${file.name}`.split('.'));
|
|
60
|
+
const fileType = file.type || path([type, fileExtenstion], defaultAllowFileExtensions);
|
|
59
61
|
const validFileType = checkFileType(type, file.type, fileExtenstion, allowFileExtensions);
|
|
60
62
|
|
|
63
|
+
file.type = fileType;
|
|
61
64
|
fd.append('file', file);
|
|
62
65
|
fd.append('name', file.name);
|
|
66
|
+
fd.append('mimetype', fileType);
|
|
63
67
|
|
|
64
68
|
if (validFileType) {
|
|
65
69
|
this.setState({ loading: true, error: false });
|
|
66
70
|
setInputError(undefined);
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
axios.post(postFileUrl, fd, {
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'multipart/form-data',
|
|
75
|
+
},
|
|
71
76
|
})
|
|
72
77
|
.then(response => {
|
|
73
|
-
|
|
74
|
-
throw new Error();
|
|
75
|
-
} else {
|
|
76
|
-
return response.json();
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
.then(data => {
|
|
78
|
+
const { data } = response;
|
|
80
79
|
const { input: { name } } = this.props;
|
|
81
80
|
const fileName = data.filename;
|
|
82
81
|
|
|
@@ -96,7 +95,7 @@ class File extends Component {
|
|
|
96
95
|
url,
|
|
97
96
|
text: fileName,
|
|
98
97
|
extenstion: fileExtenstion,
|
|
99
|
-
contentType:
|
|
98
|
+
contentType: fileType,
|
|
100
99
|
type,
|
|
101
100
|
};
|
|
102
101
|
|
|
@@ -114,14 +113,14 @@ class File extends Component {
|
|
|
114
113
|
}
|
|
115
114
|
})
|
|
116
115
|
.catch((error) => {
|
|
117
|
-
setInputError(getFileErrorText(error));
|
|
116
|
+
setInputError(getFileErrorText(pathOr('', ['response', 'data', 'message'], error)));
|
|
118
117
|
this.setState({ error: true });
|
|
119
118
|
});
|
|
120
119
|
} else {
|
|
121
120
|
const fileItem = {
|
|
122
121
|
text: file.name,
|
|
123
122
|
extenstion: fileExtenstion,
|
|
124
|
-
contentType:
|
|
123
|
+
contentType: fileType,
|
|
125
124
|
type,
|
|
126
125
|
};
|
|
127
126
|
|
|
@@ -305,13 +304,12 @@ class File extends Component {
|
|
|
305
304
|
className={styles.fileInput}
|
|
306
305
|
id={name}
|
|
307
306
|
type='file'
|
|
308
|
-
value=''
|
|
309
307
|
onChange={this.onChange}
|
|
310
308
|
accept={this.getAccept(type)}
|
|
311
|
-
disabled={disabled || loading && !error}
|
|
309
|
+
disabled={disabled || (loading && !error)}
|
|
312
310
|
/>
|
|
313
311
|
<label htmlFor={name} className={`${disabled ? 'disabled' : ''}`}>
|
|
314
|
-
{ loading && !error && <Spinner /> }
|
|
312
|
+
{ (loading && !error) && <Spinner /> }
|
|
315
313
|
<span className='button-text'>
|
|
316
314
|
{t('upload')}
|
|
317
315
|
</span>
|
package/src/utils/validation.js
CHANGED
|
@@ -24,7 +24,7 @@ export const checkFileType = (fileType, mimeType, extenstion, allowFileExtension
|
|
|
24
24
|
|
|
25
25
|
return allowFileTypes ? contains(mimeType, split(',', replace(/\s/g, '', allowFileTypes))) : true;
|
|
26
26
|
default:
|
|
27
|
-
return allowFileTypes ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType];
|
|
27
|
+
return !fileType || (allowFileTypes ? allowFileExtensions[fileType][extenstion] : defaultAllowFileExtensions[fileType][extenstion]);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
export const getFileTypeMessage = (type, allowFileExtensions = {}) => {
|