Stop preemptively generating screenshots for video stories
This commit is contained in:
parent
f798bc999c
commit
54d4734f05
6 changed files with 57 additions and 19 deletions
|
@ -191,6 +191,30 @@ export function _cleanMessageData(data: MessageType): MessageType {
|
||||||
return omit(attachment, ['data']);
|
return omit(attachment, ['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attachment.screenshotData) {
|
||||||
|
assertDev(
|
||||||
|
false,
|
||||||
|
`_cleanMessageData/${logId}: Attachment ${index} had screenshotData field; deleting`
|
||||||
|
);
|
||||||
|
return omit(attachment, ['screenshotData']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachment.screenshot?.data) {
|
||||||
|
assertDev(
|
||||||
|
false,
|
||||||
|
`_cleanMessageData/${logId}: Attachment ${index} had screenshot.data field; deleting`
|
||||||
|
);
|
||||||
|
return omit(attachment, ['screenshot.data']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachment.thumbnail?.data) {
|
||||||
|
assertDev(
|
||||||
|
false,
|
||||||
|
`_cleanMessageData/${logId}: Attachment ${index} had thumbnail.data field; deleting`
|
||||||
|
);
|
||||||
|
return omit(attachment, ['thumbnail.data']);
|
||||||
|
}
|
||||||
|
|
||||||
return attachment;
|
return attachment;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1918,8 +1918,14 @@ function saveMessageSync(
|
||||||
|
|
||||||
if (attachments) {
|
if (attachments) {
|
||||||
strictAssert(
|
strictAssert(
|
||||||
attachments.every(attachment => !attachment.data),
|
attachments.every(
|
||||||
'Attempting to save a hydrated message'
|
attachment =>
|
||||||
|
!attachment.data &&
|
||||||
|
!attachment.screenshotData &&
|
||||||
|
!attachment.screenshot?.data &&
|
||||||
|
!attachment.thumbnail?.data
|
||||||
|
),
|
||||||
|
'Attempting to save a message with binary attachment data'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1079,7 +1079,9 @@ function processAttachments({
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
filesToProcess.map(async file => {
|
filesToProcess.map(async file => {
|
||||||
try {
|
try {
|
||||||
const attachment = await processAttachment(file);
|
const attachment = await processAttachment(file, {
|
||||||
|
generateScreenshot: true,
|
||||||
|
});
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
removeAttachment(conversationId, file.path)(
|
removeAttachment(conversationId, file.path)(
|
||||||
dispatch,
|
dispatch,
|
||||||
|
|
|
@ -130,7 +130,6 @@ export type BaseAttachmentDraftType = {
|
||||||
blurHash?: string;
|
blurHash?: string;
|
||||||
contentType: MIME.MIMEType;
|
contentType: MIME.MIMEType;
|
||||||
screenshotContentType?: string;
|
screenshotContentType?: string;
|
||||||
screenshotSize?: number;
|
|
||||||
size: number;
|
size: number;
|
||||||
flags?: number;
|
flags?: number;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,33 +10,39 @@ import type { InMemoryAttachmentDraftType } from '../types/Attachment';
|
||||||
import { fileToBytes } from './fileToBytes';
|
import { fileToBytes } from './fileToBytes';
|
||||||
|
|
||||||
export async function handleVideoAttachment(
|
export async function handleVideoAttachment(
|
||||||
file: File
|
file: File,
|
||||||
|
options?: { generateScreenshot: boolean }
|
||||||
): Promise<InMemoryAttachmentDraftType> {
|
): Promise<InMemoryAttachmentDraftType> {
|
||||||
const objectUrl = URL.createObjectURL(file);
|
const objectUrl = URL.createObjectURL(file);
|
||||||
if (!objectUrl) {
|
if (!objectUrl) {
|
||||||
throw new Error('Failed to create object url for video!');
|
throw new Error('Failed to create object url for video!');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const screenshotContentType = IMAGE_PNG;
|
|
||||||
const screenshotBlob = await makeVideoScreenshot({
|
|
||||||
objectUrl,
|
|
||||||
contentType: screenshotContentType,
|
|
||||||
logger: log,
|
|
||||||
});
|
|
||||||
const screenshotData = await blobToArrayBuffer(screenshotBlob);
|
|
||||||
const data = await fileToBytes(file);
|
const data = await fileToBytes(file);
|
||||||
|
const attachment: InMemoryAttachmentDraftType = {
|
||||||
return {
|
|
||||||
contentType: stringToMIMEType(file.type),
|
contentType: stringToMIMEType(file.type),
|
||||||
data,
|
data,
|
||||||
fileName: file.name,
|
fileName: file.name,
|
||||||
path: file.name,
|
path: file.name,
|
||||||
pending: false,
|
pending: false,
|
||||||
screenshotContentType,
|
|
||||||
screenshotData: new Uint8Array(screenshotData),
|
|
||||||
screenshotSize: screenshotData.byteLength,
|
|
||||||
size: data.byteLength,
|
size: data.byteLength,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options?.generateScreenshot) {
|
||||||
|
const screenshotContentType = IMAGE_PNG;
|
||||||
|
|
||||||
|
const screenshotBlob = await makeVideoScreenshot({
|
||||||
|
objectUrl,
|
||||||
|
contentType: screenshotContentType,
|
||||||
|
logger: log,
|
||||||
|
});
|
||||||
|
attachment.screenshotData = new Uint8Array(
|
||||||
|
await blobToArrayBuffer(screenshotBlob)
|
||||||
|
);
|
||||||
|
attachment.screenshotContentType = screenshotContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachment;
|
||||||
} finally {
|
} finally {
|
||||||
URL.revokeObjectURL(objectUrl);
|
URL.revokeObjectURL(objectUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ import { showToast } from './showToast';
|
||||||
import { ToastFileSize } from '../components/ToastFileSize';
|
import { ToastFileSize } from '../components/ToastFileSize';
|
||||||
|
|
||||||
export async function processAttachment(
|
export async function processAttachment(
|
||||||
file: File
|
file: File,
|
||||||
|
options?: { generateScreenshot: boolean }
|
||||||
): Promise<InMemoryAttachmentDraftType | void> {
|
): Promise<InMemoryAttachmentDraftType | void> {
|
||||||
const fileType = stringToMIMEType(file.type);
|
const fileType = stringToMIMEType(file.type);
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ export async function processAttachment(
|
||||||
if (isImageTypeSupported(fileType) || isHeic(fileType, file.name)) {
|
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, options);
|
||||||
} else {
|
} else {
|
||||||
const data = await fileToBytes(file);
|
const data = await fileToBytes(file);
|
||||||
attachment = {
|
attachment = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue