Finished up #55

This commit is contained in:
kdeng00
2019-08-13 21:05:11 -04:00
parent 4d59b311e6
commit 533a8d81a9
5 changed files with 36 additions and 29 deletions
+3
View File
@@ -30,6 +30,9 @@ namespace Icarus.Controllers.Managers
[DllImport("libicarus.so")]
public static extern void delete_empty_directories(Sng song, string root_path);
[DllImport("libicarus.so")]
public static extern void delete_from_filesystem(Sng song);
[DllImport("libicarus.so")]
public static extern void delete_song_empty_directories(Sng song, string root_path);
#endregion
+11 -22
View File
@@ -151,9 +151,8 @@ namespace Icarus.Controllers.Managers
{
_logger.Info("Starting the process of saving the song to the filesystem");
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
var song = await SaveSongTemp(songFile, fileTempPath);
song.SongPath = fileTempPath;
var song = await SaveSongTemp(songFile,
Path.Combine(_tempDirectoryRoot, songFile.FileName));
var rootPath = _config.GetValue<string>("RootMusicPath");
var strCount = rootPath.Length + song.Artist.Length +
@@ -164,27 +163,18 @@ namespace Icarus.Controllers.Managers
DirectoryManager.create_directory(ConvertSongToSng(song),
rootPath, filePathSB);
var filePath = filePathSB.ToString().Substring(0, strCount);
var tmpSongPath = song.SongPath;
System.IO.File.Delete(fileTempPath);
song.SongPath = filePathSB.ToString().Substring(0, strCount);
var songFilename = songFile.FileName;
if (!songFilename.EndsWith(".mp3"))
filePath += $"{songFilename}.mp3";
if (!songFile.FileName.EndsWith(".mp3"))
song.SongPath += $"{songFile.FileName}.mp3";
else
filePath += $"{songFilename}";
song.SongPath += $"{songFile.FileName}";
_logger.Info($"Absolute song path: {filePath}");
_logger.Info($"Absolute song path: {song.SongPath}");
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await (songFile.CopyToAsync(fileStream));
song.SongPath = filePath;
_logger.Info("Song successfully saved to filesystem");
}
DirectoryManager.copy_song(song.SongPath, tmpSongPath);
var coverMgr = new CoverArtManager(_config.GetValue<string>("CoverArtPath"));
var coverArt = coverMgr.SaveCoverArt(song);
@@ -254,11 +244,9 @@ namespace Icarus.Controllers.Managers
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
{
byte[] uncompressedSong = await System.IO.File.ReadAllBytesAsync(details.SongPath);
return new SongData
{
Data = uncompressedSong
Data = await System.IO.File.ReadAllBytesAsync(details.SongPath)
};
}
private async Task<Song> SaveSongTemp(IFormFile songFile, string filePath)
@@ -275,6 +263,7 @@ namespace Icarus.Controllers.Managers
_logger.Info("Assigning song filename");
song.Filename = songFile.FileName;
song.SongPath = filePath;
return song;
}
+2 -3
View File
@@ -103,9 +103,8 @@ namespace Icarus.Controllers.V1
Console.WriteLine("Uploading song...");
_logger.LogInformation("Uploading song...");
var uploads = _songTempDir;
Console.WriteLine($"Song Root Path {uploads}");
_logger.LogInformation($"Song root path {uploads}");
Console.WriteLine($"Song Root Path {_songTempDir}");
_logger.LogInformation($"Song root path {_songTempDir}");
foreach (var sng in songData)
if (sng.Length > 0) {
Console.WriteLine($"Song filename {sng.FileName}");
+4 -2
View File
@@ -5,8 +5,10 @@
std::string create_directory_process(Song, const char*);
std::string read_cover_art(const char*);
bool delete_song(Song*);
void copy_stock_to_root(const char*, const std::string);
void copy_song_to_path(const char*, const char*);
void delete_cover_art_file(const std::string);
void delete_directories(Song song, const char*);
void delete_song(Song song);
void delete_directories(Song, const char*);
void delete_song(Song);
+15 -1
View File
@@ -37,7 +37,6 @@ std::string create_directory_process(Song song, const char *root_path)
return alb_path.string() + "/";
}
std::string read_cover_art(const char *source)
{
auto source_path = fs::path(source);
@@ -53,6 +52,12 @@ std::string read_cover_art(const char *source)
return buf.str();
}
bool delete_song(Song *song)
{
return fs::remove(song->SongPath);
}
void copy_stock_to_root(const char *target, const std::string buff)
{
std::cout<<"starting process"<<std::endl;
@@ -133,6 +138,7 @@ void copy_stock_cover_art(const char*, const char*);
void copy_song(const char*, const char*);
void delete_cover_art(const char*, const char*);
void delete_empty_directories(Song, const char*);
void delete_from_filesystem(Song);
void delete_song_empty_directories(Song, const char*);
void print_song_details(const Song);
@@ -167,6 +173,14 @@ void delete_empty_directories(Song song, const char *root_path)
{
delete_directories(song, root_path);
}
void delete_from_filesystem(Song song)
{
if (delete_song(&song)) {
std::cout<<"successfully deleted song from filesystem"<<std::endl;
} else {
std::cout<<"failed to deleted song from filesystem"<<std::endl;
}
}
void delete_song_empty_directories(Song song, const char *root_path)
{
delete_song(song);