mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
change the communication protocol to RMQ
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using MalwareMultiScan.Shared.Attributes;
|
||||
using MalwareMultiScan.Shared.Data.Responses;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
@@ -7,9 +14,45 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[Produces("application/json")]
|
||||
public class QueueController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
private readonly ScanResultService _scanResultService;
|
||||
|
||||
public QueueController( ScanResultService scanResultService)
|
||||
{
|
||||
return Ok();
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
[HttpPost("file")]
|
||||
[ProducesResponseType(typeof(ResultResponse), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanFile([FromForm] 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);
|
||||
}
|
||||
|
||||
[HttpPost("url")]
|
||||
[ProducesResponseType(typeof(ResultResponse), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanUrl([FromForm] [UrlValidation] Uri 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.ToString());
|
||||
|
||||
return Created(resultUrl, result);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user