#79: Added query parameter to randomize filename when downloading songs
Right now only the endpoint has this parameter added
This commit is contained in:
@@ -48,6 +48,14 @@ public class DirectoryManager : BaseManager
|
||||
|
||||
|
||||
#region Methods
|
||||
// Does not include extension
|
||||
public static string GenerateFilename(int length)
|
||||
{
|
||||
string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS;
|
||||
var random = new Random();
|
||||
return new string(Enumerable.Repeat(chars, length).Select(s =>
|
||||
s[random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
public void CreateDirectory()
|
||||
{
|
||||
CreateDirectory(_song);
|
||||
|
||||
@@ -48,14 +48,24 @@ public class SongDataController : BaseController
|
||||
|
||||
|
||||
[HttpGet("download/{id}")]
|
||||
public IActionResult Download(int id)
|
||||
public IActionResult Download(int id, [FromQuery] bool? randomizeFilename)
|
||||
{
|
||||
var songContext = new SongContext(_connectionString);
|
||||
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
||||
|
||||
var song = _songMgr.RetrieveSong(songMetaData).Result;
|
||||
var filename = "";
|
||||
|
||||
if (randomizeFilename.HasValue && randomizeFilename.Value)
|
||||
{
|
||||
filename = Managers.DirectoryManager.GenerateFilename(10) + Constants.FileExtensions.WAV_EXTENSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = songMetaData.Title + Constants.FileExtensions.WAV_EXTENSION;
|
||||
}
|
||||
|
||||
return File(song.Data, "application/x-msdownload", songMetaData.Filename);
|
||||
return File(song.Data, "application/x-msdownload", filename);
|
||||
}
|
||||
|
||||
// Assumes that the song already has metadata such as
|
||||
|
||||
Reference in New Issue
Block a user