Skip to content

Commit

Permalink
Merge branch 'hotfix/v3.0.1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySafronov committed Nov 28, 2024
2 parents 31a58da + e80aedd commit df68776
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 52 deletions.
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/ASC.Api.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="10.2.0" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="10.2.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" />

<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static async Task<IConnectionMultiplexer> GetRedisConnectionMultiplexerAs
}

var configurationOption = redisConfiguration.ConfigurationOptions;

configurationOption.DefaultDatabase = redisConfiguration.Database;
configurationOption.ClientName = clientName;

var redisConnection = await RedisPersistentConnection.InitializeAsync(configurationOption);
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Common/ASC.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
<PackageReference Include="StackExchange.Redis.Extensions.Core" Version="10.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="7.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ASC.EventBus\ASC.EventBus.csproj" />
Expand Down
9 changes: 1 addition & 8 deletions common/ASC.Common/Caching/Protobuf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,7 @@ public static T Deserialize<T>(byte[] data)

public static T Deserialize<T>(ReadOnlySpan<byte> data)
{
try
{
return Serializer.Deserialize<T>(data);
}
catch (ArgumentException) // concurrency handling
{
return Serializer.Deserialize<T>(data);
}
return Serializer.Deserialize<T>(data);
}
}

Expand Down
7 changes: 5 additions & 2 deletions common/ASC.Common/Utils/SwaggerCustomFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ private OpenApiSchema UpdateSchema(Type checkType, OpenApiSchema result)
result.Example = array;
}

if(arraySchema.OneOf != null)
if(arraySchema.OneOf.Count != 0)
{
result.Items = new OpenApiSchema { AnyOf = arraySchema.OneOf };
}
else if(checkType == typeof(object))
{
result.Items = new OpenApiSchema { Type = "object" };
}

}
else if(checkType == typeof(JsonElement))
Expand Down Expand Up @@ -261,7 +265,6 @@ private OpenApiSchema UpdateSchema(Type checkType, OpenApiSchema result)

return result;
}

private IOpenApiAny GetExample(object exampleValue)
{
return exampleValue switch
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Migration/ASC.Migration.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="FolkerKinzel.VCards" Version="7.2.2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.67" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Socket.IO/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getAndSaveAppsettings(){
if(redis != null)
{
redis.connect_timeout = redis.ConnectTimeout;
redis.db = redis.Database;
redis.database = redis.Database;
redis.username = redis.User;
redis.password = redis.Password;
redis.socket = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
using System.Text.Encodings.Web;

public class Programm
{
Expand Down Expand Up @@ -137,7 +138,13 @@ private static string ModifyJsonDocumentation(JsonObject jsonObject)
}
}
}
return jsonObject.ToJsonString(new JsonSerializerOptions { WriteIndented = true });
var options = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};

return jsonObject.ToJsonString(options);
}

