#90: Adding functionality to download cover art #97

Merged
kdeng00 merged 3 commits from tsk-90 into master 2024-06-16 18:28:08 -04:00
3 changed files with 20 additions and 21 deletions
Showing only changes of commit d4419b16d5 - Show all commits
-8
View File
@@ -1,11 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Icarus.Constants;
using Icarus.Controllers.Utilities;
using Icarus.Database.Contexts;
+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
}
+5 -7
View File
@@ -1,10 +1,3 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using Newtonsoft.Json;
namespace Icarus.Models;
@@ -33,5 +26,10 @@ public class CoverArt
return (flag == 0) ? filename : $"{filename}{extension}";
}
public async Task<byte[]> GetData()
{
return await File.ReadAllBytesAsync(this.ImagePath);
}
#endregion
}