mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
finished unit tests and docstrings
This commit is contained in:
@@ -8,6 +8,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Queue controller.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/queue")]
|
||||
[Produces("application/json")]
|
||||
@@ -15,23 +18,33 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
private readonly IScanResultService _scanResultService;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize queue controller.
|
||||
/// </summary>
|
||||
/// <param name="scanResultService">Scan result service.</param>
|
||||
public QueueController(IScanResultService scanResultService)
|
||||
{
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queue file for scanning.
|
||||
/// </summary>
|
||||
/// <param name="file">File from form data.</param>
|
||||
[HttpPost("file")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanFile(
|
||||
[Required, MaxFileSize] IFormFile file)
|
||||
[Required] [MaxFileSize] IFormFile file)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
string storedFileId;
|
||||
|
||||
await using (var uploadFileStream = file.OpenReadStream())
|
||||
{
|
||||
storedFileId = await _scanResultService.StoreFile(file.FileName, uploadFileStream);
|
||||
}
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, Url.Action("Index", "Download", new {id = storedFileId},
|
||||
Request?.Scheme, Request?.Host.Value));
|
||||
@@ -39,11 +52,15 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
return CreatedAtAction("Index", "ScanResults", new {id = result.Id}, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queue URL for scanning.
|
||||
/// </summary>
|
||||
/// <param name="url">URL from form data.</param>
|
||||
[HttpPost("url")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanUrl(
|
||||
[FromForm, Required, IsHttpUrl] string url)
|
||||
[FromForm] [Required] [IsHttpUrl] string url)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
|
Reference in New Issue
Block a user