s3: add limit on download file size

This commit is contained in:
Abdullah Atta
2025-10-02 13:36:38 +05:00
committed by Abdullah Atta
parent 3bb140aeb3
commit 61dd2e1f74
4 changed files with 43 additions and 10 deletions
+12 -2
View File
@@ -160,14 +160,24 @@ namespace Notesnook.API.Services
return this.GetPresignedURL(userId, name, HttpVerb.PUT);
}
public string GetDownloadObjectUrl(string userId, string name)
public async Task<string?> GetDownloadObjectUrl(string userId, string name)
{
var subscriptionService = await WampServers.SubscriptionServer.GetServiceAsync<IUserSubscriptionService>(SubscriptionServerTopics.UserSubscriptionServiceTopic);
var subscription = await subscriptionService.GetUserSubscriptionAsync(Clients.Notesnook.Id, userId);
var size = await GetObjectSizeAsync(userId, name);
if (StorageHelper.IsFileSizeExceeded(subscription, size))
{
var fileSizeLimit = StorageHelper.GetFileSizeLimitForPlan(subscription);
throw new Exception($"You cannot download files larger than {StorageHelper.FormatBytes(fileSizeLimit)} on this plan.");
}
var url = this.GetPresignedURL(userId, name, HttpVerb.GET);
if (url == null) return null;
return url;
}
public async Task<MultipartUploadMeta> StartMultipartUploadAsync(string userId, string name, int parts, string uploadId = null)
public async Task<MultipartUploadMeta> StartMultipartUploadAsync(string userId, string name, int parts, string? uploadId = null)
{
var objectName = GetFullObjectName(userId, name);
if (userId == null || objectName == null) throw new Exception("Could not initiate multipart upload.");