fix Artist api
All checks were successful
Release / pack-and-publish (release) Successful in 40s

This commit is contained in:
FrigaT
2026-04-16 18:43:07 +03:00
parent ea9f392896
commit 5541d0ad27
3 changed files with 29 additions and 28 deletions

View File

@@ -1,4 +1,3 @@
using System.Text.Json.Serialization;
using YandexMusic.API.Models.Album; using YandexMusic.API.Models.Album;
using YandexMusic.API.Models.Common; using YandexMusic.API.Models.Common;
using YandexMusic.API.Models.Common.Cover; using YandexMusic.API.Models.Common.Cover;
@@ -11,7 +10,6 @@ public class YArtistBriefInfo
{ {
public YButton ActionButton { get; set; } public YButton ActionButton { get; set; }
public List<YAlbum> Albums { get; set; } public List<YAlbum> Albums { get; set; }
[JsonConverter(typeof(YCoverConverter))]
public List<YCover> AllCovers { get; set; } public List<YCover> AllCovers { get; set; }
public List<YAlbum> AlsoAlbums { get; set; } public List<YAlbum> AlsoAlbums { get; set; }
public YArtist Artist { get; set; } public YArtist Artist { get; set; }

View File

@@ -1,33 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace YandexMusic.API.Models.Common.Cover; namespace YandexMusic.API.Models.Common.Cover;
public class YCoverConverter : JsonConverter<YCover>
{
public override YCover? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject) return null;
using var doc = JsonDocument.ParseValue(ref reader);
var root = doc.RootElement;
var type = root.TryGetProperty("type", out var t) ? t.GetString() : null;
if (root.TryGetProperty("error", out _)) type = "error";
return type switch
{
"color" => JsonSerializer.Deserialize<YCoverColor>(root.GetRawText(), options),
"error" => JsonSerializer.Deserialize<YCoverError>(root.GetRawText(), options),
"from-artist-photos" or "from-album-cover" => JsonSerializer.Deserialize<YCoverImage>(root.GetRawText(), options),
"pic" => JsonSerializer.Deserialize<YCoverPic>(root.GetRawText(), options),
"mosaic" => JsonSerializer.Deserialize<YCoverMosaic>(root.GetRawText(), options),
_ => new YCover() { Type = YCoverType.Error }
};
}
public override void Write(Utf8JsonWriter writer, YCover value, JsonSerializerOptions options)
=> JsonSerializer.Serialize(writer, value, options);
}
[JsonConverter(typeof(YCoverConverter))] [JsonConverter(typeof(YCoverConverter))]
public class YCover public class YCover
{ {

View File

@@ -0,0 +1,29 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace YandexMusic.API.Models.Common.Cover;
public class YCoverConverter : JsonConverter<YCover>
{
public override YCover? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject) return null;
using var doc = JsonDocument.ParseValue(ref reader);
var root = doc.RootElement;
var type = root.TryGetProperty("type", out var t) ? t.GetString() : null;
if (root.TryGetProperty("error", out _)) type = "error";
return type switch
{
"color" => JsonSerializer.Deserialize<YCoverColor>(root.GetRawText(), options),
"error" => JsonSerializer.Deserialize<YCoverError>(root.GetRawText(), options),
"from-artist-photos" or "from-album-cover" => JsonSerializer.Deserialize<YCoverImage>(root.GetRawText(), options),
"pic" => JsonSerializer.Deserialize<YCoverPic>(root.GetRawText(), options),
"mosaic" => JsonSerializer.Deserialize<YCoverMosaic>(root.GetRawText(), options),
_ => new YCover() { Type = YCoverType.Error }
};
}
public override void Write(Utf8JsonWriter writer, YCover value, JsonSerializerOptions options)
=> JsonSerializer.Serialize(writer, value, options);
}