#79: Added functionality to the comressed song endpoint
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user