Skip to content

Commit

Permalink
Fixed the CheckFileSize method in FileManagerBase
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Oct 26, 2023
1 parent a586eb1 commit 5b34555
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>4.0.0-preview.9</Version>
<Version>4.0.0-preview.10</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,15 @@ protected virtual void CheckFileQuantity(int count, IFileContainerConfiguration
}
}

protected virtual void CheckFileSize(Dictionary<string, long> fileNameByteSizeMapping,
protected virtual void CheckFileSize(List<(string, long)> fileNameByteSizes,
IFileContainerConfiguration configuration)
{
foreach (var pair in fileNameByteSizeMapping.Where(
pair => pair.Value > configuration.MaxByteSizeForEachFile))
foreach (var tuple in fileNameByteSizes.Where(tuple => tuple.Item2 > configuration.MaxByteSizeForEachFile))
{
throw new FileSizeExceededLimitException(pair.Key, pair.Value, configuration.MaxByteSizeForEachFile);
throw new FileSizeExceededLimitException(tuple.Item1, tuple.Item2, configuration.MaxByteSizeForEachFile);
}

var totalByteSize = fileNameByteSizeMapping.Values.Sum();
var totalByteSize = fileNameByteSizes.Select(x => x.Item2).Sum();

if (totalByteSize > configuration.MaxByteSizeForEachUpload)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class FileManager : FileManagerBase, IFileManager

if (model.FileType == FileType.RegularFile)
{
CheckFileSize(new Dictionary<string, long> { { model.FileName, model.GetContentLength() } },
configuration);
CheckFileSize(new List<(string, long)> { (model.FileName, model.GetContentLength()) }, configuration);
CheckFileExtension(new[] { model.FileName }, configuration);
}

Expand Down Expand Up @@ -127,8 +126,7 @@ public class FileManager : FileManagerBase, IFileManager
FileContainerConfigurationProvider.Get<FileContainerConfiguration>(models.First().FileContainerName);

CheckFileQuantity(models.Count, configuration);
CheckFileSize(models.ToDictionary(x => x.FileName, x => x.GetContentLength()),
configuration);
CheckFileSize(models.Select(x => (x.FileName, x.GetContentLength())).ToList(), configuration);

foreach (var model in models)
{
Expand Down

0 comments on commit 5b34555

Please sign in to comment.