Skip to content

Commit

Permalink
Merge pull request #152 from ONLYOFFICE/bugfix/65837
Browse files Browse the repository at this point in the history
Bugfix/65837
  • Loading branch information
pavelbannov authored Jan 17, 2024
2 parents 37045a7 + d62d13b commit 2cf6921
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
14 changes: 3 additions & 11 deletions products/ASC.Files/Core/Core/Security/ExternalShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> CreateShareKeyAsync(Guid linkId)
Expand Down
27 changes: 15 additions & 12 deletions products/ASC.Files/Core/Core/VirtualRooms/RoomLogoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -61,7 +62,8 @@ public RoomLogoManager(
FilesMessageService filesMessageService,
EmailValidationKeyProvider emailValidationKeyProvider,
SecurityContext securityContext,
FileUtilityConfiguration fileUtilityConfiguration)
FileUtilityConfiguration fileUtilityConfiguration,
ExternalShare externalShare)
{
_storageFactory = storageFactory;
_tenantManager = tenantManager;
Expand All @@ -72,6 +74,7 @@ public RoomLogoManager(
_emailValidationKeyProvider = emailValidationKeyProvider;
_securityContext = securityContext;
_fileUtilityConfiguration = fileUtilityConfiguration;
_externalShare = externalShare;
}

public bool EnableAudit { get; set; } = true;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -315,7 +318,7 @@ private async ValueTask<string> GetLogoPathAsync<T>(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<byte[]> GetTempAsync(IDataStore store, string fileName)
Expand Down

0 comments on commit 2cf6921

Please sign in to comment.