Check filename extension for heic/heif images
This commit is contained in:
parent
69edaeabfb
commit
5c8f740c2a
|
@ -26,8 +26,11 @@ export const VIDEO_MP4 = stringToMIMEType('video/mp4');
|
||||||
export const VIDEO_QUICKTIME = stringToMIMEType('video/quicktime');
|
export const VIDEO_QUICKTIME = stringToMIMEType('video/quicktime');
|
||||||
export const LONG_MESSAGE = stringToMIMEType('text/x-signal-plain');
|
export const LONG_MESSAGE = stringToMIMEType('text/x-signal-plain');
|
||||||
|
|
||||||
export const isHeic = (value: string): boolean =>
|
export const isHeic = (value: string, fileName: string): boolean =>
|
||||||
value === 'image/heic' || value === 'image/heif';
|
value === 'image/heic' ||
|
||||||
|
value === 'image/heif' ||
|
||||||
|
fileName.endsWith('.heic') ||
|
||||||
|
fileName.endsWith('.heif');
|
||||||
export const isGif = (value: string): value is MIMEType =>
|
export const isGif = (value: string): value is MIMEType =>
|
||||||
value === 'image/gif';
|
value === 'image/gif';
|
||||||
export const isJPEG = (value: string): value is MIMEType =>
|
export const isJPEG = (value: string): value is MIMEType =>
|
||||||
|
|
|
@ -18,7 +18,7 @@ export async function handleImageAttachment(
|
||||||
): Promise<InMemoryAttachmentDraftType> {
|
): Promise<InMemoryAttachmentDraftType> {
|
||||||
let processedFile: File | Blob = file;
|
let processedFile: File | Blob = file;
|
||||||
|
|
||||||
if (isHeic(file.type)) {
|
if (isHeic(file.type, file.name)) {
|
||||||
const uuid = genUuid();
|
const uuid = genUuid();
|
||||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||||
|
|
||||||
|
@ -41,7 +41,9 @@ export async function handleImageAttachment(
|
||||||
file: resizedBlob,
|
file: resizedBlob,
|
||||||
fileName,
|
fileName,
|
||||||
} = await autoScale({
|
} = 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,
|
fileName: file.name,
|
||||||
file: processedFile,
|
file: processedFile,
|
||||||
});
|
});
|
||||||
|
|
|
@ -82,7 +82,7 @@ export async function processAttachment(
|
||||||
|
|
||||||
let attachment: InMemoryAttachmentDraftType;
|
let attachment: InMemoryAttachmentDraftType;
|
||||||
try {
|
try {
|
||||||
if (isImageTypeSupported(fileType) || isHeic(fileType)) {
|
if (isImageTypeSupported(fileType) || isHeic(fileType, file.name)) {
|
||||||
attachment = await handleImageAttachment(file);
|
attachment = await handleImageAttachment(file);
|
||||||
} else if (isVideoTypeSupported(fileType)) {
|
} else if (isVideoTypeSupported(fileType)) {
|
||||||
attachment = await handleVideoAttachment(file);
|
attachment = await handleVideoAttachment(file);
|
||||||
|
|
Loading…
Reference in New Issue