044f23fc62
Fix dead streaming & downloading through SW Possible fix for stuck sticker viewer
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
/*
|
|
* https://github.com/morethanwords/tweb
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
*/
|
|
|
|
import type {MyDocument} from '../lib/appManagers/appDocsManager';
|
|
import type {MyPhoto} from '../lib/appManagers/appPhotosManager';
|
|
import type {ThumbCache} from '../lib/storages/thumbs';
|
|
import getImageFromStrippedThumb from './getImageFromStrippedThumb';
|
|
|
|
export default function getStrippedThumbIfNeeded(photo: MyPhoto | MyDocument, cacheContext: ThumbCache, useBlur: boolean, ignoreCache = false) {
|
|
const isVideo = (['video', 'gif'] as MyDocument['type'][]).includes((photo as MyDocument).type);
|
|
if(!cacheContext.downloaded || isVideo || ignoreCache) {
|
|
if(photo._ === 'document' && cacheContext.downloaded && !ignoreCache && !isVideo) {
|
|
return null;
|
|
}
|
|
|
|
const sizes = (photo as MyPhoto).sizes || (photo as MyDocument).thumbs;
|
|
const thumb = sizes?.length ? sizes.find((size) => size._ === 'photoStrippedSize') : null;
|
|
if(thumb && ('bytes' in thumb)) {
|
|
return getImageFromStrippedThumb(photo, thumb as any, useBlur);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|