pass through mimetype rather than assuming data uri
This commit is contained in:
@@ -103,9 +103,15 @@ export function createInitialImages(
|
||||
|
||||
export async function pasteImage(
|
||||
uri: string,
|
||||
mimeType?: string,
|
||||
): Promise<ComposerImageWithoutTransformation> {
|
||||
const {width, height} = await getImageDim(uri)
|
||||
const match = /^data:(.+?);/.exec(uri)
|
||||
|
||||
let mime = mimeType
|
||||
if (!mime) {
|
||||
const match = /^data:(.+?);/.exec(uri)
|
||||
mime = match ? match[1] : 'image/jpeg'
|
||||
}
|
||||
|
||||
return {
|
||||
alt: '',
|
||||
@@ -114,7 +120,7 @@ export async function pasteImage(
|
||||
path: uri,
|
||||
width: width,
|
||||
height: height,
|
||||
mime: match ? match[1] : 'image/jpeg',
|
||||
mime,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,7 +886,7 @@ let ComposerPost = React.memo(function ComposerPost({
|
||||
)
|
||||
|
||||
const onPhotoPasted = useCallback(
|
||||
async (uri: string) => {
|
||||
async (uri: string, mimeType?: string) => {
|
||||
if (
|
||||
uri.startsWith('data:video/') ||
|
||||
(isWeb && uri.startsWith('data:image/gif'))
|
||||
@@ -905,7 +905,8 @@ let ComposerPost = React.memo(function ComposerPost({
|
||||
.then(blob => new File([blob], name, {type: mimeType}))
|
||||
onSelectVideo(post.id, await getVideoMetadata(file))
|
||||
} else {
|
||||
const res = await pasteImage(uri)
|
||||
const res = await pasteImage(uri, mimeType)
|
||||
|
||||
onImageAdd([res])
|
||||
}
|
||||
},
|
||||
|
||||
@@ -130,7 +130,7 @@ export function TextInput({
|
||||
const file = files.find(f => isAcceptedImageMimeType(f.type))
|
||||
|
||||
if (file) {
|
||||
onPhotoPasted(file.data)
|
||||
onPhotoPasted(file.data, file.type)
|
||||
}
|
||||
},
|
||||
[onPhotoPasted],
|
||||
|
||||
@@ -26,7 +26,7 @@ export type TextInputProps = {
|
||||
hasRightPadding: boolean
|
||||
isActive: boolean
|
||||
setRichText: (v: RichText) => void
|
||||
onPhotoPasted: (uri: string) => void
|
||||
onPhotoPasted: (uri: string, mimeType?: string) => void
|
||||
onPressPublish: (richtext: RichText) => void
|
||||
onNewLink: (uri: string) => void
|
||||
onError: (err: string) => void
|
||||
|
||||
Reference in New Issue
Block a user