fix Bug 60214

This commit is contained in:
pavelbannov 2022-12-23 21:00:05 +03:00
parent 1266d817f8
commit 00b32e638a
5 changed files with 20 additions and 23 deletions

View File

@ -393,21 +393,16 @@ internal class FileDao : AbstractDao, IFileDao<int>
return SaveFileAsync(file, fileStream, true);
}
public Task<File<int>> SaveFileAsync(File<int> file, Stream fileStream, bool checkQuota = true)
public async Task<File<int>> SaveFileAsync(File<int> file, Stream fileStream, bool checkQuota = true)
{
ArgumentNullException.ThrowIfNull(file);
var maxChunkedUploadSize = _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic);
var maxChunkedUploadSize = await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic);
if (checkQuota && maxChunkedUploadSize < file.ContentLength)
{
throw FileSizeComment.GetFileSizeException(maxChunkedUploadSize);
}
return InternalSaveFileAsync(file, fileStream, checkQuota);
}
private async Task<File<int>> InternalSaveFileAsync(File<int> file, Stream fileStream, bool checkQuota = true)
{
if (checkQuota && _coreBaseSettings.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace"))
{
var personalMaxSpace = _coreConfiguration.PersonalMaxSpace(_settingsManager);
@ -585,18 +580,18 @@ internal class FileDao : AbstractDao, IFileDao<int>
throw new ArgumentException("No file id or folder id toFolderId determine provider");
}
var maxChunkedUploadSize = _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic);
return InternalReplaceFileVersionAsync(file, fileStream);
}
private async Task<File<int>> InternalReplaceFileVersionAsync(File<int> file, Stream fileStream)
{
var maxChunkedUploadSize = await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic);
if (maxChunkedUploadSize < file.ContentLength)
{
throw FileSizeComment.GetFileSizeException(maxChunkedUploadSize);
}
return InternalReplaceFileVersionAsync(file, fileStream);
}
private async Task<File<int>> InternalReplaceFileVersionAsync(File<int> file, Stream fileStream)
{
if (_coreBaseSettings.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace"))
{
var personalMaxSpace = _coreConfiguration.PersonalMaxSpace(_settingsManager);

View File

@ -944,7 +944,9 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
tmp = _coreConfiguration.PersonalMaxSpace(_settingsManager) - await _globalSpace.GetUserUsedSpaceAsync();
}
return Math.Min(tmp, chunkedUpload ? _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic) : _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic));
return Math.Min(tmp, chunkedUpload ?
await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic) :
await _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic));
}
private async Task RecalculateFoldersCountAsync(int id)

View File

@ -316,7 +316,7 @@ public class FileUploader
if (chunkLength > _setupInfo.ChunkUploadSize)
{
throw FileSizeComment.GetFileSizeException(_setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic));
throw FileSizeComment.GetFileSizeException(await _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic));
}
var maxUploadSize = await GetMaxFileSizeAsync(uploadSession.FolderId, uploadSession.BytesTotal > 0);

View File

@ -188,7 +188,7 @@ public class SecurityController : ControllerBase
}
[HttpPost("audit/login/report")]
public object CreateLoginHistoryReport()
public async Task<object> CreateLoginHistoryReport()
{
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -203,14 +203,14 @@ public class SecurityController : ControllerBase
var events = _loginEventsRepository.GetByFilter(fromDate: from, to: to);
using var stream = _auditReportCreator.CreateCsvReport(events);
var result = _auditReportSaver.UploadCsvReport(stream, reportName);
var result = await _auditReportSaver.UploadCsvReport(stream, reportName);
_messageService.Send(MessageAction.LoginHistoryReportDownloaded);
return result;
}
[HttpPost("audit/events/report")]
public object CreateAuditTrailReport()
public async Task<object> CreateAuditTrailReport()
{
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -228,7 +228,7 @@ public class SecurityController : ControllerBase
var events = _auditEventsRepository.GetByFilter(from: from, to: to);
using var stream = _auditReportCreator.CreateCsvReport(events);
var result = _auditReportSaver.UploadCsvReport(stream, reportName);
var result = await _auditReportSaver.UploadCsvReport(stream, reportName);
_messageService.Send(MessageAction.AuditTrailReportDownloaded);
return result;

View File

@ -49,9 +49,9 @@ public class SetupInfo
/// <summary>
/// Max possible file size for not chunked upload. Less or equal than 100 mb.
/// </summary>
public long MaxUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic)
public async Task<long> MaxUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic)
{
return Math.Min(AvailableFileSize, MaxChunkedUploadSize(tenantManager, maxTotalSizeStatistic));
return Math.Min(AvailableFileSize, await MaxChunkedUploadSize(tenantManager, maxTotalSizeStatistic));
}
public long AvailableFileSize
@ -201,12 +201,12 @@ public class SetupInfo
return _hideSettings == null || !_hideSettings.Contains(settings, StringComparer.CurrentCultureIgnoreCase);
}
public long MaxChunkedUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic)
public async Task<long> MaxChunkedUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic)
{
var diskQuota = tenantManager.GetCurrentTenantQuota();
if (diskQuota != null)
{
var usedSize = maxTotalSizeStatistic.GetValue().Result;
var usedSize = await maxTotalSizeStatistic.GetValue();
var freeSize = Math.Max(diskQuota.MaxTotalSize - usedSize, 0);
return Math.Min(freeSize, diskQuota.MaxFileSize);
}