tsk-103: Confirmed functionality is working
This commit is contained in:
@@ -18,3 +18,7 @@ Icarus/bin
|
|||||||
Icarus/obj
|
Icarus/obj
|
||||||
Models/bin
|
Models/bin
|
||||||
Models/obj
|
Models/obj
|
||||||
|
Migrations
|
||||||
|
Icarus.txt
|
||||||
|
Storage
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@@ -116,6 +116,42 @@ public class DirectoryManager : BaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int DeleteEmptyDirectories(string? directory, int level)
|
||||||
|
{
|
||||||
|
var deleted = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
var curDir = directory;
|
||||||
|
for (var i = 0; i < level; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!System.IO.Directory.Exists(curDir))
|
||||||
|
{
|
||||||
|
// return deleted;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.IsDirectoryEmpty(curDir))
|
||||||
|
{
|
||||||
|
System.IO.Directory.Delete(curDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
curDir = System.IO.Directory.GetParent(curDir).ToString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var exMsg = ex.Message;
|
||||||
|
Console.WriteLine($"An error occurred {exMsg}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteEmptyDirectories(Song song)
|
public void DeleteEmptyDirectories(Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -110,11 +110,18 @@ public class SongManager : BaseManager
|
|||||||
{
|
{
|
||||||
var songPath = songMetaData.SongPath();
|
var songPath = songMetaData.SongPath();
|
||||||
System.IO.File.Delete(songPath);
|
System.IO.File.Delete(songPath);
|
||||||
successful = true;
|
successful = !System.IO.File.Exists(songPath);
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config!, songMetaData);
|
if (successful)
|
||||||
dirMgr.DeleteEmptyDirectories();
|
{
|
||||||
Console.WriteLine("Song successfully deleted");
|
Console.WriteLine("Song successfully deleted");
|
||||||
}
|
}
|
||||||
|
DirectoryManager dirMgr = new DirectoryManager(_config!, songMetaData);
|
||||||
|
var deletedAmount = dirMgr.DeleteEmptyDirectories(songMetaData.SongDirectory, 1);
|
||||||
|
if (deletedAmount > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{deletedAmount} directories deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var exMsg = ex.Message;
|
var exMsg = ex.Message;
|
||||||
|
|||||||
@@ -112,8 +112,11 @@ public class TokenManager : BaseManager
|
|||||||
{
|
{
|
||||||
return new LoginResult
|
return new LoginResult
|
||||||
{
|
{
|
||||||
UserId = user.Id, Username = user.Username, Token = token.AccessToken,
|
UserId = user.Id,
|
||||||
TokenType = token.TokenType, Expiration = token.Expiration,
|
Username = user.Username,
|
||||||
|
Token = token.AccessToken,
|
||||||
|
TokenType = token.TokenType,
|
||||||
|
Expiration = token.Expiration,
|
||||||
Message = SUCCESSFUL_TOKEN_MESSAGE
|
Message = SUCCESSFUL_TOKEN_MESSAGE
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -224,8 +227,10 @@ public class TokenManager : BaseManager
|
|||||||
|
|
||||||
return new TokenRequest
|
return new TokenRequest
|
||||||
{
|
{
|
||||||
ClientId = _clientId, ClientSecret = _clientSecret,
|
ClientId = _clientId,
|
||||||
Audience = _audience, GrantType = _grantType
|
ClientSecret = _clientSecret,
|
||||||
|
Audience = _audience,
|
||||||
|
GrantType = _grantType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ using Icarus.Database.Contexts;
|
|||||||
|
|
||||||
namespace Icarus.Controllers.V1;
|
namespace Icarus.Controllers.V1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Route("api/v1/song/data")]
|
[Route("api/v1/song/data")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
@@ -151,10 +153,13 @@ public class SongDataController : BaseController
|
|||||||
switch (song.AudioType)
|
switch (song.AudioType)
|
||||||
{
|
{
|
||||||
case "wav":
|
case "wav":
|
||||||
// song = _songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song);
|
|
||||||
// TODO: Make sure the tmp file gets deleted. Check
|
|
||||||
var _ = _songMgr.DeleteSongFromFileSystem(tmpSong);
|
var _ = _songMgr.DeleteSongFromFileSystem(tmpSong);
|
||||||
return BadRequest("No support for .wav files");
|
return BadRequest(new UploadSongWithDataResponse
|
||||||
|
{
|
||||||
|
Subject = "No longer supported",
|
||||||
|
Message = "No support for .wav files",
|
||||||
|
Songs = new List<Song>()
|
||||||
|
});
|
||||||
case "flac":
|
case "flac":
|
||||||
song = _songMgr.SaveFlacSongToFileSystem(up.SongData, up.CoverArtData, song);
|
song = _songMgr.SaveFlacSongToFileSystem(up.SongData, up.CoverArtData, song);
|
||||||
break;
|
break;
|
||||||
@@ -209,4 +214,16 @@ public class SongDataController : BaseController
|
|||||||
[FromForm(Name = "metadata")]
|
[FromForm(Name = "metadata")]
|
||||||
public string? SongFile { get; set; }
|
public string? SongFile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UploadSongWithDataResponse
|
||||||
|
{
|
||||||
|
#region Properties
|
||||||
|
[Newtonsoft.Json.JsonProperty("message")]
|
||||||
|
public string Message { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("subject")]
|
||||||
|
public string Subject { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("data")]
|
||||||
|
public List<Song> Songs { get; set; }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ public class SongStreamController : BaseController
|
|||||||
_logger!.LogInformation("Starting to stream song...>");
|
_logger!.LogInformation("Starting to stream song...>");
|
||||||
Console.WriteLine("Starting to streamsong...");
|
Console.WriteLine("Starting to streamsong...");
|
||||||
|
|
||||||
return await Task.Run(() => {
|
return await Task.Run(() =>
|
||||||
|
{
|
||||||
return File(stream, "application/octet-stream", filename);
|
return File(stream, "application/octet-stream", filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJw
|
|||||||
{
|
{
|
||||||
options.RequireHttpsMetadata = false;
|
options.RequireHttpsMetadata = false;
|
||||||
options.SaveToken = true;
|
options.SaveToken = true;
|
||||||
|
var audience = Configuration["JWT:Audience"];
|
||||||
|
var issuer = Configuration["JWT:Issuer"];
|
||||||
options.TokenValidationParameters = new TokenValidationParameters()
|
options.TokenValidationParameters = new TokenValidationParameters()
|
||||||
{
|
{
|
||||||
ValidateIssuer = true,
|
ValidateIssuer = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user