Remove custom serializer ignore

This commit is contained in:
Zoe Roux 2024-03-22 19:35:47 +01:00
parent 64031668c1
commit 9493531eaa
No known key found for this signature in database
15 changed files with 38 additions and 191 deletions

View File

@ -10,11 +10,9 @@
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="EntityFrameworkCore.Projectables" Version="4.1.4-prebeta" />
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sprache" Version="2.3.1" />
<PackageReference Include="System.ComponentModel.Composition" Version="7.0.0" />
</ItemGroup>

View File

@ -1,28 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
namespace Kyoo.Abstractions.Models.Attributes
{
/// <summary>
/// Remove a property from the deserialization pipeline. The user can't input value for this property.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class DeserializeIgnoreAttribute : Attribute { }
}

View File

@ -1,28 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
namespace Kyoo.Abstractions.Models.Attributes
{
/// <summary>
/// Remove an property from the serialization pipeline. It will simply be skipped.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class SerializeIgnoreAttribute : Attribute { }
}

View File

@ -19,10 +19,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -65,13 +64,13 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The list of movies contained in this collection.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Movie>? Movies { get; set; }
/// <summary>
/// The list of shows contained in this collection.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Show>? Shows { get; set; }
/// <inheritdoc />

View File

@ -20,9 +20,9 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using EntityFrameworkCore.Projectables;
using JetBrains.Annotations;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
@ -60,7 +60,6 @@ namespace Kyoo.Abstractions.Models
);
return GetSlug(ShowId.ToString(), SeasonNumber, EpisodeNumber, AbsoluteNumber);
}
[UsedImplicitly]
private set
{
Match match = Regex.Match(value, @"(?<show>.+)-s(?<season>\d+)e(?<episode>\d+)");
@ -90,7 +89,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The slug of the Show that contain this episode. If this is not set, this episode is ill-formed.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public string? ShowSlug { private get; set; }
/// <summary>
@ -249,7 +248,7 @@ namespace Kyoo.Abstractions.Models
|| (x.SeasonNumber == SeasonNumber && x.EpisodeNumber > EpisodeNumber)
);
[SerializeIgnore]
[JsonIgnore]
public ICollection<EpisodeWatchStatus>? Watched { get; set; }
/// <summary>

View File

@ -21,11 +21,11 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using EntityFrameworkCore.Projectables;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -119,11 +119,11 @@ namespace Kyoo.Abstractions.Models
/// <inheritdoc />
public Image? Logo { get; set; }
[SerializeIgnore]
[JsonIgnore]
[Column("air_date")]
public DateTime? StartAir => AirDate;
[SerializeIgnore]
[JsonIgnore]
[Column("air_date")]
public DateTime? EndAir => AirDate;
@ -138,7 +138,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The ID of the Studio that made this show.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public Guid? StudioId { get; set; }
/// <summary>
@ -155,7 +155,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The list of collections that contains this show.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Collection>? Collections { get; set; }
/// <summary>
@ -164,7 +164,7 @@ namespace Kyoo.Abstractions.Models
public VideoLinks Links =>
new() { Direct = $"/movie/{Slug}/direct", Hls = $"/movie/{Slug}/master.m3u8", };
[SerializeIgnore]
[JsonIgnore]
public ICollection<MovieWatchStatus>? Watched { get; set; }
/// <summary>

View File

@ -20,10 +20,9 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -62,7 +61,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The list of roles this person has played in. See <see cref="PeopleRole"/> for more information.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<PeopleRole>? Roles { get; set; }
public People() { }

View File

