Skip to content

Commit

Permalink
Merge pull request Expensify#47953 from s77rt/pasteFile-add-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham authored Aug 25, 2024
2 parents c3c70a2 + b983f87 commit 1604e3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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

0 comments on commit 1604e3e

Please sign in to comment.