#79: Added functionality to the comressed song endpoint

This commit is contained in:
kdeng00
2024-06-16 17:56:25 -04:00
parent c7a530107f
commit 0394ad38da
3 changed files with 23 additions and 7 deletions
@@ -36,9 +36,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
@@ -46,18 +46,31 @@ 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 = string.Empty;
if (randomizeFilename.HasValue && randomizeFilename.Value)
{
filename = Managers.DirectoryManager.GenerateFilename(10) + Constants.FileExtensions.ZIP_EXTENSION;
}
else
{
filename = sng.Title + Constants.FileExtensions.ZIP_EXTENSION;
}
return File(song.Data, "application/x-msdownload", filename);
}
#endregion
}