Can download a cover art via the cover art's id. Just need to have a stock cover art for songs without any and update the documentation. #50

This commit is contained in:
amazing-username
2019-07-13 16:04:39 -04:00
parent 1004f6c93d
commit 59895af3b4
3 changed files with 107 additions and 76 deletions
+36 -10
View File
@@ -1,14 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Icarus.Controllers.Managers;
using Icarus.Database.Repositories;
using Icarus.Models;
namespace Icarus.Controllers.V1
{
[Route("api/v1/coverart/song")]
[Route("api/v1/coverart")]
[ApiController]
public class CoverArtController : ControllerBase
{
@@ -19,18 +24,39 @@ namespace Icarus.Controllers.V1
#region Constructors
public CoverArtController(ILogger<CoverArtController> logger)
{
_logger = logger;
}
#endregion
{
_logger = logger;
}
#endregion
#region HTTP Routes
[HttpGet("{id}")]
public IActionResult Get(int id)
{
return NotFound();
}
[HttpGet("{id}")]
[Authorize("download:cover_art")]
public IActionResult Get(int id)
{
var coverArt = new CoverArt
{
CoverArtId = id
};
var coverArtRepository = HttpContext
.RequestServices
.GetService(
typeof(CoverArtRepository)) as CoverArtRepository;
coverArt = coverArtRepository.GetCoverArt(coverArt);
if (coverArt != null)
{
var coverArtBytes = System.IO.File.ReadAllBytes(
coverArt.ImagePath);
return File(coverArtBytes, "application/x-msdownload",
coverArt.SongTitle);
}
else
return NotFound();
}
#endregion
}
}