Once again whitelist HEVC for Telegram

This commit is contained in:
dangered wolf 2024-03-11 21:04:01 -04:00
parent 0b68161e68
commit 05c75567be
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 7 additions and 5 deletions

View file

@ -1,5 +1,7 @@
import { Context } from "hono";
/* Help populate API response for media */
export const processMedia = (media: TweetMedia): APIPhoto | APIVideo | null => {
export const processMedia = (c: Context, media: TweetMedia): APIPhoto | APIVideo | null => {
if (media.type === 'photo') {
return {
type: 'photo',
@ -11,7 +13,7 @@ export const processMedia = (media: TweetMedia): APIPhoto | APIVideo | null => {
} else if (media.type === 'video' || media.type === 'animated_gif') {
/* Find the variant with the highest bitrate */
const bestVariant = media.video_info?.variants?.filter?.((format) => {
return !format.url.includes('hevc')
return c.req.header('user-agent')?.includes('Telegram') || !format.url.includes('hevc')
}).reduce?.((a, b) =>
(a.bitrate ?? 0) > (b.bitrate ?? 0) ? a : b
);

View file

@ -171,7 +171,7 @@ export const buildAPITwitterStatus = async (
/* Populate status media */
mediaList.forEach(media => {
const mediaObject = processMedia(media);
const mediaObject = processMedia(c, media);
if (mediaObject) {
apiStatus.media.all = apiStatus.media?.all ?? [];
apiStatus.media?.all?.push(mediaObject);
@ -234,7 +234,7 @@ export const buildAPITwitterStatus = async (
if (card.media) {
if (card.media.videos) {
card.media.videos.forEach(video => {
const mediaObject = processMedia(video) as APIVideo;
const mediaObject = processMedia(c, video) as APIVideo;
if (mediaObject) {
apiStatus.media.all = apiStatus.media?.all ?? [];
apiStatus.media?.all?.push(mediaObject);
@ -245,7 +245,7 @@ export const buildAPITwitterStatus = async (
}
if (card.media.photos) {
card.media.photos.forEach(photo => {
const mediaObject = processMedia(photo) as APIPhoto;
const mediaObject = processMedia(c, photo) as APIPhoto;
if (mediaObject) {
apiStatus.media.all = apiStatus.media?.all ?? [];
apiStatus.media?.all?.push(mediaObject);