mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-03 03:23:28 +00:00
Merge pull request #166 from Sea-Haven-Industries/fix/ab/sh-383-mobile-video-upload
Allow mobile work order video uploads up to 200 MB
This commit is contained in:
commit
b36b69df83
2 changed files with 17 additions and 6 deletions
|
|
@ -31,7 +31,7 @@ public class WorkOrderMediaControllerTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AddMedia_HasFiftyMegabyteRequestLimit()
|
public void AddMedia_HasTwoHundredMegabyteRequestLimit()
|
||||||
{
|
{
|
||||||
var method = typeof(WorkOrderMediaController).GetMethod(nameof(WorkOrderMediaController.AddMedia));
|
var method = typeof(WorkOrderMediaController).GetMethod(nameof(WorkOrderMediaController.AddMedia));
|
||||||
var attribute = Assert.Single(
|
var attribute = Assert.Single(
|
||||||
|
|
@ -39,14 +39,24 @@ public class WorkOrderMediaControllerTests
|
||||||
candidate => candidate.AttributeType == typeof(RequestSizeLimitAttribute));
|
candidate => candidate.AttributeType == typeof(RequestSizeLimitAttribute));
|
||||||
var bytes = Assert.Single(attribute.ConstructorArguments);
|
var bytes = Assert.Single(attribute.ConstructorArguments);
|
||||||
|
|
||||||
Assert.Equal(50_000_000L, bytes.Value);
|
Assert.Equal(200_000_000L, bytes.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddMedia_HasTwoHundredMegabyteMultipartBodyLimit()
|
||||||
|
{
|
||||||
|
var method = typeof(WorkOrderMediaController).GetMethod(nameof(WorkOrderMediaController.AddMedia));
|
||||||
|
var attribute = Assert.IsType<RequestFormLimitsAttribute>(Assert.Single(
|
||||||
|
method!.GetCustomAttributes(typeof(RequestFormLimitsAttribute), inherit: true)));
|
||||||
|
|
||||||
|
Assert.Equal(200_000_000L, attribute.MultipartBodyLengthLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AddMedia_FileOverLimit_ReturnsStableUnprocessableEntity()
|
public async Task AddMedia_FileOverLimit_ReturnsStableUnprocessableEntity()
|
||||||
{
|
{
|
||||||
var file = new Mock<IFormFile>();
|
var file = new Mock<IFormFile>();
|
||||||
file.SetupGet(candidate => candidate.Length).Returns(50_000_001);
|
file.SetupGet(candidate => candidate.Length).Returns(200_000_001);
|
||||||
var storage = new Mock<IFileStoragePort>(MockBehavior.Strict);
|
var storage = new Mock<IFileStoragePort>(MockBehavior.Strict);
|
||||||
var controller = CreateController(storage: storage);
|
var controller = CreateController(storage: storage);
|
||||||
|
|
||||||
|
|
@ -55,7 +65,7 @@ public class WorkOrderMediaControllerTests
|
||||||
var response = Assert.IsType<UnprocessableEntityObjectResult>(result);
|
var response = Assert.IsType<UnprocessableEntityObjectResult>(result);
|
||||||
var error = Assert.IsType<WorkOrderBoardValidationErrorDto>(response.Value);
|
var error = Assert.IsType<WorkOrderBoardValidationErrorDto>(response.Value);
|
||||||
Assert.Equal("FileTooLarge", error.Code);
|
Assert.Equal("FileTooLarge", error.Code);
|
||||||
Assert.Equal("The uploaded file must not exceed 50 MB.", error.Message);
|
Assert.Equal("The uploaded file must not exceed 200 MB.", error.Message);
|
||||||
storage.VerifyNoOtherCalls();
|
storage.VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
[Route("api/workorders")]
|
[Route("api/workorders")]
|
||||||
public class WorkOrderMediaController : Controller
|
public class WorkOrderMediaController : Controller
|
||||||
{
|
{
|
||||||
public const long MaxUploadBytes = 50_000_000;
|
public const long MaxUploadBytes = 200_000_000;
|
||||||
|
|
||||||
private readonly IWorkOrderMediaService _workOrderMediaService;
|
private readonly IWorkOrderMediaService _workOrderMediaService;
|
||||||
private readonly IFileStoragePort _fileStorage;
|
private readonly IFileStoragePort _fileStorage;
|
||||||
|
|
@ -75,6 +75,7 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
|
|
||||||
[HttpPost("{id:int}/media")]
|
[HttpPost("{id:int}/media")]
|
||||||
[RequestSizeLimit(MaxUploadBytes)]
|
[RequestSizeLimit(MaxUploadBytes)]
|
||||||
|
[RequestFormLimits(MultipartBodyLengthLimit = MaxUploadBytes)]
|
||||||
public async Task<IActionResult> AddMedia(
|
public async Task<IActionResult> AddMedia(
|
||||||
int id,
|
int id,
|
||||||
[FromForm] WorkOrderMediaCategory? category,
|
[FromForm] WorkOrderMediaCategory? category,
|
||||||
|
|
@ -91,7 +92,7 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
{
|
{
|
||||||
throw new WorkOrderBoardValidationException(
|
throw new WorkOrderBoardValidationException(
|
||||||
"FileTooLarge",
|
"FileTooLarge",
|
||||||
"The uploaded file must not exceed 50 MB.");
|
"The uploaded file must not exceed 200 MB.");
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkOrderMediaFileRules.EnsureAllowed(file, category);
|
WorkOrderMediaFileRules.EnsureAllowed(file, category);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue