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

On paste file add file extension if not found #47953

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"@react-ng/bounds-observer": "^0.2.1",
"@rnmapbox/maps": "10.1.20",
"@shopify/flash-list": "1.6.3",
"@types/mime-db": "^1.43.5",
"@ua/react-native-airship": "17.2.1",
"@vue/preload-webpack-plugin": "^2.0.0",
"awesome-phonenumber": "^5.4.0",
Expand Down
10 changes: 8 additions & 2 deletions src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {MarkdownStyle} from '@expensify/react-native-live-markdown';
import mimeDb from 'mime-db';
import type {ForwardedRef} from 'react';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import type {NativeSyntheticEvent, TextInput, TextInputChangeEventData, TextInputPasteEventData} from 'react-native';
Expand All @@ -14,6 +15,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import updateIsFullComposerAvailable from '@libs/ComposerUtils/updateIsFullComposerAvailable';
import * as EmojiUtils from '@libs/EmojiUtils';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import type {ComposerProps} from './types';

const excludeNoStyles: Array<keyof MarkdownStyle> = [];
Expand Down Expand Up @@ -92,9 +94,13 @@ function Composer(
if (clipboardContent.type === 'text/plain') {
return;
}
const mimeType = clipboardContent.type;
const fileURI = clipboardContent.data;
const fileName = fileURI.split('/').pop();
const file: FileObject = {uri: fileURI, name: fileName, type: clipboardContent.type};
const baseFileName = fileURI.split('/').pop() ?? 'file';
const {fileName: stem, fileExtension: originalFileExtension} = FileUtils.splitExtensionFromFileName(baseFileName);
const fileExtension = originalFileExtension || (mimeDb[mimeType].extensions?.[0] ?? 'bin');
const fileName = `${stem}.${fileExtension}`;
const file: FileObject = {uri: fileURI, name: fileName, type: mimeType};
onPasteFile(file);
},
[onPasteFile],
Expand Down
Loading