Skip to content

Commit 56159ff

Browse files
committed
IMPROVEMENT: Imported images should have restricted file extensions (closes #368)
Co-authored-by: Lakhdar Berache <amineberache1@gmail.com>
1 parent a503e5f commit 56159ff

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

frontend/src/menu-items/PictureUploadAction.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useRef } from 'react';
2+
import { NotificationManager } from 'react-notifications';
23

34
import DiscreeteDropdown from '../components/DiscreeteDropdown';
45

5-
function PictureUploadAction ({ id, backend, handleImageUrl }) {
6+
function PictureUploadAction({ id, backend, handleImageUrl }) {
67
const fileInputRef = useRef(null);
78

89
const handleClick = () => {
@@ -11,7 +12,15 @@ function PictureUploadAction ({ id, backend, handleImageUrl }) {
1112

1213
const handleFileChange = (event) => {
1314
const file = event.target.files[0];
14-
if (file) backend.putAttachment(id, file, (response) => {
15+
16+
if (!file) return;
17+
18+
if (!file.type.startsWith('image/')) {
19+
NotificationManager.warning('Please choose an image file (png,jpg,jpeg...).', '', 2000);
20+
return;
21+
}
22+
23+
backend.putAttachment(id, file, (response) => {
1524
handleImageUrl(`![<IMAGE DESCRIPTION>](${response.url})`);
1625
});
1726
};
@@ -24,6 +33,7 @@ function PictureUploadAction ({ id, backend, handleImageUrl }) {
2433
<input
2534
id="image-input"
2635
type="file"
36+
accept="image/apng, image/avif, image/gif, image/jpeg, image/png, image/svg+xml, image/webp"
2737
ref={fileInputRef}
2838
style={{ display: 'none' }}
2939
onChange={handleFileChange}

0 commit comments

Comments
 (0)