Переделано воспроизведение аудио
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:
@@ -2,8 +2,6 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using YandexMusic.API.Common;
|
||||
@@ -23,7 +21,8 @@ internal abstract class YRequestBuilder<TParams>
|
||||
/// <summary>Шаблон пути (может содержать плейсхолдеры вида {id}).</summary>
|
||||
protected abstract string PathTemplate { get; }
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
/// <summary>Определяет, нужно ли добавлять заголовок Authorization для этого запроса.</summary>
|
||||
protected virtual bool ShouldAddAuthorization => true;
|
||||
|
||||
/// <summary>Основной экземпляр API.</summary>
|
||||
protected YandexMusicApi Api { get; }
|
||||
@@ -34,12 +33,6 @@ internal abstract class YRequestBuilder<TParams>
|
||||
protected YRequestBuilder(YandexMusicApi api)
|
||||
{
|
||||
Api = api;
|
||||
_jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
}
|
||||
|
||||
private string FullUrl => $"{BaseUrl.TrimEnd('/')}/{PathTemplate.TrimStart('/')}";
|
||||
@@ -66,7 +59,7 @@ internal abstract class YRequestBuilder<TParams>
|
||||
};
|
||||
msg.Headers.TryAddWithoutValidation(GetHeaderName(HttpRequestHeader.AcceptCharset), Encoding.UTF8.WebName);
|
||||
msg.Headers.TryAddWithoutValidation(GetHeaderName(HttpRequestHeader.AcceptEncoding), "gzip");
|
||||
if (!string.IsNullOrEmpty(Storage.Token))
|
||||
if (ShouldAddAuthorization && !string.IsNullOrEmpty(Storage.Token))
|
||||
msg.Headers.TryAddWithoutValidation(GetHeaderName(HttpRequestHeader.Authorization), $"OAuth {Storage.Token}");
|
||||
SetCustomHeaders(msg.Headers);
|
||||
return msg;
|
||||
@@ -120,8 +113,6 @@ internal abstract class YRequestBuilder<TParams>
|
||||
protected virtual HttpContent? GetContent(TParams parameters) => null;
|
||||
protected virtual void SetCustomHeaders(HttpRequestHeaders headers) { }
|
||||
|
||||
protected string SerializeJson(object data) => JsonSerializer.Serialize(data, _jsonOptions);
|
||||
|
||||
/// <summary>Выполняет запрос и возвращает десериализованный ответ.</summary>
|
||||
public async Task<HttpResponseMessage?> ExecuteRawAsync(TParams parameters)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user