mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 10:00:55 +01:00
parent
b7d8e0bb6c
commit
71c73e503c
2 changed files with 7 additions and 5 deletions
|
@ -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?.reduce?.((a, b) =>
|
||||
!a.url.includes('/hevc/') && (a.bitrate ?? 0) > (b.bitrate ?? 0) ? a : b
|
||||
(c.req.header('User-Agent')?.includes('Telegram') || !a.url.includes('/hevc/')) && (a.bitrate ?? 0) > (b.bitrate ?? 0) ? a : b
|
||||
);
|
||||
return {
|
||||
url: bestVariant?.url || '',
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue