Improved mosaic caching

This commit is contained in:
dangered wolf 2022-07-24 14:20:27 -04:00
parent 656d3b3b0c
commit b7f10cfd04
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 4 additions and 3 deletions

View file

@ -1,6 +1,6 @@
import { Constants } from './constants';
export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia> => {
export const handleMosaic = async (mediaList: TweetMedia[], userAgent: string): Promise<TweetMedia> => {
let mosaicDomains = Constants.MOSAIC_DOMAIN_LIST;
let selectedDomain: string | null = null;
while (selectedDomain === null && mosaicDomains.length > 0) {
@ -26,7 +26,8 @@ export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia>
''
);
console.log('mosaicMedia', mosaicMedia);
let constructUrl = `https://${selectedDomain}/1`;
// TODO: use a better system for this, 0 gets png 1 gets webp, usually
let constructUrl = `https://${selectedDomain}/${userAgent.indexOf('Telegram') > -1 ? '0' : '1'}`;
if (mosaicMedia[0]) {
constructUrl += `/${mosaicMedia[0]}`;
}

View file

@ -288,7 +288,7 @@ export const handleStatus = async (
processMedia(firstMedia);
} else if (mediaList.length > 1) {
console.log('Handling mosaic');
processMedia(await handleMosaic(mediaList));
processMedia(await handleMosaic(mediaList, userAgent || ''));
renderedMosaic = true;
}