Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3948e25fc3 | |||
| a39c232c34 | |||
| 8ec7092272 | |||
| 84615472ef | |||
| e4be56101a | |||
| 59895af3b4 | |||
| 1004f6c93d | |||
| 026a528a81 | |||
| 226ca44206 | |||
| 4940768d22 | |||
| f7963237fd | |||
| 0ee1473639 | |||
| 2b59bfac32 | |||
| 0932be2f2b | |||
| 82686f5c33 | |||
| b5501e323f | |||
| 089bd1191c | |||
| 56fe805f80 | |||
| ada8fa79d3 | |||
| bc209c2363 |
@@ -10,16 +10,15 @@ namespace Icarus.Authorization.Handlers
|
|||||||
{
|
{
|
||||||
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
|
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
|
||||||
{
|
{
|
||||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
|
||||||
HasScopeRequirement requirement)
|
|
||||||
{
|
{
|
||||||
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
|
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scopes = context.User.FindFirst(c => c.Type == "scope" &&
|
var scopes = context.User.FindFirst(c =>
|
||||||
c.Issuer == requirement.Issuer).Value.Split(' ');
|
c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
|
||||||
|
|
||||||
if (scopes.Any(s => s == requirement.Scope))
|
if (scopes.Any(s => s == requirement.Scope))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Icarus.Constants
|
||||||
|
{
|
||||||
|
public class DirectoryPaths
|
||||||
|
{
|
||||||
|
public static string CoverArtPath =>
|
||||||
|
Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
using Icarus.Constants;
|
||||||
|
using Icarus.Controllers.Utilities;
|
||||||
|
using Icarus.Database.Repositories;
|
||||||
|
using Icarus.Models;
|
||||||
|
using Icarus.Types;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers.Managers
|
||||||
|
{
|
||||||
|
public class CoverArtManager : BaseManager
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private string _rootCoverArtPath;
|
||||||
|
private byte[] _stockCoverArt = null;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public CoverArtManager(string rootPath)
|
||||||
|
{
|
||||||
|
_rootCoverArtPath = rootPath;
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public void SaveCoverArtToDatabase(ref Song song, ref CoverArt coverArt,
|
||||||
|
CoverArtRepository coverArtRepository)
|
||||||
|
{
|
||||||
|
_logger.Info("Saving cover art record to the database");
|
||||||
|
coverArtRepository.SaveCoverArt(coverArt);
|
||||||
|
|
||||||
|
coverArt = coverArtRepository.GetCoverArt(CoverArtField.SongTitle,
|
||||||
|
coverArt);
|
||||||
|
|
||||||
|
song.CoverArtId = coverArt.CoverArtId;
|
||||||
|
}
|
||||||
|
public void DeleteCoverArtFromDatabase(CoverArt coverArt,
|
||||||
|
CoverArtRepository coverArtRepository)
|
||||||
|
{
|
||||||
|
_logger.Info("Attempting to delete cover art from the database");
|
||||||
|
coverArtRepository.DeleteCoverArt(coverArt);
|
||||||
|
}
|
||||||
|
public void DeleteCoverArt(CoverArt coverArt)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var stockCoverArtPath = _rootCoverArtPath + "CoverArt.png";
|
||||||
|
if (!string.Equals(stockCoverArtPath, coverArt.ImagePath,
|
||||||
|
StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
_logger.Info("Song does not contain the stock cover art");
|
||||||
|
File.Delete(coverArt.ImagePath);
|
||||||
|
_logger.Info("Cover art deleted from the filesystem");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Info("Song contains the stock cover art");
|
||||||
|
_logger.Info("Will not delete from from the filesystem");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoverArt SaveCoverArt(Song song)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dirMgr = new DirectoryManager(_rootCoverArtPath);
|
||||||
|
dirMgr.CreateDirectory(song);
|
||||||
|
var imagePath = dirMgr.SongDirectory + song.Title + ".png";
|
||||||
|
var coverArt = new CoverArt
|
||||||
|
{
|
||||||
|
SongTitle = song.Title,
|
||||||
|
ImagePath = imagePath
|
||||||
|
};
|
||||||
|
|
||||||
|
var metaData = new MetadataRetriever();
|
||||||
|
var imgBytes = metaData.RetrieveCoverArtBytes(song);
|
||||||
|
|
||||||
|
if (imgBytes != null)
|
||||||
|
{
|
||||||
|
_logger.Info("Saving cover art to the filesystem");
|
||||||
|
File.WriteAllBytes(coverArt.ImagePath, imgBytes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Info("Song has no cover art, applying stock cover art");
|
||||||
|
coverArt.ImagePath = _rootCoverArtPath + "CoverArt.png";
|
||||||
|
metaData.UpdateCoverArt(song, coverArt);
|
||||||
|
File.WriteAllBytes(coverArt.ImagePath, _stockCoverArt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return coverArt;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(DirectoryPaths.CoverArtPath))
|
||||||
|
_stockCoverArt = File.ReadAllBytes(DirectoryPaths.CoverArtPath);
|
||||||
|
|
||||||
|
if (!File.Exists(_rootCoverArtPath + "CoverArt.png"))
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(_rootCoverArtPath + "CoverArt.png",
|
||||||
|
_stockCoverArt);
|
||||||
|
Console.WriteLine("Copied Stock Cover Art");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
using Icarus.Types;
|
||||||
|
|
||||||
namespace Icarus.Controllers.Managers
|
namespace Icarus.Controllers.Managers
|
||||||
{
|
{
|
||||||
@@ -39,6 +40,10 @@ namespace Icarus.Controllers.Managers
|
|||||||
_config = config;
|
_config = config;
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
public DirectoryManager(string rootDirectory)
|
||||||
|
{
|
||||||
|
_rootSongDirectory = rootDirectory;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +69,29 @@ namespace Icarus.Controllers.Managers
|
|||||||
Console.WriteLine($"An error occurred {ex.Message}");
|
Console.WriteLine($"An error occurred {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CreateDirectory(Song song)
|
||||||
|
{
|
||||||
|
_song = song;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_songDirectory = AlbumDirectory();
|
||||||
|
|
||||||
|
if (!Directory.Exists(_songDirectory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(_songDirectory);
|
||||||
|
Console.WriteLine($"The directory has been created");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"The song will be saved in the following" +
|
||||||
|
$" directory: {_songDirectory}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
public void DeleteEmptyDirectories()
|
public void DeleteEmptyDirectories()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -160,9 +188,17 @@ namespace Icarus.Controllers.Managers
|
|||||||
return songPath;
|
return songPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
||||||
{
|
{
|
||||||
|
switch (dirTypes)
|
||||||
|
{
|
||||||
|
case DirectoryType.Music:
|
||||||
_rootSongDirectory = _config.GetValue<string>("RootMusicPath");
|
_rootSongDirectory = _config.GetValue<string>("RootMusicPath");
|
||||||
|
break;
|
||||||
|
case DirectoryType.CoverArt:
|
||||||
|
_rootSongDirectory = _config.GetValue<string>("CoverArtPath");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsDirectoryEmpty(string path)
|
private bool IsDirectoryEmpty(string path)
|
||||||
|
|||||||
@@ -96,8 +96,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore,
|
public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore,
|
||||||
ArtistRepository artistStore, GenreRepository genreStore,
|
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
|
||||||
YearRepository yearStore)
|
|
||||||
{
|
{
|
||||||
var result = new SongResult();
|
var result = new SongResult();
|
||||||
|
|
||||||
@@ -163,17 +162,25 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
public void DeleteSong(Song song, SongRepository songStore,
|
public void DeleteSong(Song song, SongRepository songStore,
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
AlbumRepository albumStore, ArtistRepository artistStore,
|
||||||
GenreRepository genreStore, YearRepository yearStore)
|
GenreRepository genreStore, YearRepository yearStore,
|
||||||
|
CoverArtRepository coverStore)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (DeleteSongFromFilesystem(song))
|
if (DeleteSongFromFilesystem(song))
|
||||||
{
|
{
|
||||||
_logger.Info("Failed to delete the song");
|
_logger.Error("Failed to delete the song");
|
||||||
|
|
||||||
throw new Exception("Failed to delete the song");
|
throw new Exception("Failed to delete the song");
|
||||||
}
|
}
|
||||||
|
_logger.Info("Song deleted from the filesystem");
|
||||||
|
|
||||||
|
var coverMgr = new CoverArtManager(_config.GetValue<string>(
|
||||||
|
"CoverArtPath"));
|
||||||
|
var coverArt = coverStore.GetCoverArt(song);
|
||||||
|
coverMgr.DeleteCoverArt(coverArt);
|
||||||
|
|
||||||
|
coverMgr.DeleteCoverArtFromDatabase(coverArt, coverStore);
|
||||||
DeleteSongFromDatabase(song, songStore, albumStore, artistStore,
|
DeleteSongFromDatabase(song, songStore, albumStore, artistStore,
|
||||||
genreStore, yearStore);
|
genreStore, yearStore);
|
||||||
}
|
}
|
||||||
@@ -283,6 +290,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
DirectoryManager dirMgr = new DirectoryManager(_config, _song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, _song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
filePath = dirMgr.SongDirectory;
|
filePath = dirMgr.SongDirectory;
|
||||||
|
|
||||||
if (!song.FileName.EndsWith(".mp3"))
|
if (!song.FileName.EndsWith(".mp3"))
|
||||||
filePath += $"{song.FileName}.mp3";
|
filePath += $"{song.FileName}.mp3";
|
||||||
else
|
else
|
||||||
@@ -305,8 +313,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
|
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
|
||||||
AlbumRepository alStoreContext,
|
AlbumRepository alStoreContext, ArtistRepository arStoreContext)
|
||||||
ArtistRepository arStoreContext)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -318,6 +325,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
var filePath = dirMgr.SongDirectory;
|
var filePath = dirMgr.SongDirectory;
|
||||||
|
|
||||||
if (!songFile.FileName.EndsWith(".mp3"))
|
if (!songFile.FileName.EndsWith(".mp3"))
|
||||||
filePath += $"{songFile.FileName}.mp3";
|
filePath += $"{songFile.FileName}.mp3";
|
||||||
else
|
else
|
||||||
@@ -342,7 +350,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore,
|
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore,
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
AlbumRepository albumStore, ArtistRepository artistStore,
|
||||||
GenreRepository genreStore, YearRepository yearStore)
|
GenreRepository genreStore, YearRepository yearStore,
|
||||||
|
CoverArtRepository coverArtStore)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -350,11 +359,13 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
|
var fileTempPath = Path.Combine(_tempDirectoryRoot, songFile.FileName);
|
||||||
var song = await SaveSongTemp(songFile, fileTempPath);
|
var song = await SaveSongTemp(songFile, fileTempPath);
|
||||||
System.IO.File.Delete(fileTempPath);
|
song.SongPath = fileTempPath;
|
||||||
|
|
||||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
|
|
||||||
|
System.IO.File.Delete(fileTempPath);
|
||||||
|
|
||||||
var filePath = dirMgr.SongDirectory;
|
var filePath = dirMgr.SongDirectory;
|
||||||
var songFilename = songFile.FileName;
|
var songFilename = songFile.FileName;
|
||||||
|
|
||||||
@@ -365,6 +376,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info($"Absolute song path: {filePath}");
|
_logger.Info($"Absolute song path: {filePath}");
|
||||||
|
|
||||||
|
|
||||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||||
{
|
{
|
||||||
await (songFile.CopyToAsync(fileStream));
|
await (songFile.CopyToAsync(fileStream));
|
||||||
@@ -373,6 +385,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Song successfully saved to filesystem");
|
_logger.Info("Song successfully saved to filesystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var coverMgr = new CoverArtManager(_config.GetValue<string>("CoverArtPath"));
|
||||||
|
var coverArt = coverMgr.SaveCoverArt(song);
|
||||||
|
|
||||||
|
coverMgr.SaveCoverArtToDatabase(ref song, ref coverArt,
|
||||||
|
coverArtStore);
|
||||||
SaveSongToDatabase(song, songStore, albumStore, artistStore, genreStore,
|
SaveSongToDatabase(song, songStore, albumStore, artistStore, genreStore,
|
||||||
yearStore);
|
yearStore);
|
||||||
}
|
}
|
||||||
@@ -599,9 +616,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
if (!currentTitle.Equals(songUpdates.Title) || !currentArtist.Equals(songUpdates.Artist) ||
|
if (!currentTitle.Equals(songUpdates.Title) || !currentArtist.Equals(songUpdates.Artist) ||
|
||||||
!currentAlbum.Equals(songUpdates.AlbumTitle) ||
|
!currentAlbum.Equals(songUpdates.AlbumTitle) ||
|
||||||
!currentGenre.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
|
!currentGenre.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -793,9 +808,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = DoesSongExistOnFilesystem(song);
|
return DoesSongExistOnFilesystem(song);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
private bool DoesSongExistOnFilesystem(Song song)
|
private bool DoesSongExistOnFilesystem(Song song)
|
||||||
{
|
{
|
||||||
@@ -824,13 +837,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
var info = string.Empty;
|
var info = string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(newAlbumArtist))
|
if (string.IsNullOrEmpty(newAlbumArtist))
|
||||||
{
|
|
||||||
newAlbumArtist = oldAlbumArtist;
|
newAlbumArtist = oldAlbumArtist;
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(newAlbumTitle))
|
if (string.IsNullOrEmpty(newAlbumTitle))
|
||||||
{
|
|
||||||
newAlbumTitle = oldAlbumTitle;
|
newAlbumTitle = oldAlbumTitle;
|
||||||
}
|
|
||||||
|
|
||||||
if ((string.IsNullOrEmpty(newAlbumTitle) && string.IsNullOrEmpty(newAlbumArtist) ||
|
if ((string.IsNullOrEmpty(newAlbumTitle) && string.IsNullOrEmpty(newAlbumArtist) ||
|
||||||
oldAlbumTitle.Equals(newAlbumTitle) && oldAlbumArtist.Equals(newAlbumArtist)))
|
oldAlbumTitle.Equals(newAlbumTitle) && oldAlbumArtist.Equals(newAlbumArtist)))
|
||||||
@@ -1032,9 +1041,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Changes to song record found");
|
_logger.Info("Changes to song record found");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(newSongRecord.Title))
|
if (!string.IsNullOrEmpty(newSongRecord.Title))
|
||||||
{
|
|
||||||
updatedSongRecord.Title = newSongRecord.Title;
|
updatedSongRecord.Title = newSongRecord.Title;
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(newSongRecord.AlbumTitle))
|
if (!string.IsNullOrEmpty(newSongRecord.AlbumTitle))
|
||||||
{
|
{
|
||||||
updatedSongRecord.AlbumTitle = newSongRecord.AlbumTitle;
|
updatedSongRecord.AlbumTitle = newSongRecord.AlbumTitle;
|
||||||
@@ -1052,9 +1059,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
||||||
}
|
}
|
||||||
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
||||||
{
|
|
||||||
updatedSongRecord.Year = newSongRecord.Year;
|
updatedSongRecord.Year = newSongRecord.Year;
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Applied changes to song record");
|
_logger.Info("Applied changes to song record");
|
||||||
|
|
||||||
@@ -1090,21 +1095,15 @@ namespace Icarus.Controllers.Managers
|
|||||||
System.IO.File.Delete(oldSongPath);
|
System.IO.File.Delete(oldSongPath);
|
||||||
|
|
||||||
if (System.IO.File.Exists(oldSongPath))
|
if (System.IO.File.Exists(oldSongPath))
|
||||||
{
|
|
||||||
Console.WriteLine("Old path exists when it should not");
|
Console.WriteLine("Old path exists when it should not");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Saving song metadata to the database");
|
_logger.Info("Saving song metadata to the database");
|
||||||
|
|
||||||
if (songStore.DoesSongExist(newSongRecord))
|
if (songStore.DoesSongExist(newSongRecord))
|
||||||
{
|
|
||||||
songStore.UpdateSong(updatedSongRecord);
|
songStore.UpdateSong(updatedSongRecord);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
songStore.SaveSong(updatedSongRecord);
|
songStore.SaveSong(updatedSongRecord);
|
||||||
}
|
|
||||||
|
|
||||||
newSongRecord = updatedSongRecord;
|
newSongRecord = updatedSongRecord;
|
||||||
|
|
||||||
@@ -1135,10 +1134,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var album = albumStore.GetAlbum(song, true);
|
var album = albumStore.GetAlbum(song, true);
|
||||||
|
|
||||||
if (album.SongCount <= 1)
|
if (album.SongCount <= 1)
|
||||||
{
|
|
||||||
albumStore.DeleteAlbum(album);
|
albumStore.DeleteAlbum(album);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore)
|
private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore)
|
||||||
{
|
{
|
||||||
if (!artistStore.DoesArtistExist(song))
|
if (!artistStore.DoesArtistExist(song))
|
||||||
@@ -1150,10 +1147,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var artist = artistStore.GetArtist(song, true);
|
var artist = artistStore.GetArtist(song, true);
|
||||||
|
|
||||||
if (artist.SongCount <= 1)
|
if (artist.SongCount <= 1)
|
||||||
{
|
|
||||||
artistStore.DeleteArtist(artist);
|
artistStore.DeleteArtist(artist);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore)
|
private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore)
|
||||||
{
|
{
|
||||||
if (!genreStore.DoesGenreExist(song))
|
if (!genreStore.DoesGenreExist(song))
|
||||||
@@ -1165,10 +1160,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var genre = genreStore.GetGenre(song, true);
|
var genre = genreStore.GetGenre(song, true);
|
||||||
|
|
||||||
if (genre.SongCount <= 1)
|
if (genre.SongCount <= 1)
|
||||||
{
|
|
||||||
genreStore.DeleteGenre(genre);
|
genreStore.DeleteGenre(genre);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteYearFromDatabase(Song song, YearRepository yearStore)
|
private void DeleteYearFromDatabase(Song song, YearRepository yearStore)
|
||||||
{
|
{
|
||||||
if (!yearStore.DoesYearExist(song))
|
if (!yearStore.DoesYearExist(song))
|
||||||
@@ -1180,10 +1173,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var year = yearStore.GetSongYear(song, true);
|
var year = yearStore.GetSongYear(song, true);
|
||||||
|
|
||||||
if (year.SongCount <= 1)
|
if (year.SongCount <= 1)
|
||||||
{
|
|
||||||
yearStore.DeleteYear(year);
|
yearStore.DeleteYear(year);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async Task PopulateSongDetails()
|
private async Task PopulateSongDetails()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Serializing token object into JSON");
|
_logger.Info("Serializing token object into JSON");
|
||||||
var tokenObject = JsonConvert.SerializeObject(tokenRequest);
|
var tokenObject = JsonConvert.SerializeObject(tokenRequest);
|
||||||
Console.WriteLine(tokenObject);
|
|
||||||
request.AddParameter("application/json; charset=utf-8",
|
request.AddParameter("application/json; charset=utf-8",
|
||||||
tokenObject, ParameterType.RequestBody);
|
tokenObject, ParameterType.RequestBody);
|
||||||
|
|
||||||
@@ -61,15 +61,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
var tokenResult = JsonConvert
|
var tokenResult = JsonConvert
|
||||||
.DeserializeObject<Token>(response.Content);
|
.DeserializeObject<Token>(response.Content);
|
||||||
_logger.Info("Response deserialized");
|
_logger.Info("Response deserialized");
|
||||||
Console.WriteLine(response.Content);
|
|
||||||
|
|
||||||
return new LoginResult
|
return new LoginResult
|
||||||
{
|
{
|
||||||
UserId = user.Id,
|
UserId = user.Id, Username = user.Username, Token = tokenResult.AccessToken,
|
||||||
Username = user.Username,
|
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
||||||
Token = tokenResult.AccessToken,
|
|
||||||
TokenType = tokenResult.TokenType,
|
|
||||||
Expiration = tokenResult.Expiration,
|
|
||||||
Message = "Successfully retrieved token"
|
Message = "Successfully retrieved token"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -80,10 +76,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
return new TokenRequest
|
return new TokenRequest
|
||||||
{
|
{
|
||||||
ClientId = _clientId,
|
ClientId = _clientId, ClientSecret = _clientSecret,
|
||||||
ClientSecret = _clientSecret,
|
Audience = _audience, GrantType = _grantType
|
||||||
Audience = _audience,
|
|
||||||
GrantType = _grantType
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +92,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
_url = $"https://{_config["Auth0:Domain"]}";
|
_url = $"https://{_config["Auth0:Domain"]}";
|
||||||
|
|
||||||
PrintCredentials();
|
PrintCredentials();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Testing Methods
|
#region Testing Methods
|
||||||
|
|||||||
@@ -101,6 +101,25 @@ namespace Icarus.Controllers.Utilities
|
|||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] RetrieveCoverArtBytes(Song song)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Fetching image");
|
||||||
|
var tag = TagLib.File.Create(song.SongPath);
|
||||||
|
byte[] imgBytes = tag.Tag.Pictures[0].Data.Data;
|
||||||
|
|
||||||
|
return imgBytes;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred in MetadataRetriever");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateMetadata(Song song)
|
public void UpdateMetadata(Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -140,6 +159,22 @@ namespace Icarus.Controllers.Utilities
|
|||||||
Message = "Failed to update metadata";
|
Message = "Failed to update metadata";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void UpdateCoverArt(Song song, CoverArt coverArt)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Updating song's cover art");
|
||||||
|
|
||||||
|
var tag = TagLib.File.Create(song.SongPath);
|
||||||
|
var pics = tag.Tag.Pictures;
|
||||||
|
Array.Resize(ref pics, 1);
|
||||||
|
|
||||||
|
pics[0] = new Picture(coverArt.ImagePath)
|
||||||
|
{
|
||||||
|
Description = "Cover Art"
|
||||||
|
};
|
||||||
|
|
||||||
|
tag.Tag.Pictures = pics;
|
||||||
|
tag.Save();
|
||||||
|
}
|
||||||
|
|
||||||
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
|
private void PerformUpdate(Song updatedSong, SortedDictionary<string, bool> checkedValues)
|
||||||
{
|
{
|
||||||
@@ -161,7 +196,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
|
||||||
switch (key.ToLower())
|
switch (key.ToLower())
|
||||||
{
|
{
|
||||||
case "title":
|
case "title":
|
||||||
@@ -186,7 +220,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fileTag.Save();
|
fileTag.Save();
|
||||||
|
|
||||||
@@ -263,18 +296,14 @@ namespace Icarus.Controllers.Utilities
|
|||||||
songValues["Artists"] = String.IsNullOrEmpty(song.Artist);
|
songValues["Artists"] = String.IsNullOrEmpty(song.Artist);
|
||||||
songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle);
|
songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle);
|
||||||
songValues["Genre"] = String.IsNullOrEmpty(song.Genre);
|
songValues["Genre"] = String.IsNullOrEmpty(song.Genre);
|
||||||
|
|
||||||
if (song.Year == null)
|
if (song.Year == null)
|
||||||
{
|
|
||||||
songValues["Year"] = true;
|
songValues["Year"] = true;
|
||||||
}
|
|
||||||
else if (song.Year==0)
|
else if (song.Year==0)
|
||||||
{
|
|
||||||
songValues["Year"] = true;
|
songValues["Year"] = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
songValues["Year"] = false;
|
songValues["Year"] = false;
|
||||||
}
|
|
||||||
Console.WriteLine("Checking for null data completed");
|
Console.WriteLine("Checking for null data completed");
|
||||||
_logger.Info("Checking for null data completed");
|
_logger.Info("Checking for null data completed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
|
|
||||||
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
||||||
password: password,
|
password: password, salt: salt,
|
||||||
salt: salt,
|
|
||||||
prf: KeyDerivationPrf.HMACSHA1,
|
prf: KeyDerivationPrf.HMACSHA1,
|
||||||
iterationCount: 10000,
|
iterationCount: 10000,
|
||||||
numBytesRequested: 256/8));
|
numBytesRequested: 256/8));
|
||||||
@@ -81,9 +80,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
byte[] salt = new byte[128/8];
|
byte[] salt = new byte[128/8];
|
||||||
|
|
||||||
using (var rng = RandomNumberGenerator.Create())
|
using (var rng = RandomNumberGenerator.Create())
|
||||||
{
|
|
||||||
rng.GetBytes(salt);
|
rng.GetBytes(salt);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return salt;
|
return salt;
|
||||||
|
|||||||
@@ -40,21 +40,16 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
List<Album> albums = new List<Album>();
|
List<Album> albums = new List<Album>();
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
albums = albumStoreContext.GetAlbums();
|
albums = albumStoreContext.GetAlbums();
|
||||||
|
|
||||||
if (albums.Count > 0)
|
if (albums.Count > 0)
|
||||||
{
|
|
||||||
return Ok(albums);
|
return Ok(albums);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:albums")]
|
[Authorize("read:albums")]
|
||||||
@@ -65,8 +60,7 @@ namespace Icarus.Controllers.V1
|
|||||||
AlbumId = id
|
AlbumId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
if (albumStoreContext.DoesAlbumExist(album))
|
if (albumStoreContext.DoesAlbumExist(album))
|
||||||
@@ -76,10 +70,8 @@ namespace Icarus.Controllers.V1
|
|||||||
return Ok(album);
|
return Ok(album);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("read:artists")]
|
[Authorize("read:artists")]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
var artists = artistStoreContext.GetArtists();
|
var artists = artistStoreContext.GetArtists();
|
||||||
|
|
||||||
if (artists.Count > 0)
|
if (artists.Count > 0)
|
||||||
{
|
|
||||||
return Ok(artists);
|
return Ok(artists);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:artists")]
|
[Authorize("read:artists")]
|
||||||
@@ -64,22 +59,18 @@ namespace Icarus.Controllers.V1
|
|||||||
ArtistId = id
|
ArtistId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
if (artistStoreContext.DoesArtistExist(artist))
|
if (artistStoreContext.DoesArtistExist(artist))
|
||||||
{
|
{
|
||||||
artist = artistStoreContext.GetArtist(artist);
|
artist = artistStoreContext.GetArtist(artist);
|
||||||
|
|
||||||
|
|
||||||
return Ok(artist);
|
return Ok(artist);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
using Icarus.Controllers.Managers;
|
||||||
|
using Icarus.Database.Repositories;
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers.V1
|
||||||
|
{
|
||||||
|
[Route("api/v1/coverart")]
|
||||||
|
[ApiController]
|
||||||
|
public class CoverArtController : ControllerBase
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private readonly ILogger<CoverArtController> _logger;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public CoverArtController(ILogger<CoverArtController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region HTTP Routes
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize("download:cover_art")]
|
||||||
|
public IActionResult Get(int id)
|
||||||
|
{
|
||||||
|
var coverArt = new CoverArt { CoverArtId = id };
|
||||||
|
|
||||||
|
var coverArtRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(
|
||||||
|
typeof(CoverArtRepository)) as CoverArtRepository;
|
||||||
|
|
||||||
|
coverArt = coverArtRepository.GetCoverArt(coverArt);
|
||||||
|
|
||||||
|
if (coverArt != null)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Found cover art record");
|
||||||
|
var coverArtBytes = System.IO.File.ReadAllBytes(
|
||||||
|
coverArt.ImagePath);
|
||||||
|
|
||||||
|
return File(coverArtBytes, "application/x-msdownload",
|
||||||
|
coverArt.SongTitle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Cover art not found");
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
var genres = new List<Genre>();
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
var genreStore = HttpContext
|
var genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
genres = genreStore.GetGenres();
|
genres = genreStore.GetGenres();
|
||||||
|
|
||||||
if (genres.Count > 0)
|
if (genres.Count > 0)
|
||||||
{
|
|
||||||
return Ok(genres);
|
return Ok(genres);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new List<Genre>());
|
return NotFound(new List<Genre>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:genre")]
|
[Authorize("read:genre")]
|
||||||
@@ -64,8 +59,7 @@ namespace Icarus.Controllers.V1
|
|||||||
GenreId = id
|
GenreId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
var genreStore = HttpContext
|
var genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
if (genreStore.DoesGenreExist(genre))
|
if (genreStore.DoesGenreExist(genre))
|
||||||
@@ -75,10 +69,8 @@ namespace Icarus.Controllers.V1
|
|||||||
return Ok(genre);
|
return Ok(genre);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new Genre());
|
return NotFound(new Genre());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace Icarus.Controllers.V1
|
|||||||
#region HTTP endpoints
|
#region HTTP endpoints
|
||||||
public IActionResult Post([FromBody] User user)
|
public IActionResult Post([FromBody] User user)
|
||||||
{
|
{
|
||||||
UserRepository context = HttpContext
|
UserRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(UserRepository)) as UserRepository;
|
.GetService(typeof(UserRepository)) as UserRepository;
|
||||||
|
|
||||||
_logger.LogInformation("Starting process of validating credentials");
|
_logger.LogInformation("Starting process of validating credentials");
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace Icarus.Controllers.V1
|
|||||||
user.Password = pe.HashPassword(user);
|
user.Password = pe.HashPassword(user);
|
||||||
user.EmailVerified = false;
|
user.EmailVerified = false;
|
||||||
|
|
||||||
UserRepository context = HttpContext
|
UserRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(UserRepository)) as UserRepository;
|
.GetService(typeof(UserRepository)) as UserRepository;
|
||||||
|
|
||||||
context.SaveUser(user);
|
context.SaveUser(user);
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("download:songs")]
|
[Authorize("download:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
SongCompression cmp = new SongCompression(_archiveDir);
|
SongCompression cmp = new SongCompression(_archiveDir);
|
||||||
|
|||||||
@@ -49,28 +49,22 @@ namespace Icarus.Controllers.V1
|
|||||||
Console.WriteLine("Attemtping to retrieve songs");
|
Console.WriteLine("Attemtping to retrieve songs");
|
||||||
_logger.LogInformation("Attempting to retrieve songs");
|
_logger.LogInformation("Attempting to retrieve songs");
|
||||||
|
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
songs = context.GetAllSongs();
|
songs = context.GetAllSongs();
|
||||||
|
|
||||||
if (songs.Count > 0)
|
if (songs.Count > 0)
|
||||||
{
|
|
||||||
return Ok(songs);
|
return Ok(songs);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:song_details")]
|
[Authorize("read:song_details")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
Song song = new Song { Id = id };
|
Song song = new Song { Id = id };
|
||||||
@@ -79,37 +73,28 @@ namespace Icarus.Controllers.V1
|
|||||||
Console.WriteLine("Here");
|
Console.WriteLine("Here");
|
||||||
|
|
||||||
if (song.Id != 0)
|
if (song.Id != 0)
|
||||||
{
|
|
||||||
return Ok(song);
|
return Ok(song);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Authorize("update:songs")]
|
[Authorize("update:songs")]
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public IActionResult Put(int id, [FromBody] Song song)
|
public IActionResult Put(int id, [FromBody] Song song)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
ArtistRepository artistStore = HttpContext
|
ArtistRepository artistStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
AlbumRepository albumStore = HttpContext
|
AlbumRepository albumStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
GenreRepository genreStore = HttpContext
|
GenreRepository genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
YearRepository yearStore = HttpContext
|
YearRepository yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
song.Id = id;
|
song.Id = id;
|
||||||
@@ -117,12 +102,10 @@ namespace Icarus.Controllers.V1
|
|||||||
_logger.LogInformation("Retrieving filepath of song");
|
_logger.LogInformation("Retrieving filepath of song");
|
||||||
|
|
||||||
if (!context.DoesSongExist(song))
|
if (!context.DoesSongExist(song))
|
||||||
{
|
|
||||||
return NotFound(new SongResult
|
return NotFound(new SongResult
|
||||||
{
|
{
|
||||||
Message = "Song does not exist"
|
Message = "Song does not exist"
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
||||||
yearStore);
|
yearStore);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
using Icarus.Database.Contexts;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Repositories;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
@@ -22,6 +23,12 @@ namespace Icarus.Controllers.V1
|
|||||||
public class SongDataController : ControllerBase
|
public class SongDataController : ControllerBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private SongRepository _songRepository;
|
||||||
|
private AlbumRepository _albumRepository;
|
||||||
|
private ArtistRepository _artistRepository;
|
||||||
|
private GenreRepository _genreRepository;
|
||||||
|
private YearRepository _yearRepository;
|
||||||
|
private CoverArtRepository _coverArtRepository;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
private ILogger<SongDataController> _logger;
|
private ILogger<SongDataController> _logger;
|
||||||
private SongManager _songMgr;
|
private SongManager _songMgr;
|
||||||
@@ -43,16 +50,42 @@ namespace Icarus.Controllers.V1
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
_songRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService
|
||||||
|
(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
|
_albumRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
|
_artistRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
|
_genreRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
|
_yearRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
|
_coverArtRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(CoverArtRepository)) as CoverArtRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Route("private-scoped")]
|
[Route("private-scoped")]
|
||||||
[Authorize("download:songs")]
|
[Authorize("download:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
Initialize();
|
||||||
.RequestServices
|
var songMetaData = _songRepository.GetSong(id);
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
var songMetaData = context.GetSong(id);
|
|
||||||
|
|
||||||
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
||||||
|
|
||||||
@@ -65,21 +98,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SongRepository songRepository = HttpContext
|
Initialize();
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
|
||||||
GenreRepository genreStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
|
||||||
YearRepository yearStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
|
||||||
|
|
||||||
Console.WriteLine("Uploading song...");
|
Console.WriteLine("Uploading song...");
|
||||||
_logger.LogInformation("Uploading song...");
|
_logger.LogInformation("Uploading song...");
|
||||||
@@ -88,15 +107,13 @@ namespace Icarus.Controllers.V1
|
|||||||
Console.WriteLine($"Song Root Path {uploads}");
|
Console.WriteLine($"Song Root Path {uploads}");
|
||||||
_logger.LogInformation($"Song root path {uploads}");
|
_logger.LogInformation($"Song root path {uploads}");
|
||||||
foreach (var sng in songData)
|
foreach (var sng in songData)
|
||||||
{
|
|
||||||
if (sng.Length > 0) {
|
if (sng.Length > 0) {
|
||||||
Console.WriteLine($"Song filename {sng.FileName}");
|
Console.WriteLine($"Song filename {sng.FileName}");
|
||||||
_logger.LogInformation($"Song filename {sng.FileName}");
|
_logger.LogInformation($"Song filename {sng.FileName}");
|
||||||
|
|
||||||
await _songMgr.SaveSongToFileSystem(sng, songRepository,
|
await _songMgr.SaveSongToFileSystem(sng, _songRepository,
|
||||||
albumStoreContext, artistStoreContext,
|
_albumRepository, _artistRepository,
|
||||||
genreStore, yearStore);
|
_genreRepository, _yearRepository, _coverArtRepository);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -110,25 +127,11 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("delete:songs")]
|
[Authorize("delete:songs")]
|
||||||
public IActionResult Delete(int id)
|
public IActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
Initialize();
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
AlbumRepository albumStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
|
||||||
ArtistRepository artistStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
|
||||||
GenreRepository genreStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
|
||||||
YearRepository yearStore = HttpContext
|
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
|
||||||
|
|
||||||
var songMetaData = new Song{ Id = id };
|
var songMetaData = new Song{ Id = id };
|
||||||
Console.WriteLine($"Id {songMetaData.Id}");
|
Console.WriteLine($"Id {songMetaData.Id}");
|
||||||
songMetaData = context.GetSong(songMetaData);
|
songMetaData = _songRepository.GetSong(songMetaData);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||||
{
|
{
|
||||||
@@ -139,8 +142,10 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
||||||
|
|
||||||
_songMgr.DeleteSong(songMetaData, context, albumStore,
|
_songMgr.DeleteSong(songMetaData, _songRepository,
|
||||||
artistStore, genreStore, yearStore);
|
_albumRepository, _artistRepository,
|
||||||
|
_genreRepository, _yearRepository,
|
||||||
|
_coverArtRepository);
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("stream:songs")]
|
[Authorize("stream:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
var songStore= HttpContext
|
var songStore= HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
var song = songStore.GetSong(new Song { Id = id });
|
var song = songStore.GetSong(new Song { Id = id });
|
||||||
@@ -51,9 +50,7 @@ namespace Icarus.Controllers.V1
|
|||||||
var mem = new MemoryStream();
|
var mem = new MemoryStream();
|
||||||
|
|
||||||
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||||
{
|
|
||||||
await stream.CopyToAsync(mem);
|
await stream.CopyToAsync(mem);
|
||||||
}
|
|
||||||
|
|
||||||
mem.Position = 0;
|
mem.Position = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controller.V1
|
|||||||
{
|
{
|
||||||
var yearValues = new List<Year>();
|
var yearValues = new List<Year>();
|
||||||
|
|
||||||
var yearStore = HttpContext
|
var yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
yearValues = yearStore.GetSongYears();
|
yearValues = yearStore.GetSongYears();
|
||||||
|
|
||||||
if (yearValues.Count > 0)
|
if (yearValues.Count > 0)
|
||||||
{
|
|
||||||
return Ok(yearValues);
|
return Ok(yearValues);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new List<Year>());
|
return NotFound(new List<Year>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:year")]
|
[Authorize("read:year")]
|
||||||
@@ -64,8 +59,7 @@ namespace Icarus.Controller.V1
|
|||||||
YearId = id
|
YearId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
var yearStore = HttpContext
|
var yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
if (yearStore.DoesYearExist(year))
|
if (yearStore.DoesYearExist(year))
|
||||||
@@ -75,10 +69,8 @@ namespace Icarus.Controller.V1
|
|||||||
return Ok(year);
|
return Ok(year);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new Year());
|
return NotFound(new Year());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Album> Albums { get; set; }
|
public DbSet<Album> Albums { get; set; }
|
||||||
|
|
||||||
public AlbumContext(DbContextOptions<AlbumContext> options)
|
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Artist> Artists { get; set; }
|
public DbSet<Artist> Artists { get; set; }
|
||||||
|
|
||||||
public ArtistContext(DbContextOptions<ArtistContext> options)
|
public ArtistContext(DbContextOptions<ArtistContext> options) : base (options) { }
|
||||||
: base (options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MySql.Data;
|
||||||
|
using MySql.Data.EntityFrameworkCore.Extensions;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
|
namespace Icarus.Database.Contexts
|
||||||
|
{
|
||||||
|
public class CoverArtContext : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<CoverArt> CoverArtImages { get; set; }
|
||||||
|
|
||||||
|
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<CoverArt>()
|
||||||
|
.ToTable("CoverArt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,10 +13,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public class GenreContext : DbContext
|
public class GenreContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Genre> Genres { get; set; }
|
public DbSet<Genre> Genres { get; set; }
|
||||||
|
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
|
||||||
public GenreContext(DbContextOptions<GenreContext> options)
|
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public DbSet<Song> Songs { get; set; }
|
public DbSet<Song> Songs { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public SongContext(DbContextOptions<SongContext> options)
|
public SongContext(DbContextOptions<SongContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@@ -48,6 +46,12 @@ namespace Icarus.Database.Contexts
|
|||||||
.HasForeignKey(s => s.YearId)
|
.HasForeignKey(s => s.YearId)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.HasOne(s => s.SongCoverArt)
|
||||||
|
.WithMany(ca => ca.Songs)
|
||||||
|
.HasForeignKey(s => s.CoverArtId)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.Year)
|
.Property(s => s.Year)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
@@ -63,6 +67,9 @@ namespace Icarus.Database.Contexts
|
|||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.AlbumId)
|
.Property(s => s.AlbumId)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.Property(s => s.CoverArtId)
|
||||||
|
.IsRequired(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public UserContext(DbContextOptions<UserContext> options)
|
public UserContext(DbContextOptions<UserContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Year> YearValues { get; set; }
|
public DbSet<Year> YearValues { get; set; }
|
||||||
|
|
||||||
public YearContext(DbContextOptions<YearContext> options)
|
public YearContext(DbContextOptions<YearContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ namespace Icarus.Database.Repositories
|
|||||||
var albums = new List<Album>();
|
var albums = new List<Album>();
|
||||||
|
|
||||||
if (AnyAlbums())
|
if (AnyAlbums())
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (MySqlConnection conn = GetConnection())
|
using (MySqlConnection conn = GetConnection())
|
||||||
@@ -40,20 +39,15 @@ namespace Icarus.Database.Repositories
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
var query = "SELECT * FROM Album";
|
var query = "SELECT * FROM Album";
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
_logger.Error(msg, "An error occurred");
|
_logger.Error(msg, "An error occurred");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return albums;
|
return albums;
|
||||||
}
|
}
|
||||||
@@ -70,14 +64,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
||||||
"alb.AlbumId=sng.AlbumId GROUP BY alb.AlbumId";
|
"alb.AlbumId=sng.AlbumId GROUP BY alb.AlbumId";
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -103,12 +93,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@AlbumId", album.AlbumId);
|
cmd.Parameters.AddWithValue("@AlbumId", album.AlbumId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -135,12 +123,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -160,28 +146,22 @@ namespace Icarus.Database.Repositories
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT alb.*, COUNT(*) AS SongCount FROM Album alb " +
|
query = "SELECT alb.*, COUNT(*) AS SongCount FROM Album alb " +
|
||||||
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
||||||
"alb.Title=@Title GROUP BY alb.AlbumId LIMIT 1";
|
"alb.Title=@Title GROUP BY alb.AlbumId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT alb.*, 0 AS SongCount FROM Album alb WHERE " +
|
query = "SELECT alb.*, 0 AS SongCount FROM Album alb WHERE " +
|
||||||
"alb.Title=@Title LIMIT 1";
|
"alb.Title=@Title LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -391,18 +371,12 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Album";
|
var query = "SELECT * FROM Album";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (albums.Count > 0)
|
if (albums.Count > 0)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY art.ArtistId";
|
"GROUP BY art.ArtistId";
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
|
|
||||||
artists = ParseData(reader);
|
artists = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -78,12 +73,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@ArtistId", artist.ArtistId);
|
cmd.Parameters.AddWithValue("@ArtistId", artist.ArtistId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -109,12 +102,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -137,28 +128,22 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT art.*, COUNT(*) AS SongCount FROM Artist " +
|
query = "SELECT art.*, COUNT(*) AS SongCount FROM Artist " +
|
||||||
"art LEFT JOIN Song sng ON art.ArtistId=sng.ArtistId " +
|
"art LEFT JOIN Song sng ON art.ArtistId=sng.ArtistId " +
|
||||||
"WHERE art.Name=@Name GROUP BY art.ArtistId LIMIT 1";
|
"WHERE art.Name=@Name GROUP BY art.ArtistId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT art.*, 0 AS SongCount FROM Artist art " +
|
query = "SELECT art.*, 0 AS SongCount FROM Artist art " +
|
||||||
"WHERE art.Name=@Name LIMIT 1";
|
"WHERE art.Name=@Name LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -0,0 +1,255 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
using Icarus.Models;
|
||||||
|
using Icarus.Types;
|
||||||
|
|
||||||
|
namespace Icarus.Database.Repositories
|
||||||
|
{
|
||||||
|
public class CoverArtRepository : BaseRepository
|
||||||
|
{
|
||||||
|
#region Constructors
|
||||||
|
public CoverArtRepository(string connectionString)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public CoverArt GetCoverArt(CoverArt cover)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Querying cover art record");
|
||||||
|
|
||||||
|
var query = "SELECT * FROM CoverArt WHERE " +
|
||||||
|
"CoverArtId=@CoverArtId";
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters
|
||||||
|
.AddWithValue("@CoverArtId", cover.CoverArtId);
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
return ParseSingleData(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CoverArt GetCoverArt(Song song)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Querying cover art record");
|
||||||
|
|
||||||
|
var query = "SELECT cov.* FROM CoverArt cov LEFT JOIN " +
|
||||||
|
"Song sng ON cov.CoverArtId=sng.CoverArtId WHERE " +
|
||||||
|
"sng.Id=@SongId";
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.AddWithValue("@SongId", song.Id);
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
return ParseSingleData(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CoverArt GetCoverArt(CoverArtField field, CoverArt cover)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Querying cover art record");
|
||||||
|
|
||||||
|
using (var cmd = new MySqlCommand(BuildQuery(field), conn))
|
||||||
|
{
|
||||||
|
switch (field)
|
||||||
|
{
|
||||||
|
case CoverArtField.SongTitle:
|
||||||
|
cmd.Parameters.AddWithValue("@SongTitle",
|
||||||
|
cover.SongTitle);
|
||||||
|
break;
|
||||||
|
case CoverArtField.ImagePath:
|
||||||
|
cmd.Parameters.AddWithValue("@ImagePath",
|
||||||
|
cover.ImagePath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
return ParseSingleData(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DoesCoverArtExist(CoverArt cover)
|
||||||
|
{
|
||||||
|
return GetCoverArt(cover) != null ? true : false;
|
||||||
|
}
|
||||||
|
public bool DoesCoverArtExist(Song song)
|
||||||
|
{
|
||||||
|
return GetCoverArt(song) != null ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveCoverArt(CoverArt coverArt)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Saving cover art record");
|
||||||
|
|
||||||
|
var query = "INSERT INTO CoverArt(SongTitle, ImagePath) " +
|
||||||
|
"VALUES(@SongTitle, @ImagePath)";
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters
|
||||||
|
.AddWithValue("@SongTitle", coverArt.SongTitle);
|
||||||
|
cmd.Parameters
|
||||||
|
.AddWithValue("@ImagePath", coverArt.ImagePath);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DeleteCoverArt(CoverArt cover)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Deleting cover art record");
|
||||||
|
|
||||||
|
var query = "DELETE FROM CoverArt WHERE " +
|
||||||
|
"CoverArtId=@CoverArtId";
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters
|
||||||
|
.AddWithValue("@CoverArtId", cover.CoverArtId);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CoverArt> ParseData(MySqlDataReader reader)
|
||||||
|
{
|
||||||
|
if (reader.HasRows)
|
||||||
|
{
|
||||||
|
var coverArtList = new List<CoverArt>();
|
||||||
|
_logger.Info("Parsing cover art records");
|
||||||
|
while (reader.Read())
|
||||||
|
coverArtList.Add(new CoverArt
|
||||||
|
{
|
||||||
|
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
||||||
|
SongTitle = reader["SongTitle"].ToString(),
|
||||||
|
ImagePath = reader["ImagePath"].ToString()
|
||||||
|
});
|
||||||
|
|
||||||
|
return coverArtList;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CoverArt ParseSingleData(MySqlDataReader reader)
|
||||||
|
{
|
||||||
|
if (reader.HasRows)
|
||||||
|
{
|
||||||
|
_logger.Info("Parsing single cover art record");
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
return new CoverArt
|
||||||
|
{
|
||||||
|
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
||||||
|
SongTitle = reader["SongTitle"].ToString(),
|
||||||
|
ImagePath = reader["ImagePath"].ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildQuery(CoverArtField field)
|
||||||
|
{
|
||||||
|
switch (field)
|
||||||
|
{
|
||||||
|
case CoverArtField.SongTitle:
|
||||||
|
return "SELECT * FROM CoverArt WHERE SongTitle=@SongTitle";
|
||||||
|
case CoverArtField.ImagePath:
|
||||||
|
return "SELECT * FROM CoverArt WHERE ImagePath=" +
|
||||||
|
"@ImagePath";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool? AnyCoverArt()
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Checking to see if there are any cover art " +
|
||||||
|
"records");
|
||||||
|
|
||||||
|
var query = "SELECT * FROM CoverArt";
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
return reader.HasRows;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,14 +45,10 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Genre";
|
var query = "SELECT * FROM Genre";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genres = ParseData(reader);
|
genres = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -82,14 +78,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY gnr.GenreId";
|
"GROUP BY gnr.GenreId";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genres = ParseData(reader);
|
genres = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -121,12 +113,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@GenreId", genre.GenreId);
|
cmd.Parameters.AddWithValue("@GenreId", genre.GenreId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -159,12 +149,10 @@ namespace Icarus.Database.Repositories
|
|||||||
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -191,17 +179,13 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT gnr.*, COUNT(*) AS SongCount FROM Genre gnr " +
|
query = "SELECT gnr.*, COUNT(*) AS SongCount FROM Genre gnr " +
|
||||||
"LEFT JOIN Song sng ON gnr.GenreId=sng.GenreId " +
|
"LEFT JOIN Song sng ON gnr.GenreId=sng.GenreId " +
|
||||||
"WHERE gnr.GenreName=@GenreName GROUP BY gnr.GenreId " +
|
"WHERE gnr.GenreName=@GenreName GROUP BY gnr.GenreId " +
|
||||||
"LIMIT 1";
|
"LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT gnr.*, 0 AS SongCount FROM Genre gnr " +
|
query = "SELECT gnr.*, 0 AS SongCount FROM Genre gnr " +
|
||||||
"WHERE gnr.GenreName=@GenreName LIMIT 1";
|
"WHERE gnr.GenreName=@GenreName LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
@@ -209,12 +193,10 @@ namespace Icarus.Database.Repositories
|
|||||||
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -446,14 +428,10 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Genre";
|
var query = "SELECT * FROM Genre";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
return reader.HasRows;
|
return reader.HasRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ namespace Icarus.Database.Repositories
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
string query = "INSERT INTO Song(Title, AlbumTitle, Artist," +
|
string query = "INSERT INTO Song(Title, AlbumTitle, Artist," +
|
||||||
" Year, Genre, Duration, Filename, SongPath, AlbumId, " +
|
" Year, Genre, Duration, Filename, SongPath, AlbumId, " +
|
||||||
"ArtistId, GenreId, YearId) VALUES(@Title, @AlbumTitle, " +
|
"ArtistId, GenreId, YearId, CoverArtId) VALUES(@Title," +
|
||||||
"@Artist, @Year, @Genre, @Duration, @Filename, @SongPath, " +
|
" @AlbumTitle, @Artist, @Year, @Genre, @Duration, " +
|
||||||
"@AlbumId, @ArtistId, @GenreId, @YearId)";
|
"@Filename, @SongPath, @AlbumId, @ArtistId, @GenreId," +
|
||||||
|
" @YearId, @CoverArtId)";
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Title", song.Title);
|
cmd.Parameters.AddWithValue("@Title", song.Title);
|
||||||
@@ -53,6 +54,7 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@ArtistId", song.ArtistId);
|
cmd.Parameters.AddWithValue("@ArtistId", song.ArtistId);
|
||||||
cmd.Parameters.AddWithValue("@GenreId", song.GenreId);
|
cmd.Parameters.AddWithValue("@GenreId", song.GenreId);
|
||||||
cmd.Parameters.AddWithValue("@YearId", song.YearId);
|
cmd.Parameters.AddWithValue("@YearId", song.YearId);
|
||||||
|
cmd.Parameters.AddWithValue("@CoverArtId", song.CoverArtId);
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@@ -175,11 +177,9 @@ namespace Icarus.Database.Repositories
|
|||||||
Console.WriteLine("ffff");
|
Console.WriteLine("ffff");
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
songs = ParseData(reader);
|
songs = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var exMsg = ex.Message;
|
var exMsg = ex.Message;
|
||||||
@@ -207,12 +207,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Id", song.Id);
|
cmd.Parameters.AddWithValue("@Id", song.Id);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
song = ParseSingleData(reader);
|
song = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -237,10 +235,8 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Id", id);
|
cmd.Parameters.AddWithValue("@Id", id);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
song = ParseSingleData(reader);
|
song = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_logger.Info("Song found");
|
_logger.Info("Song found");
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
@@ -290,7 +286,8 @@ namespace Icarus.Database.Repositories
|
|||||||
AlbumId = Convert.ToInt32(reader["AlbumId"].ToString()),
|
AlbumId = Convert.ToInt32(reader["AlbumId"].ToString()),
|
||||||
ArtistId = Convert.ToInt32(reader["ArtistId"].ToString()),
|
ArtistId = Convert.ToInt32(reader["ArtistId"].ToString()),
|
||||||
GenreId = Convert.ToInt32(reader["GenreId"].ToString()),
|
GenreId = Convert.ToInt32(reader["GenreId"].ToString()),
|
||||||
YearId = Convert.ToInt32(reader["YearId"].ToString())
|
YearId = Convert.ToInt32(reader["YearId"].ToString()),
|
||||||
|
CoverArtId = Convert.ToInt32(reader["CoverArtId"].ToString())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,6 +313,7 @@ namespace Icarus.Database.Repositories
|
|||||||
song.ArtistId = Convert.ToInt32(reader["ArtistId"].ToString());
|
song.ArtistId = Convert.ToInt32(reader["ArtistId"].ToString());
|
||||||
song.GenreId = Convert.ToInt32(reader["GenreId"].ToString());
|
song.GenreId = Convert.ToInt32(reader["GenreId"].ToString());
|
||||||
song.YearId = Convert.ToInt32(reader["YearId"].ToString());
|
song.YearId = Convert.ToInt32(reader["YearId"].ToString());
|
||||||
|
song.CoverArtId = Convert.ToInt32(reader["CoverArtId"].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
|
|||||||
@@ -83,11 +83,9 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Username", user.Username);
|
cmd.Parameters.AddWithValue("@Username", user.Username);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
user = ParseSingleData(reader);
|
user = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Successfully retrieved user");
|
_logger.Info("Successfully retrieved user");
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY yr.YearId";
|
"GROUP BY yr.YearId";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
yearValues = ParseData(reader);
|
yearValues = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -80,12 +76,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@YearId", year.YearId);
|
cmd.Parameters.AddWithValue("@YearId", year.YearId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -114,12 +108,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -143,28 +135,22 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT yr.*, COUNT(*) AS SongCount FROM Year yr " +
|
query = "SELECT yr.*, COUNT(*) AS SongCount FROM Year yr " +
|
||||||
"LEFT JOIN Song sng ON yr.YearValue=sng.Year WHERE " +
|
"LEFT JOIN Song sng ON yr.YearValue=sng.Year WHERE " +
|
||||||
"yr.YearValue=@YearValue GROUP BY yr.YearId LIMIT 1";
|
"yr.YearValue=@YearValue GROUP BY yr.YearId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT yr.*, 0 AS SongCount FROM Year yr " +
|
query = "SELECT yr.*, 0 AS SongCount FROM Year yr " +
|
||||||
"WHERE yr.YearValue=@YearValue LIMIT 1";
|
"WHERE yr.YearValue=@YearValue LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using(var cmd = new MySqlCommand(query, conn))
|
using(var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
|
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
<Content Include="Images/Stock/*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Icarus.Models
|
||||||
|
{
|
||||||
|
public class CoverArt
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int CoverArtId { get; set; }
|
||||||
|
[JsonProperty("title")]
|
||||||
|
public string SongTitle { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public string ImagePath { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public List<Song> Songs { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,5 +45,10 @@ namespace Icarus.Models
|
|||||||
public Year SongYear { get; set; }
|
public Year SongYear { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int? YearId { get; set; }
|
public int? YearId { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public CoverArt SongCoverArt { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public int? CoverArtId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -35,14 +35,13 @@ namespace Icarus
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>()
|
||||||
.UseStartup<Startup>()
|
|
||||||
.UseUrls("http://localhost:5002")
|
.UseUrls("http://localhost:5002")
|
||||||
.ConfigureLogging(logging =>
|
.ConfigureLogging(logging =>
|
||||||
{
|
{
|
||||||
logging.ClearProviders();
|
logging.ClearProviders();
|
||||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||||
})
|
})
|
||||||
.UseNLog() ;
|
.UseNLog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduc
|
|||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
Currently under development. No version has been released
|
* [v0.1](https://github.com/amazing-username/Icarus/releases/tag/v0.1)
|
||||||
|
|
||||||
## Authors
|
## Authors
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ echo "Adding Genre migration"
|
|||||||
dotnet ef migrations add Genre --context GenreContext
|
dotnet ef migrations add Genre --context GenreContext
|
||||||
echo "Adding Year migration"
|
echo "Adding Year migration"
|
||||||
dotnet ef migrations add Year --context YearContext
|
dotnet ef migrations add Year --context YearContext
|
||||||
|
echo "Adding Cover art migration"
|
||||||
|
dotnet ef migrations add CoverArt --context CoverArtContext
|
||||||
|
|
||||||
echo "Updating migrations.."
|
echo "Updating migrations.."
|
||||||
echo "Updating User migration"
|
echo "Updating User migration"
|
||||||
@@ -20,4 +22,5 @@ echo "Updating Album migration"
|
|||||||
echo "Updating Artist migration"
|
echo "Updating Artist migration"
|
||||||
echo "Updating Genre migration"
|
echo "Updating Genre migration"
|
||||||
echo "Updating Year migration"
|
echo "Updating Year migration"
|
||||||
|
echo "Updating Cover art migration"
|
||||||
dotnet ef database update --context SongContext
|
dotnet ef database update --context SongContext
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
delete from Song where Id>0;
|
delete from Song;
|
||||||
delete from Album where AlbumId>0;
|
delete from Album;
|
||||||
delete from Artist where ArtistId>0;
|
delete from Artist;
|
||||||
|
delete from Genre;
|
||||||
|
delete from Year;
|
||||||
|
delete from CoverArt;
|
||||||
|
|||||||
+27
-38
@@ -59,53 +59,47 @@ namespace Icarus
|
|||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("download:songs", policy =>
|
options.AddPolicy("download:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("download:songs", domain)));
|
.Add(new HasScopeRequirement("download:songs", domain)));
|
||||||
|
|
||||||
|
options.AddPolicy("download:cover_art", policy =>
|
||||||
|
policy.Requirements
|
||||||
|
.Add(new HasScopeRequirement("download:cover_art", domain)));
|
||||||
|
|
||||||
options.AddPolicy("upload:songs", policy =>
|
options.AddPolicy("upload:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("upload:songs", domain)));
|
.Add(new HasScopeRequirement("upload:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("delete:songs", policy =>
|
options.AddPolicy("delete:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("delete:songs", domain)));
|
.Add(new HasScopeRequirement("delete:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:song_details", policy =>
|
options.AddPolicy("read:song_details", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:song_details", domain)));
|
.Add(new HasScopeRequirement("read:song_details", domain)));
|
||||||
|
|
||||||
options.AddPolicy("update:songs", policy =>
|
options.AddPolicy("update:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("update:songs", domain)));
|
.Add(new HasScopeRequirement("update:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:artists", policy =>
|
options.AddPolicy("read:artists", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:artists", domain)));
|
.Add(new HasScopeRequirement("read:artists", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:albums", policy =>
|
options.AddPolicy("read:albums", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:albums", domain)));
|
.Add(new HasScopeRequirement("read:albums", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:genre", policy =>
|
options.AddPolicy("read:genre", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:genre", domain)));
|
.Add(new HasScopeRequirement("read:genre", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:year", policy =>
|
options.AddPolicy("read:year", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:year", domain)));
|
.Add(new HasScopeRequirement("read:year", domain)));
|
||||||
|
|
||||||
options.AddPolicy("stream:songs", policy =>
|
options.AddPolicy("stream:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("stream:songs", domain)));
|
.Add(new HasScopeRequirement("stream:songs", domain)));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,28 +109,25 @@ namespace Icarus
|
|||||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
||||||
new SongRepository(Configuration
|
new SongRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
||||||
new AlbumRepository(Configuration
|
new AlbumRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
||||||
new ArtistRepository(Configuration
|
new ArtistRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
||||||
new GenreRepository(Configuration
|
new GenreRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
||||||
new YearRepository(Configuration
|
new YearRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
services.Add(new ServiceDescriptor(typeof(CoverArtRepository),
|
||||||
|
new CoverArtRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
||||||
new UserRepository(Configuration
|
new UserRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
||||||
@@ -144,20 +135,18 @@ namespace Icarus
|
|||||||
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
||||||
|
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
// The default HSTS value is 30 days.
|
||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// You may want to change this for production scenarios
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Icarus.Types
|
||||||
|
{
|
||||||
|
public enum CoverArtField
|
||||||
|
{
|
||||||
|
SongTitle = 0,
|
||||||
|
ImagePath
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Icarus.Types
|
||||||
|
{
|
||||||
|
public enum DirectoryType
|
||||||
|
{
|
||||||
|
Music = 0,
|
||||||
|
CoverArt
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,13 +9,14 @@
|
|||||||
"Auth0": {
|
"Auth0": {
|
||||||
"Domain": "[domain].auth0.com",
|
"Domain": "[domain].auth0.com",
|
||||||
"ApiIdentifier": "https://[identifier]/api",
|
"ApiIdentifier": "https://[identifier]/api",
|
||||||
"ClientId":"",
|
"ClientId": "",
|
||||||
"ClientSecret":""
|
"ClientSecret": ""
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=;Database=;Uid=;Pwd=;"
|
"DefaultConnection": "Server=;Database=;Uid=;Pwd=;"
|
||||||
},
|
},
|
||||||
"RootMusicPath": "/music/path/",
|
"RootMusicPath": "/music/path/",
|
||||||
"TemporaryMusicPath": "/music/temp/path/",
|
"TemporaryMusicPath": "/music/temp/path/",
|
||||||
"ArchivePath": "/archive/path/"
|
"ArchivePath": "/archive/path/",
|
||||||
|
"CoverArtPath": "/cover/art/path/"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -9,13 +9,14 @@
|
|||||||
"Auth0": {
|
"Auth0": {
|
||||||
"Domain": "[domain].auth0.com",
|
"Domain": "[domain].auth0.com",
|
||||||
"ApiIdentifier": "https://[identifier]/api",
|
"ApiIdentifier": "https://[identifier]/api",
|
||||||
"ClientId":"",
|
"ClientId": "",
|
||||||
"ClientSecret":""
|
"ClientSecret": ""
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=;Database=;Uid=;Pwd=;"
|
"DefaultConnection": "Server=;Database=;Uid=;Pwd=;"
|
||||||
},
|
},
|
||||||
"RootMusicPath": "/music/path/",
|
"RootMusicPath": "/music/path/",
|
||||||
"TemporaryMusicPath": "/music/temp/path/",
|
"TemporaryMusicPath": "/music/temp/path/",
|
||||||
"ArchivePath": "/archive/path/"
|
"ArchivePath": "/archive/path/",
|
||||||
|
"CoverArtPath": "/cover/art/path/"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user