Upload: Fix video upload (#3671)
This commit is contained in:
parent
022d915199
commit
c2ca3c2718
@ -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),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user