Skip to content

Commit

Permalink
A couple clarifications on sub create/edit forms (#2059)
Browse files Browse the repository at this point in the history
* Unify movie upload size checks

fixes 571caa7, e244d17

* Standardise submission create/edit UIs

* Clarify supported encode providers when editing subs
  • Loading branch information
YoshiRulz authored Dec 19, 2024
1 parent be53468 commit 93844af
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
3 changes: 2 additions & 1 deletion TASVideos.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions TASVideos/Extensions/FormFileExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.IO.Compression;
using System.Runtime.CompilerServices;
using System.Security.Claims;

using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace TASVideos.Extensions;

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Publications/AdditionalMovies.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<fieldset>
<label asp-for="AdditionalMovieFile">Add an additional movie file</label>
<input asp-for="AdditionalMovieFile" />
<div>Your movie packed in a ZIP file (max size: 150k)</div>
<div>Your movie packed in a ZIP file (max size: @SiteGlobalConstants.MaximumMovieSizeHumanReadable)</div>
<span asp-validation-for="AdditionalMovieFile"></span>
</fieldset>
<form-button-bar>
Expand Down
7 changes: 1 addition & 6 deletions TASVideos/Pages/Publications/AdditionalMovies.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ public async Task<IActionResult> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Publications/PrimaryMovie.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</fieldset>
<fieldset>
<label asp-for="PrimaryMovieFile"></label>
<div>Your movie packed in a ZIP file (max size: 150k)</div>
<div>Your movie packed in a ZIP file (max size: @SiteGlobalConstants.MaximumMovieSizeHumanReadable)</div>
<input asp-for="PrimaryMovieFile" />
<span asp-validation-for="PrimaryMovieFile"></span>
</fieldset>
Expand Down
2 changes: 2 additions & 0 deletions TASVideos/Pages/Publications/PrimaryMovie.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public async Task<IActionResult> OnPost()
ModelState.AddModelError(nameof(PrimaryMovieFile), $"A publication with the filename {PrimaryMovieFile!.FileName} already exists.");
}

PrimaryMovieFile?.AddModelErrorIfOverSizeLimit(ModelState, User);

if (!ModelState.IsValid)
{
PublicationTitle = publication.Title;
Expand Down
10 changes: 6 additions & 4 deletions TASVideos/Pages/Submissions/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<fieldset>
<label asp-for="Submission.ReplaceMovieFile"></label>
<input asp-for="Submission.ReplaceMovieFile" />
<div>Your movie packed in a ZIP file (max size: 150k)</div>
<div>Your movie packed in a ZIP file (max size: @SiteGlobalConstants.MaximumMovieSizeHumanReadable)</div>
<span asp-validation-for="Submission.ReplaceMovieFile"></span>
</fieldset>
</column>
Expand Down Expand Up @@ -52,8 +52,9 @@
<span asp-validation-for="Submission.GameName"></span>
</fieldset>
<fieldset>
<label asp-for="Submission.Emulator"></label>
<input asp-for="Submission.Emulator" spellcheck="false" placeholder="Needs to be a specific version that sync was verified on. Does not necessarily need to be the version used by the author." />
<label asp-for="Submission.Emulator">Emulator and version</label>
<input asp-for="Submission.Emulator" spellcheck="false" placeholder="Example: BizHawk 2.8.0" />
<div>Needs to be a specific version that sync was verified on. Does not necessarily need to be the version used by the author.</div>
<span asp-validation-for="Submission.Emulator"></span>
</fieldset>
</column>
Expand All @@ -70,7 +71,8 @@
</fieldset>
<fieldset>
<label asp-for="Submission.EncodeEmbedLink"></label>
<input asp-for="Submission.EncodeEmbedLink" placeholder="Embedded link to a video of your movie, Ex: www.youtube.com/embed/0mregEW6kVU" />
<input asp-for="Submission.EncodeEmbedLink" placeholder="https://www.youtube.com/embed/0mregEW6kVU" />
<div>Embedded link to a video of your movie. Must be YouTube or niconico.</div>
<span asp-validation-for="Submission.EncodeEmbedLink"></span>
</fieldset>
</column>
Expand Down
5 changes: 1 addition & 4 deletions TASVideos/Pages/Submissions/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ public async Task<IActionResult> 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))
{
Expand Down
7 changes: 4 additions & 3 deletions TASVideos/Pages/Submissions/Submit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<fieldset>
<label asp-for="MovieFile"></label>
<input asp-for="MovieFile" />
<div>Your movie packed in a ZIP file (max size: 500k)</div>
<div>Your movie packed in a ZIP file (max size: @SiteGlobalConstants.MaximumMovieSizeHumanReadable)</div>
<span asp-validation-for="MovieFile"></span>
</fieldset>
</column>
Expand All @@ -44,7 +44,7 @@
<column lg="6">
<fieldset>
<label asp-for="GameVersion"></label>
<input asp-for="GameVersion" placeholder="Example: USA" />
<input asp-for="GameVersion" placeholder="USA v1.0" />
<span asp-validation-for="GameVersion"></span>
</fieldset>
<fieldset>
Expand All @@ -71,7 +71,8 @@
</fieldset>
<fieldset>
<label asp-for="EncodeEmbeddedLink"></label>
<input asp-for="EncodeEmbeddedLink" placeholder="Embedded link to a video of your movie, Ex: www.youtube.com/embed/0mregEW6kVU" />
<input asp-for="EncodeEmbeddedLink" placeholder="https://www.youtube.com/embed/0mregEW6kVU" />
<div>Embedded link to a video of your movie. Must be YouTube or niconico.</div>
<span asp-validation-for="EncodeEmbeddedLink"></span>
</fieldset>
</column>
Expand Down
5 changes: 1 addition & 4 deletions TASVideos/Pages/Submissions/Submit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 93844af

Please sign in to comment.