#79: Added functionality to the comressed song endpoint
This commit is contained in:
@@ -10,4 +10,7 @@ public class FileExtensions
|
|||||||
|
|
||||||
// Contains file extension with period at the beginning
|
// Contains file extension with period at the beginning
|
||||||
public static string JPG_EXTENSION = ".jpg";
|
public static string JPG_EXTENSION = ".jpg";
|
||||||
|
|
||||||
|
// Contains file extension with period at the beginning
|
||||||
|
public static string ZIP_EXTENSION = ".zip";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class SongCompression
|
|||||||
|
|
||||||
if (songDetails.Filename.Contains(Constants.FileExtensions.WAV_EXTENSION))
|
if (songDetails.Filename.Contains(Constants.FileExtensions.WAV_EXTENSION))
|
||||||
{
|
{
|
||||||
_compressedSongFilename = StripMP3Extension(songDetails.Filename);
|
_compressedSongFilename = StripExtension(songDetails.Filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmpZipFilePath;
|
return tmpZipFilePath;
|
||||||
@@ -110,7 +110,7 @@ public class SongCompression
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string StripMP3Extension(string filename)
|
string StripExtension(string filename)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Before: {filename}");
|
Console.WriteLine($"Before: {filename}");
|
||||||
int filenameLength = filename.Length;
|
int filenameLength = filename.Length;
|
||||||
@@ -119,7 +119,7 @@ public class SongCompression
|
|||||||
var startIndex = endIndex - 3;
|
var startIndex = endIndex - 3;
|
||||||
Console.WriteLine($"Starting index {startIndex} and ending index {endIndex}");
|
Console.WriteLine($"Starting index {startIndex} and ending index {endIndex}");
|
||||||
var stripped = filename.Remove(startIndex, 4);
|
var stripped = filename.Remove(startIndex, 4);
|
||||||
stripped += ".zip";
|
stripped += Constants.FileExtensions.ZIP_EXTENSION;
|
||||||
Console.WriteLine($"After {stripped}");
|
Console.WriteLine($"After {stripped}");
|
||||||
|
|
||||||
return stripped;
|
return stripped;
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ public class SongCompressedDataController : BaseController
|
|||||||
#region Constructor
|
#region Constructor
|
||||||
public SongCompressedDataController(IConfiguration config)
|
public SongCompressedDataController(IConfiguration config)
|
||||||
{
|
{
|
||||||
|
_config = config;
|
||||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||||
_archiveDir = _config.GetValue<string>("ArchivePath");
|
_archiveDir = _config.GetValue<string>("ArchivePath");
|
||||||
_config = config;
|
|
||||||
_connectionString = _config.GetConnectionString("DefaultConnection");
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -46,18 +46,31 @@ public class SongCompressedDataController : BaseController
|
|||||||
|
|
||||||
#region API Routes
|
#region API Routes
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<IActionResult> DownloadCompressedSong(int id)
|
public async Task<IActionResult> DownloadCompressedSong(int id, [FromQuery] bool? randomizeFilename)
|
||||||
{
|
{
|
||||||
var context = new SongContext(_connectionString);
|
var context = new SongContext(_connectionString);
|
||||||
|
|
||||||
SongCompression cmp = new SongCompression(_archiveDir);
|
SongCompression cmp = new SongCompression(_archiveDir);
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
||||||
|
|
||||||
Console.WriteLine("Starting process of retrieving comrpessed song");
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user