summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 19:53:14 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 19:53:14 +1100
commit6d7909a02c3b30af1fe84823bcc412120d81d0f0 (patch)
treea386fadedbab16900da02d36a6089cf55b689b0f
parentForgot some schemas + only generate schemas in util/schemas + add setup script (diff)
downloadserver-6d7909a02c3b30af1fe84823bcc412120d81d0f0.tar.xz
Fix tweets with only video breaking embeds
-rw-r--r--src/api/util/utility/EmbedHandlers.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts
index 831cab9a..700f5b55 100644
--- a/src/api/util/utility/EmbedHandlers.ts
+++ b/src/api/util/utility/EmbedHandlers.ts
@@ -165,22 +165,22 @@ export const EmbedHandlers: { [key: string]: (url: URL) => Promise<Embed | Embed
 	"c.tenor.com": genericImageHandler,
 	"media.tenor.com": genericImageHandler,
 
-	// TODO: twitter, facebook
+	// TODO: facebook
 	// have to use their APIs or something because they don't send the metas in initial html
 
 	"twitter.com": (url: URL) => { return EmbedHandlers["www.twitter.com"](url); },
 	"www.twitter.com": async (url: URL) => {
 		const token = Config.get().external.twitter;
-		if (!token) return null; // todo move to config
+		if (!token) return null;
 
 		if (!url.href.includes("/status/")) return null;	// TODO;
 		const id = url.pathname.split("/")[3];	// super bad lol
 		if (!parseInt(id)) return null;
-		const endpointUrl = `https://api.twitter.com/2/tweets/${id}`
-			+ `?expansions=author_id,attachments.media_keys`
-			+ `&media.fields=url,width,height`
-			+ `&tweet.fields=created_at,public_metrics`
-			+ `&user.fields=profile_image_url`;
+		const endpointUrl = `https://api.twitter.com/2/tweets/${id}` +
+			`?expansions=author_id,attachments.media_keys` +
+			 `&media.fields=url,width,height` +
+			 `&tweet.fields=created_at,public_metrics` +
+			 `&user.fields=profile_image_url`;
 
 
 		const response = await fetch(endpointUrl, {
@@ -225,7 +225,7 @@ export const EmbedHandlers: { [key: string]: (url: URL) => Promise<Embed | Embed
 			// },
 		};
 
-		if (media) {
+		if (media.length > 0) {
 			embed.image = {
 				width: media[0].width,
 				height: media[0].height,