#79: Added query parameter to randomize filename when downloading songs (#96)

* #79: Added query parameter to randomize filename when downloading songs

Right now only the  endpoint has this parameter added

* #79: Added functionality to the comressed song endpoint

* Added functionality to the download cover art
This commit was merged in pull request #96.
This commit is contained in:
Kun Deng
2024-06-16 19:04:10 -04:00
committed by GitHub
parent 270b7d059c
commit ebb15b7cdb
7 changed files with 90 additions and 40 deletions
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using Icarus.Controllers.Utilities;
using Icarus.Models;
using Icarus.Database.Contexts;
using Icarus.Controllers.Managers;
namespace Icarus.Controllers.V1;
@@ -26,9 +27,9 @@ public class SongCompressedDataController : BaseController
#region Constructor
public SongCompressedDataController(IConfiguration config)
{
_config = config;
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
_archiveDir = _config.GetValue<string>("ArchivePath");
_config = config;
_connectionString = _config.GetConnectionString("DefaultConnection");
}
#endregion
@@ -36,18 +37,22 @@ public class SongCompressedDataController : BaseController
#region API Routes
[HttpGet("{id}")]
public async Task<IActionResult> DownloadCompressedSong(int id)
public async Task<IActionResult> DownloadCompressedSong(int id, [FromQuery] bool? randomizeFilename)
{
var context = new SongContext(_connectionString);
SongCompression cmp = new SongCompression(_archiveDir);
Console.WriteLine($"Archive directory root: {_archiveDir}");
Console.WriteLine("Starting process of retrieving comrpessed song");
SongData song = await cmp.RetrieveCompressedSong(context.RetrieveRecord(new Song{ SongID = id }));
var sng = context.RetrieveRecord(new Song{ SongID = id });
SongData song = await cmp.RetrieveCompressedSong(sng);
return File(song.Data, "application/x-msdownload", cmp.CompressedSongFilename);
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.ZIP_EXTENSION, sng.Title, randomizeFilename);
return File(song.Data, "application/x-msdownload", filename);
}
#endregion
}