wabbajack/Wabbajack.Server/Controllers/ModFiles.cs
2021-09-27 06:42:46 -06:00

35 lines
1.0 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Server.DataLayer;
namespace Wabbajack.BuildServer.Controllers
{
[Authorize(Roles = "User")]
[ApiController]
[Route("/mod_files")]
public class ModFilesForHash : ControllerBase
{
private SqlService _sql;
private ILogger<ModFilesForHash> _logger;
private readonly DTOSerializer _dtos;
public ModFilesForHash(ILogger<ModFilesForHash> logger, SqlService sql, DTOSerializer dtos)
{
_logger = logger;
_sql = sql;
_dtos = dtos;
}
[HttpGet("by_hash/{hashAsHex}")]
public async Task<IActionResult> GetByHash(string hashAsHex)
{
var files = await _sql.ResolveDownloadStatesByHash(Hash.FromHex(hashAsHex));
return Ok(_dtos.Serialize(files));
}
}
}