Highlight active playlist. Various optimizations and fixes.
This commit is contained in:
@@ -1,14 +1,32 @@
|
||||
using Harmonia.Core.Data;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Harmonia.Core.Playlists;
|
||||
|
||||
public class PlaylistRepository : JsonFileRepository<Playlist>, IPlaylistRepository
|
||||
{
|
||||
private static readonly JsonSerializerOptions _options = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
IgnoreReadOnlyProperties = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||
};
|
||||
|
||||
protected override string DirectoryName => Path.Combine("Playlists");
|
||||
|
||||
public Playlist? GetPlaylist(PlaylistSong playlistSong)
|
||||
protected override async Task<Playlist> DeserializeAsync(Stream stream)
|
||||
{
|
||||
return Get().FirstOrDefault(playlist => playlist.Songs.Contains(playlistSong));
|
||||
PlaylistDto dto = await JsonSerializer.DeserializeAsync<PlaylistDto>(stream, _options) ?? new();
|
||||
|
||||
return dto.ToPlaylist();
|
||||
}
|
||||
|
||||
protected override Task<string> SerializeAsync(Playlist playlist)
|
||||
{
|
||||
PlaylistDto dto = PlaylistDto.FromPlaylist(playlist);
|
||||
|
||||
return Task.FromResult(JsonSerializer.Serialize(dto, _options));
|
||||
}
|
||||
|
||||
protected override string GetNewFileName()
|
||||
|
||||
Reference in New Issue
Block a user