#79: Added functionality to the comressed song endpoint
This commit is contained in:
@@ -85,7 +85,7 @@ public class SongCompression
|
||||
|
||||
if (songDetails.Filename.Contains(Constants.FileExtensions.WAV_EXTENSION))
|
||||
{
|
||||
_compressedSongFilename = StripMP3Extension(songDetails.Filename);
|
||||
_compressedSongFilename = StripExtension(songDetails.Filename);
|
||||
}
|
||||
|
||||
return tmpZipFilePath;
|
||||
@@ -110,7 +110,7 @@ public class SongCompression
|
||||
}
|
||||
|
||||
|
||||
string StripMP3Extension(string filename)
|
||||
string StripExtension(string filename)
|
||||
{
|
||||
Console.WriteLine($"Before: {filename}");
|
||||
int filenameLength = filename.Length;
|
||||
@@ -119,7 +119,7 @@ public class SongCompression
|
||||
var startIndex = endIndex - 3;
|
||||
Console.WriteLine($"Starting index {startIndex} and ending index {endIndex}");
|
||||
var stripped = filename.Remove(startIndex, 4);
|
||||
stripped += ".zip";
|
||||
stripped += Constants.FileExtensions.ZIP_EXTENSION;
|
||||
Console.WriteLine($"After {stripped}");
|
||||
|
||||
return stripped;
|
||||
|
||||
@@ -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