From 962b8050541bfb29bba7b55611982f88a74b76a5 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 29 Aug 2024 12:20:32 +0500 Subject: [PATCH] api: remove s3 objects bigger than the maximum size --- Notesnook.API/Services/S3Service.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Notesnook.API/Services/S3Service.cs b/Notesnook.API/Services/S3Service.cs index 4b50b8c..05e91c2 100644 --- a/Notesnook.API/Services/S3Service.cs +++ b/Notesnook.API/Services/S3Service.cs @@ -145,6 +145,12 @@ namespace Notesnook.API.Services var request = new HttpRequestMessage(HttpMethod.Head, url); var response = await httpClient.SendAsync(request); + const long MAX_SIZE = 513 * 1024 * 1024; // 512 MB + if (!Constants.IS_SELF_HOSTED && response.Content.Headers.ContentLength >= MAX_SIZE) + { + await this.DeleteObjectAsync(userId, name); + throw new Exception("File size exceeds the maximum allowed size."); + } return response.Content.Headers.ContentLength ?? 0; }