Added endpoint to download cover art
This commit is contained in:
@@ -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.Constants;
|
||||||
using Icarus.Controllers.Utilities;
|
using Icarus.Controllers.Utilities;
|
||||||
using Icarus.Database.Contexts;
|
using Icarus.Database.Contexts;
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Database.Contexts;
|
using Icarus.Database.Contexts;
|
||||||
@@ -78,5 +72,20 @@ public class CoverArtController : BaseController
|
|||||||
return NotFound();
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -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;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Icarus.Models;
|
namespace Icarus.Models;
|
||||||
@@ -33,5 +26,10 @@ public class CoverArt
|
|||||||
|
|
||||||
return (flag == 0) ? filename : $"{filename}{extension}";
|
return (flag == 0) ? filename : $"{filename}{extension}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<byte[]> GetData()
|
||||||
|
{
|
||||||
|
return await File.ReadAllBytesAsync(this.ImagePath);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user