diff --git a/TASVideos.Common/Constants.cs b/TASVideos.Common/Constants.cs
index 0d29ce00a..db34facff 100644
--- a/TASVideos.Common/Constants.cs
+++ b/TASVideos.Common/Constants.cs
@@ -70,7 +70,8 @@ The posts after this message will continue to apply to the submission.
public const string DefaultPublicationText = "''[TODO]: describe this movie here''";
- public const int MaximumMovieSize = 2048 * 1024;
+ public const int MaximumMovieSize = 2 * 1024 * 1024;
+ public const string MaximumMovieSizeHumanReadable = "2 MiB";
public const int UserFileStorageLimit = 1000 * 1000 * 50; // 50 MB
public const int GamesForumCategory = 5;
diff --git a/TASVideos/Extensions/FormFileExtensions.cs b/TASVideos/Extensions/FormFileExtensions.cs
index 6688f328b..db2f05a37 100644
--- a/TASVideos/Extensions/FormFileExtensions.cs
+++ b/TASVideos/Extensions/FormFileExtensions.cs
@@ -1,4 +1,8 @@
using System.IO.Compression;
+using System.Runtime.CompilerServices;
+using System.Security.Claims;
+
+using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace TASVideos.Extensions;
@@ -44,14 +48,16 @@ public static bool IsCompressed(this IFormFile? formFile)
|| compressedContentTypes.Contains(formFile.ContentType);
}
- public static bool LessThanMovieSizeLimit(this IFormFile? formFile)
+ public static void AddModelErrorIfOverSizeLimit(
+ this IFormFile movie,
+ ModelStateDictionary modelState,
+ ClaimsPrincipal user,
+ [CallerArgumentExpression(nameof(movie))] string movieFieldName = default!)
{
- if (formFile is null)
+ if (!user.Has(PermissionTo.OverrideSubmissionConstraints) && movie.Length >= SiteGlobalConstants.MaximumMovieSize)
{
- return true;
+ modelState.AddModelError(movieFieldName, ".zip is too big, are you sure this is a valid movie file?");
}
-
- return formFile.Length < SiteGlobalConstants.MaximumMovieSize;
}
public static bool IsValidImage(this IFormFile? formFile)
diff --git a/TASVideos/Pages/Publications/AdditionalMovies.cshtml b/TASVideos/Pages/Publications/AdditionalMovies.cshtml
index 3793d33d6..8487eff35 100644
--- a/TASVideos/Pages/Publications/AdditionalMovies.cshtml
+++ b/TASVideos/Pages/Publications/AdditionalMovies.cshtml
@@ -42,7 +42,7 @@
diff --git a/TASVideos/Pages/Publications/AdditionalMovies.cshtml.cs b/TASVideos/Pages/Publications/AdditionalMovies.cshtml.cs
index ea20fa732..61c1f2cfd 100644
--- a/TASVideos/Pages/Publications/AdditionalMovies.cshtml.cs
+++ b/TASVideos/Pages/Publications/AdditionalMovies.cshtml.cs
@@ -60,12 +60,7 @@ public async Task OnPost()
ModelState.AddModelError(nameof(AdditionalMovieFile), "Not a valid .zip file");
}
- if (!AdditionalMovieFile.LessThanMovieSizeLimit())
- {
- ModelState.AddModelError(
- nameof(AdditionalMovieFile),
- ".zip is too big, are you sure this is a valid movie file?");
- }
+ AdditionalMovieFile?.AddModelErrorIfOverSizeLimit(ModelState, User);
if (!ModelState.IsValid)
{
diff --git a/TASVideos/Pages/Publications/PrimaryMovie.cshtml b/TASVideos/Pages/Publications/PrimaryMovie.cshtml
index f4263d04c..f436922f6 100644
--- a/TASVideos/Pages/Publications/PrimaryMovie.cshtml
+++ b/TASVideos/Pages/Publications/PrimaryMovie.cshtml
@@ -17,7 +17,7 @@
diff --git a/TASVideos/Pages/Publications/PrimaryMovie.cshtml.cs b/TASVideos/Pages/Publications/PrimaryMovie.cshtml.cs
index b59e37994..7f401f196 100644
--- a/TASVideos/Pages/Publications/PrimaryMovie.cshtml.cs
+++ b/TASVideos/Pages/Publications/PrimaryMovie.cshtml.cs
@@ -54,6 +54,8 @@ public async Task OnPost()
ModelState.AddModelError(nameof(PrimaryMovieFile), $"A publication with the filename {PrimaryMovieFile!.FileName} already exists.");
}
+ PrimaryMovieFile?.AddModelErrorIfOverSizeLimit(ModelState, User);
+
if (!ModelState.IsValid)
{
PublicationTitle = publication.Title;
diff --git a/TASVideos/Pages/Submissions/Edit.cshtml b/TASVideos/Pages/Submissions/Edit.cshtml
index d974f0116..2e7e82242 100644
--- a/TASVideos/Pages/Submissions/Edit.cshtml
+++ b/TASVideos/Pages/Submissions/Edit.cshtml
@@ -21,7 +21,7 @@
@@ -52,8 +52,9 @@
@@ -70,7 +71,8 @@
diff --git a/TASVideos/Pages/Submissions/Edit.cshtml.cs b/TASVideos/Pages/Submissions/Edit.cshtml.cs
index d99b65ae7..1cb094f1f 100644
--- a/TASVideos/Pages/Submissions/Edit.cshtml.cs
+++ b/TASVideos/Pages/Submissions/Edit.cshtml.cs
@@ -114,10 +114,7 @@ public async Task OnPost()
ModelState.AddModelError(FileFieldName, "Not a valid .zip file");
}
- if (!User.Has(PermissionTo.OverrideSubmissionConstraints) && !Submission.ReplaceMovieFile.LessThanMovieSizeLimit())
- {
- ModelState.AddModelError(FileFieldName, ".zip is too big, are you sure this is a valid movie file?");
- }
+ Submission.ReplaceMovieFile?.AddModelErrorIfOverSizeLimit(ModelState, User, movieFieldName: FileFieldName);
}
else if (!User.Has(PermissionTo.ReplaceSubmissionMovieFile))
{
diff --git a/TASVideos/Pages/Submissions/Submit.cshtml b/TASVideos/Pages/Submissions/Submit.cshtml
index 2081ececf..178bac9db 100644
--- a/TASVideos/Pages/Submissions/Submit.cshtml
+++ b/TASVideos/Pages/Submissions/Submit.cshtml
@@ -22,7 +22,7 @@
@@ -44,7 +44,7 @@
diff --git a/TASVideos/Pages/Submissions/Submit.cshtml.cs b/TASVideos/Pages/Submissions/Submit.cshtml.cs
index eae6781e1..e4239f4e2 100644
--- a/TASVideos/Pages/Submissions/Submit.cshtml.cs
+++ b/TASVideos/Pages/Submissions/Submit.cshtml.cs
@@ -191,10 +191,7 @@ private async Task ValidateModel()
ModelState.AddModelError(FileFieldName, "Not a valid .zip file");
}
- if (!MovieFile.LessThanMovieSizeLimit())
- {
- ModelState.AddModelError(FileFieldName, ".zip is too big, are you sure this is a valid movie file?");
- }
+ MovieFile?.AddModelErrorIfOverSizeLimit(ModelState, User, movieFieldName: FileFieldName);
foreach (var author in Authors)
{