tweb-i2p/src/helpers/getStrippedThumbIfNeeded.ts
Eduard Kuzmenko 6334af6014 Some refactor
2022-04-25 17:54:30 +03:00

27 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 { MyDocument } from "../lib/appManagers/appDocsManager";
import { ThumbCache } from "../lib/appManagers/appDownloadManager";
import type { MyPhoto, AppPhotosManager } from "../lib/appManagers/appPhotosManager";
import getImageFromStrippedThumb from "./getImageFromStrippedThumb";
export default function getStrippedThumbIfNeeded(photo: MyPhoto | MyDocument, cacheContext: ThumbCache, useBlur: boolean, ignoreCache = false) {
if(!cacheContext.downloaded || (['video', 'gif'] as MyDocument['type'][]).includes((photo as MyDocument).type) || ignoreCache) {
if(photo._ === 'document' && cacheContext.downloaded && !ignoreCache) {
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;
}