2020-10-25 16:11:36 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-10-29 12:17:09 +02:00
|
|
|
using MalwareMultiScan.Api.Services.Interfaces;
|
2020-10-25 16:11:36 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace MalwareMultiScan.Api.Controllers
|
|
|
|
{
|
2020-10-26 21:24:40 +02:00
|
|
|
[ApiController]
|
2020-10-27 09:57:39 +02:00
|
|
|
[Route("api/download")]
|
2020-10-26 21:24:40 +02:00
|
|
|
[Produces("application/octet-stream")]
|
2020-10-25 16:11:36 +02:00
|
|
|
public class DownloadController : Controller
|
|
|
|
{
|
2020-10-29 12:17:09 +02:00
|
|
|
private readonly IScanResultService _scanResultService;
|
2020-10-25 16:11:36 +02:00
|
|
|
|
2020-10-29 12:17:09 +02:00
|
|
|
public DownloadController(IScanResultService scanResultService)
|
2020-10-25 16:11:36 +02:00
|
|
|
{
|
2020-10-26 16:20:47 +02:00
|
|
|
_scanResultService = scanResultService;
|
2020-10-25 16:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
public async Task<IActionResult> Index(string id)
|
|
|
|
{
|
2020-10-26 16:20:47 +02:00
|
|
|
var fileStream = await _scanResultService.ObtainFile(id);
|
2020-10-25 16:11:36 +02:00
|
|
|
|
|
|
|
if (fileStream == null)
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
return File(fileStream, "application/octet-stream");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|