summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-09 16:01:32 +1000
committerErkin Alp Güney <erkinalp9035@gmail.com>2022-07-09 09:45:28 +0300
commit90eabd933b3777ec4fc47719b41a58fb70b66916 (patch)
treed4d689e937d3e2889cc3414c01708d95b7f36249
parentMerge pull request #783 from MaddyUnderStars/feat/multiUploads (diff)
downloadserver-90eabd933b3777ec4fc47719b41a58fb70b66916.tar.xz
* Make max website preview download size for embeds configurable
* Fix Message.update call throwing 'Cannot query across one-to-many for property attachments'
-rw-r--r--api/src/util/handlers/Message.ts9
-rw-r--r--util/src/entities/Config.ts2
2 files changed, 8 insertions, 3 deletions
diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts
index e9f0ac55..48f87dfe 100644
--- a/api/src/util/handlers/Message.ts
+++ b/api/src/util/handlers/Message.ts
@@ -38,7 +38,7 @@ const DEFAULT_FETCH_OPTIONS: any = {
 	headers: {
 		"user-agent": "Mozilla/5.0 (compatible; Fosscord/1.0; +https://github.com/fosscord/fosscord)"
 	},
-	size: 1024 * 1024 * 1,
+	// size: 1024 * 1024 * 5, 	// grabbed from config later
 	compress: true,
 	method: "GET"
 };
@@ -154,7 +154,10 @@ export async function postHandleMessage(message: Message) {
 
 	for (const link of links) {
 		try {
-			const request = await fetch(link, DEFAULT_FETCH_OPTIONS);
+			const request = await fetch(link, {
+				...DEFAULT_FETCH_OPTIONS,
+				size: Config.get().limits.message.maxEmbedDownloadSize,
+			});
 
 			const text = await request.text();
 			const $ = cheerio.load(text);
@@ -191,7 +194,7 @@ export async function postHandleMessage(message: Message) {
 			channel_id: message.channel_id,
 			data
 		} as MessageUpdateEvent),
-		Message.update({ id: message.id, channel_id: message.channel_id }, data)
+		Message.update({ id: message.id, channel_id: message.channel_id }, { embeds: data.embeds })
 	]);
 }
 
diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts
index 063a4d4d..75ff4a85 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -85,6 +85,7 @@ export interface ConfigValue {
 			maxReactions: number;
 			maxAttachmentSize: number;
 			maxBulkDelete: number;
+			maxEmbedDownloadSize: number;
 		};
 		channel: {
 			maxPins: number;
@@ -249,6 +250,7 @@ export const DefaultConfigOptions: ConfigValue = {
 			maxTTSCharacters: 200,
 			maxReactions: 20,
 			maxAttachmentSize: 8388608,
+			maxEmbedDownloadSize: 1024 * 1024 * 5,
 			maxBulkDelete: 100,
 		},
 		channel: {