summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-09-03 15:28:33 -0400
committerPuyodead1 <puyodead@proton.me>2023-09-03 15:28:33 -0400
commit1612832fc4f782a29988d2c9a1b928cfc00429e3 (patch)
treefdc0b57956aedfc4246f7417c44d1da03c1a1b88 /src/api
parentRewrite thumbnail/image generation for embeds (diff)
downloadserver-1612832fc4f782a29988d2c9a1b928cfc00429e3.tar.xz
add facebook, and add steam fields
Diffstat (limited to 'src/api')
-rw-r--r--src/api/util/utility/EmbedHandlers.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts
index b1e6b866..430ca4aa 100644
--- a/src/api/util/utility/EmbedHandlers.ts
+++ b/src/api/util/utility/EmbedHandlers.ts
@@ -226,8 +226,23 @@ export const EmbedHandlers: {
 	"c.tenor.com": genericImageHandler,
 	"media.tenor.com": genericImageHandler,
 
-	// TODO: facebook
-	// have to use their APIs or something because they don't send the metas in initial html
+	"facebook.com": (url) => EmbedHandlers["www.facebook.com"](url),
+	"www.facebook.com": async (url: URL) => {
+		const response = await doFetch(url);
+		if (!response) return null;
+		const metas = getMetaDescriptions(await response.text());
+
+		return {
+			url: url.href,
+			type: EmbedType.link,
+			title: metas.title,
+			description: metas.description,
+			thumbnail: makeEmbedImage(metas.image, 640, 640),
+			provider: {
+				name: "Facebook",
+			},
+		};
+	},
 
 	"twitter.com": (url) => EmbedHandlers["www.twitter.com"](url),
 	"www.twitter.com": async (url: URL) => {
@@ -385,6 +400,42 @@ export const EmbedHandlers: {
 		const response = await doFetch(url);
 		if (!response) return null;
 		const metas = getMetaDescriptions(await response.text());
+		const numReviews = metas.$("#review_summary_num_reviews").val() as
+			| string
+			| undefined;
+		const price = metas
+			.$(".game_purchase_price.price")
+			.data("price-final") as number | undefined;
+		const releaseDate = metas
+			.$(".release_date")
+			.find("div.date")
+			.text()
+			.trim();
+		const isReleased = new Date(releaseDate) < new Date();
+
+		const fields: Embed["fields"] = [];
+
+		if (numReviews)
+			fields.push({
+				name: "Reviews",
+				value: numReviews,
+				inline: true,
+			});
+
+		if (price)
+			fields.push({
+				name: "Price",
+				value: `$${price / 100}`,
+				inline: true,
+			});
+
+		// if the release date is in the past, it's already out
+		if (releaseDate && !isReleased)
+			fields.push({
+				name: "Release Date",
+				value: releaseDate,
+				inline: true,
+			});
 
 		return {
 			url: url.href,
@@ -405,7 +456,7 @@ export const EmbedHandlers: {
 				url: "https://store.steampowered.com",
 				name: "Steam",
 			},
-			// TODO: fields for release date
+			fields,
 			// TODO: Video
 		};
 	},