@ -20,9 +20,9 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using EntityFrameworkCore.Projectables;
using JetBrains.Annotations;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
@ -49,8 +49,6 @@ namespace Kyoo.Abstractions.Models
return $"{ShowId}-s{SeasonNumber}";
return $"{ShowSlug ?? Show?.Slug}-s{SeasonNumber}";
}
[UsedImplicitly]
[NotNull]
private set
{
Match match = Regex.Match(value, @"(?<show>.+)-s(?<season>\d+)");
@ -67,7 +65,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The slug of the Show that contain this episode. If this is not set, this season is ill-formed.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public string? ShowSlug { private get; set; }
/// <summary>
@ -124,7 +122,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The list of episodes that this season contains.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Episode>? Episodes { get; set; }
/// <summary>

View File

@ -21,11 +21,11 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using EntityFrameworkCore.Projectables;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -119,7 +119,7 @@ namespace Kyoo.Abstractions.Models
/// </summary>
public string? Trailer { get; set; }
[SerializeIgnore]
[JsonIgnore]
[Column("start_air")]
public DateTime? AirDate => StartAir;
@ -129,7 +129,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The ID of the Studio that made this show.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public Guid? StudioId { get; set; }
/// <summary>
@ -146,7 +146,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The different seasons in this show. If this is a movie, this list is always null or empty.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Season>? Seasons { get; set; }
/// <summary>
@ -154,13 +154,13 @@ namespace Kyoo.Abstractions.Models
/// If this is a movie, there will be a unique episode (with the seasonNumber and episodeNumber set to null).
/// Having an episode is necessary to store metadata and tracks.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Episode>? Episodes { get; set; }
/// <summary>
/// The list of collections that contains this show.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Collection>? Collections { get; set; }
/// <summary>
@ -213,7 +213,7 @@ namespace Kyoo.Abstractions.Models
private int _EpisodesCount => Episodes!.Count;
[SerializeIgnore]
[JsonIgnore]
public ICollection<ShowWatchStatus>? Watched { get; set; }
/// <summary>

View File

@ -19,10 +19,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -48,13 +47,13 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The list of shows that are made by this studio.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Show>? Shows { get; set; }
/// <summary>
/// The list of movies that are made by this studio.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public ICollection<Movie>? Movies { get; set; }
/// <inheritdoc />

View File

@ -19,10 +19,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils;
using Newtonsoft.Json;
namespace Kyoo.Abstractions.Models
{
@ -53,7 +52,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The user password (hashed, it can't be read like that). The hashing format is implementation defined.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public string? Password { get; set; }
/// <summary>

View File

@ -17,6 +17,7 @@
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Text.Json.Serialization;
using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models
@ -62,7 +63,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The user that started watching this episode.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public User User { get; set; }
/// <summary>
@ -74,7 +75,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The <see cref="Movie"/> started.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public Movie Movie { get; set; }
/// <inheritdoc/>
@ -119,7 +120,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The user that started watching this episode.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public User User { get; set; }
/// <summary>
@ -131,7 +132,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The <see cref="Episode"/> started.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public Episode Episode { get; set; }
/// <inheritdoc/>
@ -176,7 +177,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The user that started watching this episode.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public User User { get; set; }
/// <summary>
@ -188,7 +189,7 @@ namespace Kyoo.Abstractions.Models
/// <summary>
/// The <see cref="Show"/> started.
/// </summary>
[SerializeIgnore]
[JsonIgnore]
public Show Show { get; set; }
/// <inheritdoc/>

View File

@ -50,7 +50,6 @@ namespace Kyoo.Core.Api
options.SerializerSettings.ContractResolver = new JsonSerializerContract(
_httpContextAccessor
);
options.SerializerSettings.Converters.Add(new PeopleRoleConverter());
}
}
}

View File

@ -73,11 +73,6 @@ namespace Kyoo.Core.Api
return fields.Contains(member.Name);
};
}
if (member.GetCustomAttribute<SerializeIgnoreAttribute>() != null)
property.ShouldSerialize = _ => false;
if (member.GetCustomAttribute<DeserializeIgnoreAttribute>() != null)
property.ShouldDeserialize = _ => false;
return property;
}
@ -111,16 +106,9 @@ namespace Kyoo.Core.Api
return properties;
}
public class FixedValueProvider : IValueProvider
public class FixedValueProvider(object value) : IValueProvider
{
private readonly object _value;
public FixedValueProvider(object value)
{
_value = value;
}
public object GetValue(object target) => _value;
public object GetValue(object target) => value;
public void SetValue(object target, object? value) =>
throw new NotImplementedException();

View File

@ -1,76 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using Kyoo.Abstractions.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Kyoo.Core.Api
{
/// <summary>
/// A custom role's convertor to inline the person or the show depending on the value of
/// <see cref="PeopleRole.ForPeople"/>.
/// </summary>
public class PeopleRoleConverter : JsonConverter<PeopleRole>
{
/// <inheritdoc />
public override void WriteJson(
JsonWriter writer,
PeopleRole? value,
JsonSerializer serializer
)
{
// if (value == null)
// {
// writer.WriteNull();
// return;
// }
//
// ICollection<PeopleRole>? oldPeople = value.Show?.People;
// ICollection<PeopleRole>? oldRoles = value.People?.Roles;
// if (value.Show != null)
// value.Show.People = null;
// if (value.People != null)
// value.People.Roles = null;
//
// JObject obj = JObject.FromObject((value.ForPeople ? value.People : value.Show)!, serializer);
// obj.Add("role", value.Role);
// obj.Add("type", value.Type);
// obj.WriteTo(writer);
//
// if (value.Show != null)
// value.Show.People = oldPeople;
// if (value.People != null)
// value.People.Roles = oldRoles;
}
/// <inheritdoc />
public override PeopleRole ReadJson(
JsonReader reader,
Type objectType,
PeopleRole? existingValue,
bool hasExistingValue,
JsonSerializer serializer
)
{
throw new NotImplementedException();
}
}
}