mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-08 20:10:54 +01:00
Updated palette algorithm
This commit is contained in:
parent
046383f56b
commit
5afb9ffe37
3 changed files with 16 additions and 4 deletions
|
@ -78,7 +78,6 @@ const populateTweetProperties = async (
|
||||||
|
|
||||||
mediaList.forEach(media => {
|
mediaList.forEach(media => {
|
||||||
let mediaObject = processMedia(media);
|
let mediaObject = processMedia(media);
|
||||||
console.log('mediaObject', JSON.stringify(mediaObject));
|
|
||||||
if (mediaObject) {
|
if (mediaObject) {
|
||||||
if (mediaObject.type === 'photo') {
|
if (mediaObject.type === 'photo') {
|
||||||
apiTweet.twitter_card = 'summary_large_image';
|
apiTweet.twitter_card = 'summary_large_image';
|
||||||
|
@ -86,7 +85,6 @@ const populateTweetProperties = async (
|
||||||
apiTweet.media.photos = apiTweet.media.photos || [];
|
apiTweet.media.photos = apiTweet.media.photos || [];
|
||||||
apiTweet.media.photos.push(mediaObject);
|
apiTweet.media.photos.push(mediaObject);
|
||||||
|
|
||||||
console.log('media', apiTweet.media);
|
|
||||||
} else if (mediaObject.type === 'video' || mediaObject.type === 'gif') {
|
} else if (mediaObject.type === 'video' || mediaObject.type === 'gif') {
|
||||||
apiTweet.twitter_card = 'player';
|
apiTweet.twitter_card = 'player';
|
||||||
apiTweet.media = apiTweet.media || {};
|
apiTweet.media = apiTweet.media || {};
|
||||||
|
|
|
@ -14,12 +14,22 @@ export const colorFromPalette = (palette: MediaPlaceholderColor[]) => {
|
||||||
const rgb = palette[i].rgb;
|
const rgb = palette[i].rgb;
|
||||||
|
|
||||||
// We need vibrant colors, grey backgrounds won't do!
|
// We need vibrant colors, grey backgrounds won't do!
|
||||||
if (rgb.red + rgb.green + rgb.blue < 120) {
|
if (
|
||||||
|
rgb.red + rgb.green + rgb.blue < 120 ||
|
||||||
|
rgb.red + rgb.green + rgb.blue > 240 * 3
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rgbToHex(rgb.red, rgb.green, rgb.blue);
|
return rgbToHex(rgb.red, rgb.green, rgb.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If no other color passes vibrancy test (not too white or black)
|
||||||
|
Then we'll use the top color anyway. */
|
||||||
|
if (palette?.[0]?.rgb) {
|
||||||
|
console.log('falling back to top color regardless of vibrancy');
|
||||||
|
return rgbToHex(palette[0].rgb.red, palette[0].rgb.green, palette[0].rgb.blue);
|
||||||
|
}
|
||||||
|
|
||||||
return Constants.DEFAULT_COLOR;
|
return Constants.DEFAULT_COLOR;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { sanitizeText } from './utils';
|
||||||
import { Strings } from './strings';
|
import { Strings } from './strings';
|
||||||
import { getAuthorText } from './author';
|
import { getAuthorText } from './author';
|
||||||
import { statusAPI } from './api';
|
import { statusAPI } from './api';
|
||||||
import { calculateTimeLeftString } from './pollHelper';
|
|
||||||
|
|
||||||
export const returnError = (error: string): StatusResponse => {
|
export const returnError = (error: string): StatusResponse => {
|
||||||
return {
|
return {
|
||||||
|
@ -63,6 +62,7 @@ export const handleStatus = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use quote media if there is no media */
|
||||||
if (!tweet.media && tweet.quote?.media) {
|
if (!tweet.media && tweet.quote?.media) {
|
||||||
tweet.media = tweet.quote.media;
|
tweet.media = tweet.quote.media;
|
||||||
tweet.twitter_card = 'summary_large_image';
|
tweet.twitter_card = 'summary_large_image';
|
||||||
|
@ -79,6 +79,7 @@ export const handleStatus = async (
|
||||||
`<meta name="twitter:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`
|
`<meta name="twitter:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/* Video renderer */
|
||||||
if (tweet.media?.video) {
|
if (tweet.media?.video) {
|
||||||
authorText = encodeURIComponent(tweet.text || '');
|
authorText = encodeURIComponent(tweet.text || '');
|
||||||
|
|
||||||
|
@ -97,6 +98,7 @@ export const handleStatus = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Photo renderer */
|
||||||
if (tweet.media?.photos) {
|
if (tweet.media?.photos) {
|
||||||
const { photos } = tweet.media;
|
const { photos } = tweet.media;
|
||||||
let photo = photos[mediaNumber || 0];
|
let photo = photos[mediaNumber || 0];
|
||||||
|
@ -145,6 +147,7 @@ export const handleStatus = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* External media renderer (i.e. YouTube) */
|
||||||
if (tweet.media?.external) {
|
if (tweet.media?.external) {
|
||||||
const { external } = tweet.media;
|
const { external } = tweet.media;
|
||||||
headers.push(
|
headers.push(
|
||||||
|
@ -162,6 +165,7 @@ export const handleStatus = async (
|
||||||
let siteName = Constants.BRANDING_NAME;
|
let siteName = Constants.BRANDING_NAME;
|
||||||
let newText = tweet.text;
|
let newText = tweet.text;
|
||||||
|
|
||||||
|
/* Poll renderer */
|
||||||
if (tweet.poll) {
|
if (tweet.poll) {
|
||||||
const { poll } = tweet;
|
const { poll } = tweet;
|
||||||
let barLength = 34;
|
let barLength = 34;
|
||||||
|
|
Loading…
Add table
Reference in a new issue