mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fully migrate to system.text.json
This commit is contained in:
parent
7194dcb2c7
commit
e7bedd6a29
@ -19,27 +19,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Kyoo.Models;
|
||||
|
||||
public class Patch<T> : Dictionary<string, JToken>
|
||||
public class Patch<T> : Dictionary<string, JsonDocument>
|
||||
where T : class, IResource
|
||||
{
|
||||
public Guid? Id => this.GetValueOrDefault(nameof(IResource.Id))?.ToObject<Guid>();
|
||||
public Guid? Id => this.GetValueOrDefault(nameof(IResource.Id))?.Deserialize<Guid>();
|
||||
|
||||
public string? Slug => this.GetValueOrDefault(nameof(IResource.Slug))?.ToObject<string>();
|
||||
public string? Slug => this.GetValueOrDefault(nameof(IResource.Slug))?.Deserialize<string>();
|
||||
|
||||
public T Apply(T current)
|
||||
{
|
||||
foreach ((string property, JToken value) in this)
|
||||
foreach ((string property, JsonDocument value) in this)
|
||||
{
|
||||
PropertyInfo prop = typeof(T).GetProperty(
|
||||
property,
|
||||
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance
|
||||
)!;
|
||||
prop.SetValue(current, value.ToObject(prop.PropertyType));
|
||||
prop.SetValue(current, value.Deserialize(prop.PropertyType));
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Kyoo.Abstractions.Models.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Abstractions.Models
|
||||
{
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Abstractions.Models;
|
||||
|
||||
@ -36,21 +35,18 @@ public class JwtToken(string accessToken, string refreshToken, TimeSpan expireIn
|
||||
/// <summary>
|
||||
/// The type of this token (always a Bearer).
|
||||
/// </summary>
|
||||
[JsonProperty("token_type")]
|
||||
[JsonPropertyName("token_type")]
|
||||
public string TokenType => "Bearer";
|
||||
|
||||
/// <summary>
|
||||
/// The access token used to authorize requests.
|
||||
/// </summary>
|
||||
[JsonProperty("access_token")]
|
||||
[JsonPropertyName("access_token")]
|
||||
public string AccessToken { get; set; } = accessToken;
|
||||
|
||||
/// <summary>
|
||||
/// The refresh token used to retrieve a new access/refresh token when the access token has expired.
|
||||
/// </summary>
|
||||
[JsonProperty("refresh_token")]
|
||||
[JsonPropertyName("refresh_token")]
|
||||
public string RefreshToken { get; set; } = refreshToken;
|
||||
|
||||
@ -58,14 +54,12 @@ public class JwtToken(string accessToken, string refreshToken, TimeSpan expireIn
|
||||
/// When the access token will expire. After this time, the refresh token should be used to retrieve.
|
||||
/// a new token.cs
|
||||
/// </summary>
|
||||
[JsonProperty("expire_in")]
|
||||
[JsonPropertyName("expire_in")]
|
||||
public TimeSpan ExpireIn => ExpireAt.Subtract(DateTime.UtcNow);
|
||||
|
||||
/// <summary>
|
||||
/// The exact date at which the access token will expire.
|
||||
/// </summary>
|
||||
[JsonProperty("expire_at")]
|
||||
[JsonPropertyName("expire_at")]
|
||||
public DateTime ExpireAt { get; set; } = DateTime.UtcNow + expireIn;
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.12" />
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
||||
<ProjectReference Include="../Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -12,8 +12,6 @@
|
||||
<PackageReference Include="InterpolatedSql.Dapper" Version="2.1.0" />
|
||||
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.12" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.88.6" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
|
||||
</ItemGroup>
|
||||
|
@ -17,7 +17,7 @@
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using Npgsql;
|
||||
using NpgsqlTypes;
|
||||
using static Dapper.SqlMapper;
|
||||
@ -30,13 +30,13 @@ public class JsonTypeHandler<T> : TypeHandler<T>
|
||||
public override T? Parse(object value)
|
||||
{
|
||||
if (value is string str)
|
||||
return JsonConvert.DeserializeObject<T>(str);
|
||||
return JsonSerializer.Deserialize<T>(str);
|
||||
return default;
|
||||
}
|
||||
|
||||
public override void SetValue(IDbDataParameter parameter, T? value)
|
||||
{
|
||||
parameter.Value = JsonConvert.SerializeObject(value);
|
||||
parameter.Value = JsonSerializer.Serialize(value);
|
||||
((NpgsqlParameter)parameter).NpgsqlDbType = NpgsqlDbType.Jsonb;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user