Added endpoint to download cover art

This commit is contained in:
kdeng00
2024-06-16 18:20:21 -04:00
parent 23c50de468
commit d4419b16d5
3 changed files with 20 additions and 21 deletions
+15 -6
View File
@@ -1,11 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Icarus.Controllers.Managers;
using Icarus.Database.Contexts;
@@ -78,5 +72,20 @@ public class CoverArtController : BaseController
return NotFound();
}
}
[HttpGet("data/download/{id}")]
public async Task<IActionResult> Download(int id)
{
var songContext = new SongContext(_connectionString);
var covMgr = new CoverArtManager(this._config);
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
var filename = songMetaData.Title + Constants.FileExtensions.JPG_EXTENSION;
var c = covMgr.GetCoverArt(songMetaData);
var data = await c.GetData();
return File(data, "application/x-msdownload", filename);
}
#endregion
}