From 1fa7dded9886d5e187928f34a22306e7865e0392 Mon Sep 17 00:00:00 2001
From: salixor <salixor@pm.me>
Date: Thu, 26 Dec 2024 19:16:13 +0100
Subject: [PATCH] Dl a smaller thumbnail and hopefully work

---
 src/matrixeventprocessor.ts | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts
index c546f98..a9c06d1 100644
--- a/src/matrixeventprocessor.ts
+++ b/src/matrixeventprocessor.ts
@@ -38,6 +38,8 @@ const log = new Log("MatrixEventProcessor");
 const MaxFileSize = 8000000;
 const MIN_NAME_LENGTH = 2;
 const MAX_NAME_LENGTH = 32;
+const DISCORD_AVATAR_WIDTH = 128;
+const DISCORD_AVATAR_HEIGHT = 128;
 const AGE_LIMIT = 900000; // 15 * 60 * 1000
 const PROFILE_CACHE_LIFETIME = 900000;
 
@@ -522,8 +524,17 @@ export class MatrixEventProcessor {
         }
 
         if (profile?.avatar_url) {
-            const attachment = await this.bridge.botClient.downloadContent(profile.avatar_url);
-            const base64 = `data:${attachment.contentType};base64,${attachment.data.toString('base64')}`;
+            avatarUrl = await this.bridge.botClient.mxcToHttpThumbnail(
+                profile.avatar_url,
+                DISCORD_AVATAR_WIDTH,
+                DISCORD_AVATAR_HEIGHT,
+                "scale",
+            );
+            // eslint-disable-next-line @typescript-eslint/naming-convention
+            const res = await this.bridge.botClient.doRequest("GET", avatarUrl, { allow_remote: true }, null, undefined, true, undefined, true);
+            const contentType = res.headers["content-type"];
+            const data = res.body;
+            const base64 = `data:${contentType};base64,${data.toString('base64')}`;
             avatarUrl = base64;
         }
 
-- 
GitLab