summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-30 00:32:12 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-30 00:32:12 +1000
commite5011bc121f8594d8743fe91553e1a1689ba1fdb (patch)
tree67c96ba58da8e6f369533ac488546b6e4147ffad
parentTest embeding image/png etc responses (diff)
downloadserver-e5011bc121f8594d8743fe91553e1a1689ba1fdb.tar.xz
if tenor or giphy is sent, embed image rather than thumbnail
-rw-r--r--api/src/util/handlers/Message.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts
index a74e57dd..a6754bd1 100644
--- a/api/src/util/handlers/Message.ts
+++ b/api/src/util/handlers/Message.ts
@@ -215,6 +215,29 @@ export async function postHandleMessage(message: Message) {
 				if (url) embed.url = url;
 				if (description) embed.description = description;
 
+				const approvedProviders = [
+					"media4.giphy.com",
+					"c.tenor.com",
+					// todo: make configurable? don't really care tho
+				];
+
+				// very bad code below
+				// don't care lol
+				if (embed?.thumbnail?.url && approvedProviders.indexOf(new URL(embed.thumbnail.url).hostname) !== -1) {
+					embed = {
+						provider: {
+							url: link,
+							name: new URL(link).hostname,
+						},
+						image: {
+							proxy_url: `${endpointPublic}/external/resize/${encodeURIComponent(image!)}?width=${resizeWidth}&height=${resizeHeight}`,
+							url: image,
+							width: width,
+							height: height
+						}
+					};
+				}
+
 				if (title || description) {
 					data.embeds.push(embed);
 				}