diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 542020e44..eec4ee947 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -408,23 +408,23 @@ export function buildApiDocument(document: GramJs.TypeDocument): ApiDocument | u width: photoSize.w, height: photoSize.h, }; - } - if (mimeType.startsWith('image/')) { - mediaType = 'photo'; + if (mimeType.startsWith('image/')) { + mediaType = 'photo'; - const imageAttribute = attributes - .find((a: any): a is GramJs.DocumentAttributeImageSize => a instanceof GramJs.DocumentAttributeImageSize); + const imageAttribute = attributes + .find((a: any): a is GramJs.DocumentAttributeImageSize => a instanceof GramJs.DocumentAttributeImageSize); - if (imageAttribute) { - const { w: width, h: height } = imageAttribute; - mediaSize = { - width, - height, - }; + if (imageAttribute) { + const { w: width, h: height } = imageAttribute; + mediaSize = { + width, + height, + }; + } + } else if (mimeType.startsWith('video/')) { + mediaType = 'video'; } - } else if (mimeType.startsWith('video/')) { - mediaType = 'video'; } return { @@ -541,7 +541,7 @@ export function buildWebPage(media: GramJs.TypeMessageMedia): ApiWebPage | undef const { id, photo, document } = media.webpage; let video; - if (document instanceof GramJs.Document && document.mimeType.startsWith('video')) { + if (document instanceof GramJs.Document && document.mimeType.startsWith('video/')) { video = buildVideoFromDocument(document); } diff --git a/src/util/files.ts b/src/util/files.ts index 581868738..878d48036 100644 --- a/src/util/files.ts +++ b/src/util/files.ts @@ -85,6 +85,10 @@ export async function createPosterForVideo(url: string): Promise, new Promise((resolve, reject) => { video.onseeked = () => { + if (!video.videoWidth || !video.videoHeight) { + resolve(undefined); + } + const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight;