Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add missing .png to clipboard uploaded file name #23833

Merged
merged 5 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/ui-message/client/messageBox/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import './messageBoxAudioMessage';
import './messageBoxNotSubscribed';
import './messageBox.html';
import './messageBoxReadOnly';
import { getImageExtensionFromMime } from '../../../../lib/getImageExtensionFromMime';
import { keyCodes } from '../../../../client/lib/utils/keyCodes';
import { isRTL } from '../../../../client/lib/utils/isRTL';
import { call } from '../../../../client/lib/utils/call';
Expand Down Expand Up @@ -400,11 +401,14 @@ Template.messageBox.events({

const files = items
.filter((item) => item.kind === 'file' && item.type.indexOf('image/') !== -1)
.map((item) => ({
file: item.getAsFile(),
name: `Clipboard - ${ moment().format(settings.get('Message_TimeAndDateFormat')) }`,
}))
.filter(({ file }) => file !== null);
.map((item) => {
const fileItem = item.getAsFile();

return {
file: fileItem,
name: `Clipboard - ${ moment().format(settings.get('Message_TimeAndDateFormat')) }.${ getImageExtensionFromMime(fileItem.type) }`,
gabriellsh marked this conversation as resolved.
Show resolved Hide resolved
};
}).filter(({ file }) => file !== null);

if (files.length) {
event.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions client/views/room/modals/FileUploadModal/FileUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesConte
import { useTranslation } from '../../../../contexts/TranslationContext';
import FilePreview from './FilePreview';

type FilePreviewModalProps = {
type FileUploadModalProps = {
onClose: () => void;
onSubmit: (name: string, description?: string) => void;
file: File;
fileName: string;
invalidContentType: boolean;
};

const FilePreviewModal = ({
const FileUploadModal = ({
onClose,
file,
fileName,
onSubmit,
invalidContentType,
}: FilePreviewModalProps): ReactElement => {
}: FileUploadModalProps): ReactElement => {
const [name, setName] = useState<string>(fileName);
const [description, setDescription] = useState<string>('');
const t = useTranslation();
Expand Down Expand Up @@ -137,4 +137,4 @@ const FilePreviewModal = ({
);
};

export default memo(FilePreviewModal);
export default memo(FileUploadModal);
14 changes: 14 additions & 0 deletions lib/getImageExtensionFromMime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const extensionsMap: Record<string, string> = {
'image/apng': 'apng',
'image/avif': 'avif',
'image/gif': 'gif',
'image/jpeg': 'jpg',
'image/png': 'png',
'image/svg+xml': 'svg',
'image/webp': 'webp',
'image/bmp': 'bmp',
'image/x-icon': 'ico',
'image/tiff': 'tif',
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
};

export const getImageExtensionFromMime = (mime: string): string | undefined => extensionsMap[mime];