|
6 | 6 | using System.Net.Mime; |
7 | 7 | using System.Threading.Tasks; |
8 | 8 | using elFinder.NetCore.Drawing; |
| 9 | +using elFinder.NetCore.Exceptions; |
9 | 10 | using elFinder.NetCore.Extensions; |
10 | 11 | using elFinder.NetCore.Helpers; |
11 | 12 | using elFinder.NetCore.Models; |
@@ -767,6 +768,44 @@ public async Task<JsonResult> UploadAsync(FullPath path, IEnumerable<IFormFile> |
767 | 768 | } |
768 | 769 | } |
769 | 770 |
|
| 771 | + if (path.RootVolume.UploadOrder != null) |
| 772 | + { |
| 773 | + foreach (var file in files) |
| 774 | + { |
| 775 | + var mimeType = MimeHelper.GetMimeType(Path.GetExtension(file.FileName)); |
| 776 | + var constraintMap = new Dictionary<string, IEnumerable<string>> |
| 777 | + { |
| 778 | + ["allow"] = path.RootVolume.UploadAllow, |
| 779 | + ["deny"] = path.RootVolume.UploadDeny, |
| 780 | + }; |
| 781 | + |
| 782 | + foreach (var constraintType in path.RootVolume.UploadOrder) |
| 783 | + { |
| 784 | + var constraint = constraintMap[constraintType]; |
| 785 | + if (constraint == null) continue; |
| 786 | + switch (constraintType) |
| 787 | + { |
| 788 | + case "allow": |
| 789 | + { |
| 790 | + if (!constraint.Contains("all") |
| 791 | + && !constraint.Contains(mimeType) |
| 792 | + && !constraint.Contains(mimeType.Type)) |
| 793 | + throw new FileTypeNotAllowException(); |
| 794 | + break; |
| 795 | + } |
| 796 | + case "deny": |
| 797 | + { |
| 798 | + if (constraint.Contains("all") |
| 799 | + || constraint.Contains(mimeType) |
| 800 | + || constraint.Contains(mimeType.Type)) |
| 801 | + throw new FileTypeNotAllowException(); |
| 802 | + break; |
| 803 | + } |
| 804 | + } |
| 805 | + } |
| 806 | + } |
| 807 | + } |
| 808 | + |
770 | 809 | foreach (string rename in renames) |
771 | 810 | { |
772 | 811 | var fileInfo = new FileInfo(Path.Combine(path.Directory.FullName, rename)); |
|
0 commit comments