Полностью переписанное api
All checks were successful
Release / pack-and-publish (release) Successful in 36s
All checks were successful
Release / pack-and-publish (release) Successful in 36s
This commit is contained in:
5
YandexMusic.API/Models/Account/YAuthEmpty.cs
Normal file
5
YandexMusic.API/Models/Account/YAuthEmpty.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace YandexMusic.API.Models.Account;
|
||||
|
||||
public class YAuthEmpty
|
||||
{
|
||||
}
|
||||
@@ -9,4 +9,4 @@ public class YAuthQR : YAuthBase
|
||||
|
||||
[JsonPropertyName("csrf_token")]
|
||||
public string CsrfToken { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,9 @@ public class YAuthToken
|
||||
|
||||
[JsonPropertyName("track_id")]
|
||||
public string TrackId { get; set; }
|
||||
|
||||
[JsonPropertyName("process_uuid")]
|
||||
public string ProcessUuid { get; set; }
|
||||
|
||||
public Dictionary<string, string> Cookie { get; set; } = new();
|
||||
}
|
||||
@@ -2,11 +2,15 @@ using YandexMusic.API.Common;
|
||||
|
||||
namespace YandexMusic.API.Models.Common;
|
||||
|
||||
/// <summary>Контекст выполнения, содержащий ссылки на API и хранилище.</summary>
|
||||
/// <summary>
|
||||
/// Контекст выполнения, содержащий ссылки на API и хранилище.
|
||||
/// Используется в моделях для вызова методов расширения.
|
||||
/// </summary>
|
||||
public class YExecutionContext
|
||||
{
|
||||
/// <summary>Экземпляр основного API.</summary>
|
||||
public YandexMusicApi API { get; internal set; } = null!;
|
||||
|
||||
/// <summary>Хранилище данных авторизации.</summary>
|
||||
public AuthStorage Storage { get; internal set; } = null!;
|
||||
}
|
||||
@@ -1,24 +1,34 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
|
||||
namespace YandexMusic.API.Models.Common;
|
||||
namespace YandexMusic.API.Converters;
|
||||
|
||||
/// <summary>Конвертер для внедрения контекста выполнения (API и хранилище) в модели.</summary>
|
||||
/// <summary>
|
||||
/// Конвертер для внедрения контекста выполнения (API и хранилище) в модели, наследуемые от YBaseModel.
|
||||
/// </summary>
|
||||
public class YExecutionContextConverter : JsonConverter<object>
|
||||
{
|
||||
private readonly YandexMusicApi _api;
|
||||
private readonly AuthStorage _storage;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализирует новый экземпляр конвертера.
|
||||
/// </summary>
|
||||
/// <param name="api">Экземпляр основного API.</param>
|
||||
/// <param name="storage">Хранилище авторизации.</param>
|
||||
public YExecutionContextConverter(YandexMusicApi api, AuthStorage storage)
|
||||
{
|
||||
_api = api;
|
||||
_storage = storage;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeof(YBaseModel).IsAssignableFrom(typeToConvert);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
// Убираем этот конвертер из опций, чтобы избежать рекурсии
|
||||
@@ -33,6 +43,7 @@ public class YExecutionContextConverter : JsonConverter<object>
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
|
||||
{
|
||||
var innerOptions = new JsonSerializerOptions(options);
|
||||
|
||||
Reference in New Issue
Block a user