From d62d13bcbf9e7ad5299d2fdf6566671f6c6099b6 Mon Sep 17 00:00:00 2001 From: Maksim Chegulov Date: Tue, 16 Jan 2024 19:54:26 +0300 Subject: [PATCH] fix Bug 65837 --- .../Core/Core/Security/ExternalShare.cs | 14 +++------- .../Core/Core/VirtualRooms/RoomLogoManager.cs | 27 ++++++++++--------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/products/ASC.Files/Core/Core/Security/ExternalShare.cs b/products/ASC.Files/Core/Core/Security/ExternalShare.cs index 668bda8f01c..36cf9c34e3a 100644 --- a/products/ASC.Files/Core/Core/Security/ExternalShare.cs +++ b/products/ASC.Files/Core/Core/Security/ExternalShare.cs @@ -297,17 +297,9 @@ public string GetUrlWithShare(string url, string key = null) key ??= GetKey(); - if (string.IsNullOrEmpty(key)) - { - return url; - } - - var uriBuilder = new UriBuilder(url); - var query = HttpUtility.ParseQueryString(uriBuilder.Query); - query[FilesLinkUtility.ShareKey] = key; - uriBuilder.Query = query.ToString() ?? string.Empty; - - return uriBuilder.ToString(); + return !string.IsNullOrEmpty(key) + ? QueryHelpers.AddQueryString(url, FilesLinkUtility.ShareKey, key) + : url; } private async Task CreateShareKeyAsync(Guid linkId) diff --git a/products/ASC.Files/Core/Core/VirtualRooms/RoomLogoManager.cs b/products/ASC.Files/Core/Core/VirtualRooms/RoomLogoManager.cs index 1febf8f6962..4948c8e7316 100644 --- a/products/ASC.Files/Core/Core/VirtualRooms/RoomLogoManager.cs +++ b/products/ASC.Files/Core/Core/VirtualRooms/RoomLogoManager.cs @@ -51,6 +51,7 @@ public class RoomLogoManager private readonly EmailValidationKeyProvider _emailValidationKeyProvider; private readonly SecurityContext _securityContext; private readonly FileUtilityConfiguration _fileUtilityConfiguration; + private readonly ExternalShare _externalShare; public RoomLogoManager( StorageFactory storageFactory, @@ -61,7 +62,8 @@ public RoomLogoManager( FilesMessageService filesMessageService, EmailValidationKeyProvider emailValidationKeyProvider, SecurityContext securityContext, - FileUtilityConfiguration fileUtilityConfiguration) + FileUtilityConfiguration fileUtilityConfiguration, + ExternalShare externalShare) { _storageFactory = storageFactory; _tenantManager = tenantManager; @@ -72,6 +74,7 @@ public RoomLogoManager( _emailValidationKeyProvider = emailValidationKeyProvider; _securityContext = securityContext; _fileUtilityConfiguration = fileUtilityConfiguration; + _externalShare = externalShare; } public bool EnableAudit { get; set; } = true; @@ -265,12 +268,12 @@ private async Task SaveWithProcessAsync(IDataStore store, string id, byte[] imag using (var stream = new MemoryStream(imageData)) { await store.SaveAsync(fileName, stream); - } + } var sizes = new[] { _mediumLogoSize, _smallLogoSize, _largeLogoSize}; if (imageData is not { Length: > 0 }) - { + { throw new Web.Core.Users.UnknownImageFormatException(); } if (maxFileSize != -1 && imageData.Length > maxFileSize) @@ -284,21 +287,21 @@ private async Task SaveWithProcessAsync(IDataStore store, string id, byte[] imag using var img = await Image.LoadAsync(imageStream); foreach (var size in sizes) { - if (size.Item2 != img.Size) - { - using var img2 = UserPhotoThumbnailManager.GetImage(img, size.Item2, new UserPhotoThumbnailSettings(position, cropSize)); + if (size.Item2 != img.Size) + { + using var img2 = UserPhotoThumbnailManager.GetImage(img, size.Item2, new UserPhotoThumbnailSettings(position, cropSize)); imageData = CommonPhotoManager.SaveToBytes(img2); - } - else - { + } + else + { imageData = CommonPhotoManager.SaveToBytes(img); - } + } var imageFileName = string.Format(LogosPath, ProcessFolderId(id), size.Item1.ToStringLowerFast()); using var stream2 = new MemoryStream(imageData); await store.SaveAsync(imageFileName, stream2); - } + } } catch (ArgumentException error) { @@ -315,7 +318,7 @@ private async ValueTask GetLogoPathAsync(T id, SizeName size, int has var uri = await store.GetPreSignedUriAsync(string.Empty, fileName, TimeSpan.MaxValue, headers); - return uri + (secure ? "&" : "?") + $"hash={hash}"; + return _externalShare.GetUrlWithShare(uri + (secure ? "&" : "?") + $"hash={hash}"); } private async Task GetTempAsync(IDataStore store, string fileName)