Check filename extension for heic/heif images
This commit is contained in:
parent
69edaeabfb
commit
5c8f740c2a
3 changed files with 10 additions and 5 deletions
|
@ -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 =>
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue