diff --git a/Kyoo.CommonAPI/JsonSerializer.cs b/Kyoo.CommonAPI/JsonSerializer.cs index df200c26..71f9c6e6 100644 --- a/Kyoo.CommonAPI/JsonSerializer.cs +++ b/Kyoo.CommonAPI/JsonSerializer.cs @@ -1,3 +1,4 @@ +using System; using System.Reflection; using Kyoo.Models.Attributes; using Newtonsoft.Json; @@ -7,6 +8,8 @@ namespace Kyoo.Controllers { public class JsonPropertyIgnorer : CamelCasePropertyNamesContractResolver { + private int _depth = -1; + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); @@ -15,10 +18,12 @@ namespace Kyoo.Controllers if (relation != null) { if (relation.RelationID == null) - property.ShouldSerialize = x => member.GetValue(x) != null; + property.ShouldSerialize = x => _depth == 0 && member.GetValue(x) != null; else property.ShouldSerialize = x => { + if (_depth != 0) + return false; if (member.GetValue(x) != null) return true; return x.GetType().GetProperty(relation.RelationID)?.GetValue(x) != null; @@ -31,5 +36,13 @@ namespace Kyoo.Controllers property.ShouldDeserialize = _ => false; return property; } + + protected override JsonContract CreateContract(Type objectType) + { + JsonContract contract = base.CreateContract(objectType); + contract.OnSerializingCallbacks.Add((_, _) => _depth++); + contract.OnSerializedCallbacks.Add((_, _) => _depth--); + return contract; + } } } \ No newline at end of file diff --git a/Kyoo/Controllers/Repositories/EpisodeRepository.cs b/Kyoo/Controllers/Repositories/EpisodeRepository.cs index 816b2232..c4552d63 100644 --- a/Kyoo/Controllers/Repositories/EpisodeRepository.cs +++ b/Kyoo/Controllers/Repositories/EpisodeRepository.cs @@ -46,7 +46,7 @@ namespace Kyoo.Controllers public override Task Get(string slug) { - Match match = Regex.Match(slug, @"(?.*)-s(?\d*)-e(?\d*)"); + Match match = Regex.Match(slug, @"(?.*)-s(?\d*)e(?\d*)"); if (!match.Success) return _database.Episodes.FirstOrDefaultAsync(x => x.Show.Slug == slug);