Upload: Fix video upload (#3671)

This commit is contained in:
Alexander Zinchuk 2023-07-27 11:48:21 +02:00
parent 022d915199
commit c2ca3c2718
2 changed files with 7 additions and 4 deletions

View File

@ -618,16 +618,16 @@ async function uploadMedia(localMessage: ApiMessage, attachment: ApiAttachment,
} }
}; };
const fetchAndUpload = async (url: string) => { const fetchAndUpload = async (url: string, progressCallback?: (progress: number) => void) => {
const file = await fetchFile(url, filename); const file = await fetchFile(url, filename);
return uploadFile(file, patchedOnProgress); return uploadFile(file, progressCallback);
}; };
const isVideo = SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType); const isVideo = SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType);
const shouldUploadThumb = audio || isVideo || shouldSendAsFile; const shouldUploadThumb = audio || isVideo || shouldSendAsFile;
const [inputFile, thumb] = await Promise.all(compact([ const [inputFile, thumb] = await Promise.all(compact([
fetchAndUpload(blobUrl), fetchAndUpload(blobUrl, patchedOnProgress),
shouldUploadThumb && previewBlobUrl && fetchAndUpload(previewBlobUrl), shouldUploadThumb && previewBlobUrl && fetchAndUpload(previewBlobUrl),
])); ]));

View File

@ -95,7 +95,10 @@ export async function createPosterForVideo(url: string): Promise<string | undefi
canvas.height = video.videoHeight; canvas.height = video.videoHeight;
const ctx = canvas.getContext('2d')!; const ctx = canvas.getContext('2d')!;
ctx.drawImage(video, 0, 0); ctx.drawImage(video, 0, 0);
resolve(canvas.toDataURL('image/jpeg'));
canvas.toBlob((blob) => {
resolve(blob ? URL.createObjectURL(blob) : undefined);
});
}; };
video.onerror = reject; video.onerror = reject;
video.currentTime = Math.min(video.duration, 1); video.currentTime = Math.min(video.duration, 1);