mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
finalize refactoring & ready for the PR
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Attributes;
|
||||
using MalwareMultiScan.Api.Data.Models;
|
||||
@@ -23,37 +23,33 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[HttpPost("file")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanFile([FromForm] IFormFile file)
|
||||
public async Task<IActionResult> ScanFile(
|
||||
[Required, MaxFileSize] IFormFile file)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
string storedFileId;
|
||||
|
||||
await using (var uploadFileStream = file.OpenReadStream())
|
||||
{
|
||||
storedFileId = await _scanResultService.StoreFile(file.Name, uploadFileStream);
|
||||
}
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, Url.Action("Index", "Download", new {id = storedFileId},
|
||||
Request.Scheme, Request.Host.Value));
|
||||
|
||||
return Created(Url.Action("Index", "ScanResults", new {id = result.Id},
|
||||
Request.Scheme, Request.Host.Value), result);
|
||||
return CreatedAtAction("Index", "ScanResults", new {id = result.Id}, result);
|
||||
}
|
||||
|
||||
[HttpPost("url")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanUrl([FromForm] [HttpUrlValidation] Uri url)
|
||||
public async Task<IActionResult> ScanUrl(
|
||||
[FromForm, Required, IsHttpUrl] string url)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
var resultUrl = Url.Action("Index", "ScanResults", new {id = result.Id},
|
||||
Request.Scheme, Request.Host.Value);
|
||||
await _scanResultService.QueueUrlScan(result, url);
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, url.ToString());
|
||||
|
||||
return Created(resultUrl, result);
|
||||
return CreatedAtAction("Index", "ScanResults", new {id = result.Id}, result);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user