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:
@@ -35,6 +35,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
song.CoverArtId = coverArt.CoverArtId;
|
song.CoverArtId = coverArt.CoverArtId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoverArt SaveCoverArt(Song song)
|
public CoverArt SaveCoverArt(Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
using Icarus.Controllers.Managers;
|
||||||
|
using Icarus.Database.Repositories;
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
[Route("api/v1/coverart/song")]
|
[Route("api/v1/coverart")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class CoverArtController : ControllerBase
|
public class CoverArtController : ControllerBase
|
||||||
{
|
{
|
||||||
@@ -27,8 +32,29 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
#region HTTP Routes
|
#region HTTP Routes
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
|
[Authorize("download:cover_art")]
|
||||||
public IActionResult Get(int id)
|
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();
|
return NotFound();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ namespace Icarus
|
|||||||
policy.Requirements
|
policy.Requirements
|
||||||
.Add(new HasScopeRequirement("download:songs", domain)));
|
.Add(new HasScopeRequirement("download:songs", domain)));
|
||||||
|
|
||||||
|
options.AddPolicy("download:cover_art", policy =>
|
||||||
|
policy.Requirements
|
||||||
|
.Add(new HasScopeRequirement("download:cover_art", domain)));
|
||||||
|
|
||||||
options.AddPolicy("upload:songs", policy =>
|
options.AddPolicy("upload:songs", policy =>
|
||||||
policy.Requirements
|
policy.Requirements
|
||||||
.Add(new HasScopeRequirement("upload:songs", domain)));
|
.Add(new HasScopeRequirement("upload:songs", domain)));
|
||||||
|
|||||||
Reference in New Issue
Block a user