Check filename extension for heic/heif images

This commit is contained in:
Josh Perez 2021-12-06 12:20:27 -05:00 committed by GitHub
parent 69edaeabfb
commit 5c8f740c2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -26,8 +26,11 @@ export const VIDEO_MP4 = stringToMIMEType('video/mp4');
export const VIDEO_QUICKTIME = stringToMIMEType('video/quicktime');
export const LONG_MESSAGE = stringToMIMEType('text/x-signal-plain');
export const isHeic = (value: string): boolean =>
value === 'image/heic' || value === 'image/heif';
export const isHeic = (value: string, fileName: string): boolean =>
value === 'image/heic' ||
value === 'image/heif' ||
fileName.endsWith('.heic') ||
fileName.endsWith('.heif');
export const isGif = (value: string): value is MIMEType =>
value === 'image/gif';
export const isJPEG = (value: string): value is MIMEType =>

View File

@ -18,7 +18,7 @@ export async function handleImageAttachment(
): Promise<InMemoryAttachmentDraftType> {
let processedFile: File | Blob = file;
if (isHeic(file.type)) {
if (isHeic(file.type, file.name)) {
const uuid = genUuid();
const bytes = new Uint8Array(await file.arrayBuffer());
@ -41,7 +41,9 @@ export async function handleImageAttachment(
file: resizedBlob,
fileName,
} = await autoScale({
contentType: isHeic(file.type) ? IMAGE_JPEG : stringToMIMEType(file.type),
contentType: isHeic(file.type, file.name)
? IMAGE_JPEG
: stringToMIMEType(file.type),
fileName: file.name,
file: processedFile,
});

View File

@ -82,7 +82,7 @@ export async function processAttachment(
let attachment: InMemoryAttachmentDraftType;
try {
if (isImageTypeSupported(fileType) || isHeic(fileType)) {
if (isImageTypeSupported(fileType) || isHeic(fileType, file.name)) {
attachment = await handleImageAttachment(file);
} else if (isVideoTypeSupported(fileType)) {
attachment = await handleVideoAttachment(file);