diff --git a/Controllers/ImageController.cs b/Controllers/ImageController.cs index 4b81c10..842ecd3 100644 --- a/Controllers/ImageController.cs +++ b/Controllers/ImageController.cs @@ -36,7 +36,16 @@ public async Task> Post([FromForm] IFormCollection formCollect } var sqlImageData = new SQLImageData(context); - foreach (IFormFile fileReader in (FormFileCollection)formCollection.Files) + var uploadImages = (FormFileCollection)formCollection.Files; + var imageMaxNumLimit = GlobalValues.appSetting?.Data?.Resources?.Images?.MaxNum ?? 0; + if((imageMaxNumLimit > 0) && (uploadImages.Count > imageMaxNumLimit)) + { + int indexStart = imageMaxNumLimit; + int indexCount = uploadImages.Count - imageMaxNumLimit; + uploadImages.RemoveRange(indexStart, indexCount); + } + + foreach (IFormFile fileReader in uploadImages) { try { @@ -54,9 +63,17 @@ public async Task> Post([FromForm] IFormCollection formCollect } else { - var image = await FileOperator.SaveImage(fileReader.OpenReadStream(), fileReader.FileName, imageDir); - images.Add(image); - imageUrls.Add($"{image.Url}"); + int imageMaxSizeLimit = GlobalValues.appSetting.Data.Resources.Images.MaxSize; + if((imageMaxSizeLimit <= 0) || fileReader.Length <= imageMaxSizeLimit*1024*1024) + { + var image = await FileOperator.SaveImage(fileReader.OpenReadStream(), fileReader.FileName, imageDir); + images.Add(image); + imageUrls.Add($"{image.Url}"); + } + else + { + imageUrls.Add(string.Empty); + } } } catch (Exception) diff --git a/Data/Database/imagebed.sqlite b/Data/Database/imagebed.sqlite index 1d0e64c..5e8a989 100644 Binary files a/Data/Database/imagebed.sqlite and b/Data/Database/imagebed.sqlite differ diff --git a/Data/Entity/AppSetting.cs b/Data/Entity/AppSetting.cs index 803513c..239eeef 100644 --- a/Data/Entity/AppSetting.cs +++ b/Data/Entity/AppSetting.cs @@ -93,6 +93,8 @@ public class Image { public string? Path { get; set; } public RenameFormat RenameFormat { get; set; } + public int MaxSize { get; set; } + public int MaxNum { get; set; } } diff --git a/Pages/Cog.razor b/Pages/Cog.razor index 4d9d941..838ebaa 100644 --- a/Pages/Cog.razor +++ b/Pages/Cog.razor @@ -19,6 +19,32 @@ OnFinish="OnFinish" OnFinishFailed="OnFinishFailed" Style="margin-top:80px;"> + + + + + + + + MB + + + + + + + + + + + + + 张 + + + + +