private static string ModifyYamlDocumentation(string yamlData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WatermarkRequestDto
/// <summary>
/// Watermark Text
/// </summary>
[StringLength(265)]
[StringLength(255)]
public string Text { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,37 @@ public override async Task RunJob(DistributedTask distributedTask, CancellationT

var thirdPartyOperation = ThirdPartyOperation as FileDownloadOperation<string>;
var daoOperation = DaoOperation as FileDownloadOperation<int>;
await thirdPartyOperation.CompressToZipAsync(stream, scope);
await daoOperation.CompressToZipAsync(stream, scope);

if (stream != null)
{
string archiveExtension;

var thirdPartyFileOnly = thirdPartyOperation.Files.Count == 1 && thirdPartyOperation.Folders.Count == 0;
var daoFileOnly = daoOperation.Files.Count == 1 && daoOperation.Folders.Count == 0;
var compress = !((thirdPartyFileOnly || daoFileOnly) && (thirdPartyFileOnly != daoFileOnly));

string archiveExtension;

if (compress)
{
using (var zip = scope.ServiceProvider.GetService<CompressToArchive>())
{
archiveExtension = await zip.GetArchiveExtension();
}

await thirdPartyOperation.CompressToZipAsync(stream, scope);
await daoOperation.CompressToZipAsync(stream, scope);
}
else
{
if (thirdPartyFileOnly)
{
archiveExtension = await thirdPartyOperation.GetFileAsync(stream, scope);
}
else
{
archiveExtension = await daoOperation.GetFileAsync(stream, scope);
}
}

if (stream != null)
{
stream.Position = 0;
string fileName;

Expand All @@ -109,6 +128,10 @@ public override async Task RunJob(DistributedTask distributedTask, CancellationT
(await daoFactory.GetFolderDao<string>().GetFolderAsync(thirdPartyOperation.Folders[0])).Title :
(await daoFactory.GetFolderDao<int>().GetFolderAsync(daoOperation.Folders[0])).Title)}{archiveExtension}";
}
else if (!compress)
{
fileName = archiveExtension;
}
else
{
fileName = $@"{(await tenantManager.GetCurrentTenantAsync()).Alias.ToLower()}-{FileConstant.DownloadTitle}-{DateTime.UtcNow.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}{archiveExtension}";
Expand Down Expand Up @@ -373,7 +396,7 @@ internal async Task CompressToZipAsync(Stream stream, IServiceScope scope)
var fileConverter = scope.ServiceProvider.GetService<FileConverter>();
var fileDao = scope.ServiceProvider.GetService<IFileDao<T>>();

using var compressTo = scope.ServiceProvider.GetService<CompressToArchive>();
using ICompress compressTo = scope.ServiceProvider.GetService<CompressToArchive>();
await compressTo.SetStream(stream);

foreach (var path in _entriesPathId.AllKeys)
Expand Down Expand Up @@ -478,6 +501,88 @@ await fileConverter.ExecAsync(file, convertToExt) :
await ProgressStep();
}
}

internal async Task<string> GetFileAsync(Stream stream, IServiceScope scope)
{
if (_entriesPathId == null)
{
return null;
}

var fileConverter = scope.ServiceProvider.GetService<FileConverter>();
var fileDao = scope.ServiceProvider.GetService<IFileDao<T>>();

var path = _entriesPathId.AllKeys.FirstOrDefault();
if (string.IsNullOrEmpty(path))
{
await ProgressStep();
return null;
}

var entryId = _entriesPathId[path].FirstOrDefault();
if (CancellationToken.IsCancellationRequested)
{
CancellationToken.ThrowIfCancellationRequested();
}

var newTitle = path;

File<T> file = null;
var convertToExt = string.Empty;

if (!Equals(entryId, default(T)))
{
await fileDao.InvalidateCacheAsync(entryId);
file = await fileDao.GetFileAsync(entryId);

if (file == null)
{
this[Err] = FilesCommonResource.ErrorMessage_FileNotFound;
return null;
}

if (_files.TryGetValue(file.Id, out convertToExt) && !string.IsNullOrEmpty(convertToExt))
{
var sourceFileName = Path.GetFileName(path);
var targetFileName = FileUtility.ReplaceFileExtension(sourceFileName, convertToExt);
newTitle = path.Replace(sourceFileName, targetFileName);
}
}

if (!Equals(entryId, default(T)))
{
try
{
await using var readStream = await fileConverter.EnableConvertAsync(file, convertToExt, true) ?
await fileConverter.ExecAsync(file, convertToExt) :
await fileDao.GetFileStreamAsync(file);

await readStream.CopyToAsync(stream);
}
catch (Exception ex)
{
this[Err] = ex.Message;

Logger.ErrorWithException(ex);
}
}


if (!Equals(entryId, default(T)))
{
ProcessedFile(entryId);
}
else
{
ProcessedFolder(default);
}


await ProgressStep();


return newTitle;
}

private void ReplaceLongPath(ItemNameValueCollection<T> entriesPathId)
{
Expand Down
37 changes: 16 additions & 21 deletions products/ASC.Files/Core/Utils/FileTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<bool> ProlongEditingAsync<T>(T fileId, Guid tabId, Guid userId
}
else
{
tracker.EditingBy.Add(tabId,
tracker.EditingBy.TryAdd(tabId,
new TrackInfo
{
UserId = userId,
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task RemoveAsync<T>(T fileId, Guid tabId = default, Guid userId = d
{
if (tabId != Guid.Empty)
{
tracker.EditingBy.Remove(tabId);
tracker.EditingBy.TryRemove(tabId, out _);
await SetTrackerAsync(fileId, tracker);

return;
Expand All @@ -132,7 +132,7 @@ public async Task RemoveAsync<T>(T fileId, Guid tabId = default, Guid userId = d

foreach (var editTab in listForRemove)
{
tracker.EditingBy.Remove(editTab.Key);
tracker.EditingBy.TryRemove(editTab.Key, out _);
}

await SetTrackerAsync(fileId, tracker);
Expand All @@ -155,10 +155,10 @@ public async Task<bool> IsEditingAsync<T>(T fileId)

foreach (var editTab in listForRemove)
{
tracker.EditingBy.Remove(editTab.Key);
tracker.EditingBy.TryRemove(editTab.Key, out _);
}

if (tracker.EditingBy.Count == 0)
if (tracker.EditingBy.IsEmpty)
{
await RemoveTrackerAsync(fileId);

Expand Down Expand Up @@ -323,27 +323,22 @@ public record FileTrackerNotify
public record FileTracker
{
[ProtoMember(1)]
public Dictionary<Guid, TrackInfo> EditingBy { get; set; }
public ConcurrentDictionary<Guid, TrackInfo> EditingBy { get; set; }

public FileTracker() { }

internal FileTracker(Guid tabId, Guid userId, bool newScheme, bool editingAlone, int tenantId, string baseUri, string token = null)
{
EditingBy = new Dictionary<Guid, TrackInfo>
{
{
tabId,
new TrackInfo
{
UserId = userId,
NewScheme = newScheme,
EditingAlone = editingAlone,
TenantId = tenantId,
BaseUri = baseUri,
Token = token
}
}
};
EditingBy = new ConcurrentDictionary<Guid, TrackInfo>();
EditingBy.TryAdd(tabId, new TrackInfo
{
UserId = userId,
NewScheme = newScheme,
EditingAlone = editingAlone,
TenantId = tenantId,
BaseUri = baseUri,
Token = token
});
}

[ProtoContract]
Expand Down
Loading

0 comments on commit df68776

Please sign in to comment.