Switch to file scopped namespaces

This commit is contained in:
Zoe Roux 2024-03-23 00:14:34 +01:00
parent 35e37bbe76
commit 18e301f26a
No known key found for this signature in database
99 changed files with 8936 additions and 9141 deletions

View File

@ -16,6 +16,8 @@ dotnet_diagnostic.IDE0055.severity = none
dotnet_diagnostic.IDE0058.severity = none dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE0130.severity = none dotnet_diagnostic.IDE0130.severity = none
# Convert to file-scoped namespace
csharp_style_namespace_declarations = file_scoped:warning
# Sort using and Import directives with System.* appearing first # Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true dotnet_sort_system_directives_first = true
csharp_using_directive_placement = outside_namespace:warning csharp_using_directive_placement = outside_namespace:warning

View File

@ -18,8 +18,8 @@
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// An interface to interact with the database. Every repository is mapped through here. /// An interface to interact with the database. Every repository is mapped through here.
/// </summary> /// </summary>
@ -78,4 +78,3 @@ namespace Kyoo.Abstractions.Controllers
/// </summary> /// </summary>
IRepository<User> Users { get; } IRepository<User> Users { get; }
} }
}

View File

@ -19,8 +19,8 @@
using Kyoo.Abstractions.Models.Permissions; using Kyoo.Abstractions.Models.Permissions;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// A service to validate permissions. /// A service to validate permissions.
/// </summary> /// </summary>
@ -44,4 +44,3 @@ namespace Kyoo.Abstractions.Controllers
/// <returns>An authorization filter used to validate the permission.</returns> /// <returns>An authorization filter used to validate the permission.</returns>
IFilterMetadata Create(PartialPermissionAttribute attribute); IFilterMetadata Create(PartialPermissionAttribute attribute);
} }
}

View File

@ -21,8 +21,8 @@ using System.Collections.Generic;
using Autofac; using Autofac;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// A common interface used to discord plugins /// A common interface used to discord plugins
/// </summary> /// </summary>
@ -63,4 +63,3 @@ namespace Kyoo.Abstractions.Controllers
// Skipped // Skipped
} }
} }
}

View File

@ -20,8 +20,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Exceptions;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// A manager to load plugins and retrieve information from them. /// A manager to load plugins and retrieve information from them.
/// </summary> /// </summary>
@ -67,4 +67,3 @@ namespace Kyoo.Abstractions.Controllers
/// </param> /// </param>
public void LoadPlugins(params Type[] plugins); public void LoadPlugins(params Type[] plugins);
} }
}

View File

@ -23,8 +23,8 @@ using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Exceptions;
using Kyoo.Abstractions.Models.Utils; using Kyoo.Abstractions.Models.Utils;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// A common repository for every resources. /// A common repository for every resources.
/// </summary> /// </summary>
@ -170,8 +170,7 @@ namespace Kyoo.Abstractions.Controllers
/// </summary> /// </summary>
/// <param name="obj">The resource newly created.</param> /// <param name="obj">The resource newly created.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
protected static Task OnResourceCreated(T obj) => protected static Task OnResourceCreated(T obj) => OnCreated?.Invoke(obj) ?? Task.CompletedTask;
OnCreated?.Invoke(obj) ?? Task.CompletedTask;
/// <summary> /// <summary>
/// Edit a resource and replace every property /// Edit a resource and replace every property
@ -203,8 +202,7 @@ namespace Kyoo.Abstractions.Controllers
/// </summary> /// </summary>
/// <param name="obj">The resource newly edited.</param> /// <param name="obj">The resource newly edited.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
protected static Task OnResourceEdited(T obj) => protected static Task OnResourceEdited(T obj) => OnEdited?.Invoke(obj) ?? Task.CompletedTask;
OnEdited?.Invoke(obj) ?? Task.CompletedTask;
/// <summary> /// <summary>
/// Delete a resource by it's ID /// Delete a resource by it's ID
@ -247,8 +245,7 @@ namespace Kyoo.Abstractions.Controllers
/// </summary> /// </summary>
/// <param name="obj">The resource newly deleted.</param> /// <param name="obj">The resource newly deleted.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
protected static Task OnResourceDeleted(T obj) => protected static Task OnResourceDeleted(T obj) => OnDeleted?.Invoke(obj) ?? Task.CompletedTask;
OnDeleted?.Invoke(obj) ?? Task.CompletedTask;
} }
/// <summary> /// <summary>
@ -268,4 +265,3 @@ namespace Kyoo.Abstractions.Controllers
Task<User> AddExternalToken(Guid userId, string provider, ExternalToken token); Task<User> AddExternalToken(Guid userId, string provider, ExternalToken token);
Task<User> DeleteExternalToken(Guid userId, string provider); Task<User> DeleteExternalToken(Guid userId, string provider);
} }
}

View File

@ -21,8 +21,8 @@ using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// Download images and retrieve the path of those images for a resource. /// Download images and retrieve the path of those images for a resource.
/// </summary> /// </summary>
@ -76,4 +76,3 @@ namespace Kyoo.Abstractions.Controllers
/// <param name="image">The byte stream of the image. Null to delete the image.</param> /// <param name="image">The byte stream of the image. Null to delete the image.</param>
Task SetUserImage(Guid userId, Stream? image); Task SetUserImage(Guid userId, Stream? image);
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// A list of constant priorities used for <see cref="IStartupAction"/>'s <see cref="IStartupAction.Priority"/>. /// A list of constant priorities used for <see cref="IStartupAction"/>'s <see cref="IStartupAction.Priority"/>.
/// It also contains helper methods for creating new <see cref="StartupAction"/>. /// It also contains helper methods for creating new <see cref="StartupAction"/>.
@ -102,10 +102,7 @@ namespace Kyoo.Abstractions.Controllers
/// <typeparam name="T2">A second dependency that this action will use.</typeparam> /// <typeparam name="T2">A second dependency that this action will use.</typeparam>
/// <typeparam name="T3">A third dependency that this action will use.</typeparam> /// <typeparam name="T3">A third dependency that this action will use.</typeparam>
/// <returns>A new <see cref="StartupAction"/></returns> /// <returns>A new <see cref="StartupAction"/></returns>
public static StartupAction<T, T2, T3> New<T, T2, T3>( public static StartupAction<T, T2, T3> New<T, T2, T3>(Action<T, T2, T3> action, int priority)
Action<T, T2, T3> action,
int priority
)
where T : notnull where T : notnull
where T2 : notnull where T2 : notnull
where T3 : notnull => new(action, priority); where T3 : notnull => new(action, priority);
@ -271,4 +268,3 @@ namespace Kyoo.Abstractions.Controllers
/// <param name="provider">The service provider containing all services can be used.</param> /// <param name="provider">The service provider containing all services can be used.</param>
void Run(IServiceProvider provider); void Run(IServiceProvider provider);
} }
}

View File

@ -23,8 +23,8 @@ using System.Security.Claims;
using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Exceptions;
using Kyoo.Authentication.Models; using Kyoo.Authentication.Models;
namespace Kyoo.Authentication namespace Kyoo.Authentication;
{
/// <summary> /// <summary>
/// Extension methods. /// Extension methods.
/// </summary> /// </summary>
@ -62,4 +62,3 @@ namespace Kyoo.Authentication
return ret.Value; return ret.Value;
} }
} }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Models.Attributes namespace Kyoo.Abstractions.Models.Attributes;
{
/// <summary> /// <summary>
/// An attribute to specify on apis to specify it's documentation's name and category. /// An attribute to specify on apis to specify it's documentation's name and category.
/// If this is applied on a method, the specified method will be exploded from the controller's page and be /// If this is applied on a method, the specified method will be exploded from the controller's page and be
@ -49,4 +49,3 @@ namespace Kyoo.Abstractions.Models.Attributes
Name = name; Name = name;
} }
} }
}

View File

@ -18,11 +18,10 @@
using System; using System;
namespace Kyoo.Abstractions.Models.Attributes namespace Kyoo.Abstractions.Models.Attributes;
{
/// <summary> /// <summary>
/// An attribute to inform that the property is computed automatically and can't be assigned manually. /// An attribute to inform that the property is computed automatically and can't be assigned manually.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class ComputedAttribute : NotMergeableAttribute { } public class ComputedAttribute : NotMergeableAttribute { }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Models.Attributes namespace Kyoo.Abstractions.Models.Attributes;
{
/// <summary> /// <summary>
/// The targeted relation can be loaded. /// The targeted relation can be loaded.
/// </summary> /// </summary>
@ -51,4 +51,3 @@ namespace Kyoo.Abstractions.Models.Attributes
RelationID = relationID; RelationID = relationID;
} }
} }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Models.Attributes namespace Kyoo.Abstractions.Models.Attributes;
{
/// <summary> /// <summary>
/// Specify that a property can't be merged. /// Specify that a property can't be merged.
/// </summary> /// </summary>
@ -37,4 +37,3 @@ namespace Kyoo.Abstractions.Models.Attributes
/// <param name="merged">The object that has been merged with this.</param> /// <param name="merged">The object that has been merged with this.</param>
void OnMerge(object merged); void OnMerge(object merged);
} }
}

View File

@ -21,8 +21,8 @@ using Kyoo.Abstractions.Controllers;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Abstractions.Models.Permissions namespace Kyoo.Abstractions.Models.Permissions;
{
/// <summary> /// <summary>
/// Specify one part of a permissions needed for the API (the kind or the type). /// Specify one part of a permissions needed for the API (the kind or the type).
/// </summary> /// </summary>
@ -85,4 +85,3 @@ namespace Kyoo.Abstractions.Models.Permissions
/// <inheritdoc /> /// <inheritdoc />
public bool IsReusable => true; public bool IsReusable => true;
} }
}

View File

@ -21,8 +21,8 @@ using Kyoo.Abstractions.Controllers;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Abstractions.Models.Permissions namespace Kyoo.Abstractions.Models.Permissions;
{
/// <summary> /// <summary>
/// The kind of permission needed. /// The kind of permission needed.
/// </summary> /// </summary>
@ -134,4 +134,3 @@ namespace Kyoo.Abstractions.Models.Permissions
return Type; return Type;
} }
} }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Models.Permissions namespace Kyoo.Abstractions.Models.Permissions;
{
/// <summary> /// <summary>
/// The annotated route can only be accessed by a logged in user. /// The annotated route can only be accessed by a logged in user.
/// </summary> /// </summary>
@ -28,4 +28,3 @@ namespace Kyoo.Abstractions.Models.Permissions
{ {
// TODO: Implement a Filter Attribute to make this work. For now, this attribute is only useful as documentation. // TODO: Implement a Filter Attribute to make this work. For now, this attribute is only useful as documentation.
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Kyoo.Abstractions.Models.Exceptions namespace Kyoo.Abstractions.Models.Exceptions;
{
/// <summary> /// <summary>
/// An exception raised when an item already exists in the database. /// An exception raised when an item already exists in the database.
/// </summary> /// </summary>
@ -50,4 +50,3 @@ namespace Kyoo.Abstractions.Models.Exceptions
protected DuplicatedItemException(SerializationInfo info, StreamingContext context) protected DuplicatedItemException(SerializationInfo info, StreamingContext context)
: base(info, context) { } : base(info, context) { }
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Kyoo.Abstractions.Models.Exceptions namespace Kyoo.Abstractions.Models.Exceptions;
{
/// <summary> /// <summary>
/// An exception raised when an item could not be found. /// An exception raised when an item could not be found.
/// </summary> /// </summary>
@ -48,4 +48,3 @@ namespace Kyoo.Abstractions.Models.Exceptions
protected ItemNotFoundException(SerializationInfo info, StreamingContext context) protected ItemNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context) { } : base(info, context) { }
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Kyoo.Abstractions.Models.Exceptions namespace Kyoo.Abstractions.Models.Exceptions;
{
[Serializable] [Serializable]
public class UnauthorizedException : Exception public class UnauthorizedException : Exception
{ {
@ -33,4 +33,3 @@ namespace Kyoo.Abstractions.Models.Exceptions
protected UnauthorizedException(SerializationInfo info, StreamingContext context) protected UnauthorizedException(SerializationInfo info, StreamingContext context)
: base(info, context) { } : base(info, context) { }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A genre that allow one to specify categories for shows. /// A genre that allow one to specify categories for shows.
/// </summary> /// </summary>
@ -42,4 +42,3 @@ namespace Kyoo.Abstractions.Models
War, War,
Western, Western,
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// ID and link of an item on an external provider. /// ID and link of an item on an external provider.
/// </summary> /// </summary>
@ -33,4 +33,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public string? Link { get; set; } public string? Link { get; set; }
} }
}

View File

@ -20,8 +20,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A page of resource that contains information about the pagination of resources. /// A page of resource that contains information about the pagination of resources.
/// </summary> /// </summary>
@ -67,13 +67,7 @@ namespace Kyoo.Abstractions.Models
/// <param name="previous">The link of the previous page.</param> /// <param name="previous">The link of the previous page.</param>
/// <param name="next">The link of the next page.</param> /// <param name="next">The link of the next page.</param>
/// <param name="first">The link of the first page.</param> /// <param name="first">The link of the first page.</param>
public Page( public Page(ICollection<T> items, string @this, string? previous, string? next, string first)
ICollection<T> items,
string @this,
string? previous,
string? next,
string first
)
{ {
Items = items; Items = items;
This = @this; This = @this;
@ -109,4 +103,3 @@ namespace Kyoo.Abstractions.Models
First = url + query.ToQueryString(); First = url + query.ToQueryString();
} }
} }
}

View File

@ -23,8 +23,8 @@ using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A class representing collections of <see cref="Show"/>. /// A class representing collections of <see cref="Show"/>.
/// </summary> /// </summary>
@ -88,4 +88,3 @@ namespace Kyoo.Abstractions.Models
} }
} }
} }
}

View File

@ -26,8 +26,8 @@ using EntityFrameworkCore.Projectables;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A class to represent a single show's episode. /// A class to represent a single show's episode.
/// </summary> /// </summary>
@ -52,12 +52,7 @@ namespace Kyoo.Abstractions.Models
get get
{ {
if (ShowSlug != null || Show?.Slug != null) if (ShowSlug != null || Show?.Slug != null)
return GetSlug( return GetSlug(ShowSlug ?? Show!.Slug, SeasonNumber, EpisodeNumber, AbsoluteNumber);
ShowSlug ?? Show!.Slug,
SeasonNumber,
EpisodeNumber,
AbsoluteNumber
);
return GetSlug(ShowId.ToString(), SeasonNumber, EpisodeNumber, AbsoluteNumber); return GetSlug(ShowId.ToString(), SeasonNumber, EpisodeNumber, AbsoluteNumber);
} }
private set private set
@ -302,4 +297,3 @@ namespace Kyoo.Abstractions.Models
}; };
} }
} }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// An interface applied to resources. /// An interface applied to resources.
/// </summary> /// </summary>
@ -30,4 +30,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public DateTime AddedDate { get; set; } public DateTime AddedDate { get; set; }
} }
}

View File

@ -18,8 +18,8 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// An interface applied to resources containing external metadata. /// An interface applied to resources containing external metadata.
/// </summary> /// </summary>
@ -30,4 +30,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public Dictionary<string, MetadataId> ExternalId { get; set; } public Dictionary<string, MetadataId> ExternalId { get; set; }
} }
}

View File

@ -20,8 +20,8 @@ using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// An interface to represent a resource that can be retrieved from the database. /// An interface to represent a resource that can be retrieved from the database.
/// </summary> /// </summary>
@ -47,4 +47,3 @@ namespace Kyoo.Abstractions.Models
[MaxLength(256)] [MaxLength(256)]
public string Slug { get; } public string Slug { get; }
} }
}

View File

@ -23,8 +23,8 @@ using System.Globalization;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// An interface representing items that contains images (like posters, thumbnails, logo, banners...) /// An interface representing items that contains images (like posters, thumbnails, logo, banners...)
/// </summary> /// </summary>
@ -94,10 +94,7 @@ namespace Kyoo.Abstractions.Models
} }
/// <inheritdoc /> /// <inheritdoc />
public override bool CanConvertTo( public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
ITypeDescriptorContext? context,
Type? destinationType
)
{ {
return false; return false;
} }
@ -124,4 +121,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
High, High,
} }
}

View File

@ -27,8 +27,8 @@ using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A series or a movie. /// A series or a movie.
/// </summary> /// </summary>
@ -186,4 +186,3 @@ namespace Kyoo.Abstractions.Models
} }
} }
} }
}

View File

@ -26,8 +26,8 @@ using EntityFrameworkCore.Projectables;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A season of a <see cref="Show"/>. /// A season of a <see cref="Show"/>.
/// </summary> /// </summary>
@ -146,4 +146,3 @@ namespace Kyoo.Abstractions.Models
private int _EpisodesCount => Episodes!.Count; private int _EpisodesCount => Episodes!.Count;
} }
}

View File

@ -27,8 +27,8 @@ using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A series or a movie. /// A series or a movie.
/// </summary> /// </summary>
@ -277,4 +277,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
Planned Planned
} }
}

View File

@ -23,8 +23,8 @@ using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A studio that make shows. /// A studio that make shows.
/// </summary> /// </summary>
@ -78,4 +78,3 @@ namespace Kyoo.Abstractions.Models
} }
} }
} }
}

View File

@ -23,8 +23,8 @@ using System.Text.Json.Serialization;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// A single user of the app. /// A single user of the app.
/// </summary> /// </summary>
@ -114,4 +114,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public JwtToken Token { get; set; } public JwtToken Token { get; set; }
} }
}

View File

@ -20,8 +20,8 @@ using System;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// Has the user started watching, is it planned? /// Has the user started watching, is it planned?
/// </summary> /// </summary>
@ -230,4 +230,3 @@ namespace Kyoo.Abstractions.Models
/// </remarks> /// </remarks>
public int? WatchedPercent { get; set; } public int? WatchedPercent { get; set; }
} }
}

View File

@ -18,8 +18,8 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// Results of a search request. /// Results of a search request.
/// </summary> /// </summary>
@ -51,4 +51,3 @@ namespace Kyoo.Abstractions.Models
public ICollection<T> Items { get; set; } public ICollection<T> Items { get; set; }
} }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Authentication.Models namespace Kyoo.Authentication.Models;
{
/// <summary> /// <summary>
/// List of well known claims of kyoo /// List of well known claims of kyoo
/// </summary> /// </summary>
@ -53,4 +53,3 @@ namespace Kyoo.Authentication.Models
/// </summary> /// </summary>
public static string Guid => "guid"; public static string Guid => "guid";
} }
}

View File

@ -18,8 +18,8 @@
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models.Utils namespace Kyoo.Abstractions.Models.Utils;
{
/// <summary> /// <summary>
/// A class containing constant numbers. /// A class containing constant numbers.
/// </summary> /// </summary>
@ -57,4 +57,3 @@ namespace Kyoo.Abstractions.Models.Utils
/// </summary> /// </summary>
public const string AdminGroup = "4:Admin"; public const string AdminGroup = "4:Admin";
} }
}

View File

@ -24,8 +24,8 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
namespace Kyoo.Abstractions.Models.Utils namespace Kyoo.Abstractions.Models.Utils;
{
/// <summary> /// <summary>
/// A class that represent a resource. It is made to be used as a parameter in a query and not used somewhere else /// A class that represent a resource. It is made to be used as a parameter in a query and not used somewhere else
/// on the application. /// on the application.
@ -162,9 +162,7 @@ namespace Kyoo.Abstractions.Models.Utils
public Filter<T> IsSame<T>() public Filter<T> IsSame<T>()
where T : IResource where T : IResource
{ {
return _id.HasValue return _id.HasValue ? new Filter<T>.Eq("Id", _id.Value) : new Filter<T>.Eq("Slug", _slug!);
? new Filter<T>.Eq("Id", _id.Value)
: new Filter<T>.Eq("Slug", _slug!);
} }
public bool Is(Guid uid) public bool Is(Guid uid)
@ -245,4 +243,3 @@ namespace Kyoo.Abstractions.Models.Utils
} }
} }
} }
}

View File

@ -18,8 +18,8 @@
using System; using System;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// Information about the pagination. How many items should be displayed and where to start. /// Information about the pagination. How many items should be displayed and where to start.
/// </summary> /// </summary>
@ -70,4 +70,3 @@ namespace Kyoo.Abstractions.Controllers
/// <returns>A new <see cref="Pagination"/> instance</returns> /// <returns>A new <see cref="Pagination"/> instance</returns>
public static implicit operator Pagination(int limit) => new(limit); public static implicit operator Pagination(int limit) => new(limit);
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using System.Linq; using System.Linq;
namespace Kyoo.Abstractions.Models.Utils namespace Kyoo.Abstractions.Models.Utils;
{
/// <summary> /// <summary>
/// The list of errors that where made in the request. /// The list of errors that where made in the request.
/// </summary> /// </summary>
@ -50,11 +50,7 @@ namespace Kyoo.Abstractions.Models.Utils
public RequestError(string[] errors) public RequestError(string[] errors)
{ {
if (errors == null || !errors.Any()) if (errors == null || !errors.Any())
throw new ArgumentException( throw new ArgumentException("Errors must be non null and not empty", nameof(errors));
"Errors must be non null and not empty",
nameof(errors)
);
Errors = errors; Errors = errors;
} }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
/// <summary> /// <summary>
/// Information about the pagination. How many items should be displayed and where to start. /// Information about the pagination. How many items should be displayed and where to start.
/// </summary> /// </summary>
@ -33,4 +33,3 @@ namespace Kyoo.Abstractions.Controllers
/// </summary> /// </summary>
public int? Skip { get; set; } public int? Skip { get; set; }
} }
}

View File

@ -25,8 +25,8 @@ using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers;
{
public record Sort; public record Sort;
/// <summary> /// <summary>
@ -117,8 +117,7 @@ namespace Kyoo.Abstractions.Controllers
) )
}; };
Type[] types = Type[] types = typeof(T).GetCustomAttribute<OneOfAttribute>()?.Types ?? new[] { typeof(T) };
typeof(T).GetCustomAttribute<OneOfAttribute>()?.Types ?? new[] { typeof(T) };
PropertyInfo? property = types PropertyInfo? property = types
.Select(x => .Select(x =>
x.GetProperty( x.GetProperty(
@ -132,4 +131,3 @@ namespace Kyoo.Abstractions.Controllers
return new By(property.Name, desendant); return new By(property.Name, desendant);
} }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Abstractions.Models namespace Kyoo.Abstractions.Models;
{
/// <summary> /// <summary>
/// The links to see a movie or an episode. /// The links to see a movie or an episode.
/// </summary> /// </summary>
@ -33,4 +33,3 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public string Hls { get; set; } public string Hls { get; set; }
} }
}

View File

@ -21,8 +21,8 @@ using Autofac.Builder;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Utils; using Kyoo.Utils;
namespace Kyoo.Abstractions namespace Kyoo.Abstractions;
{
/// <summary> /// <summary>
/// A static class with helper functions to setup external modules /// A static class with helper functions to setup external modules
/// </summary> /// </summary>
@ -73,4 +73,3 @@ namespace Kyoo.Abstractions
return builder.RegisterRepository<T2>().AsSelf().As<T>(); return builder.RegisterRepository<T2>().AsSelf().As<T>();
} }
} }
}

View File

@ -19,8 +19,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Kyoo.Utils namespace Kyoo.Utils;
{
/// <summary> /// <summary>
/// A set of extensions class for enumerable. /// A set of extensions class for enumerable.
/// </summary> /// </summary>
@ -68,4 +68,3 @@ namespace Kyoo.Utils
action(i); action(i);
} }
} }
}

View File

@ -22,8 +22,8 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Utils namespace Kyoo.Utils;
{
/// <summary> /// <summary>
/// A class containing helper methods to merge objects. /// A class containing helper methods to merge objects.
/// </summary> /// </summary>
@ -131,4 +131,3 @@ namespace Kyoo.Utils
return first; return first;
} }
} }
}

View File

@ -25,8 +25,8 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Kyoo.Utils namespace Kyoo.Utils;
{
/// <summary> /// <summary>
/// A set of utility functions that can be used everywhere. /// A set of utility functions that can be used everywhere.
/// </summary> /// </summary>
@ -204,9 +204,7 @@ namespace Kyoo.Utils
: type.GetInheritanceTree(); : type.GetInheritanceTree();
return types return types
.Prepend(type) .Prepend(type)
.FirstOrDefault(x => .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == genericType);
x.IsGenericType && x.GetGenericTypeDefinition() == genericType
);
} }
/// <summary> /// <summary>
@ -362,4 +360,3 @@ namespace Kyoo.Utils
return "?" + string.Join('&', query.Select(x => $"{x.Key}={x.Value}")); return "?" + string.Join('&', query.Select(x => $"{x.Key}={x.Value}"));
} }
} }
}

View File

@ -32,8 +32,8 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
namespace Kyoo.Authentication namespace Kyoo.Authentication;
{
/// <summary> /// <summary>
/// A module that enable OpenID authentication for Kyoo. /// A module that enable OpenID authentication for Kyoo.
/// </summary> /// </summary>
@ -78,10 +78,7 @@ namespace Kyoo.Authentication
NewUser = _configuration NewUser = _configuration
.GetValue("DEFAULT_PERMISSIONS", "overall.read,overall.play")! .GetValue("DEFAULT_PERMISSIONS", "overall.read,overall.play")!
.Split(','), .Split(','),
RequireVerification = _configuration.GetValue( RequireVerification = _configuration.GetValue("REQUIRE_ACCOUNT_VERIFICATION", true),
"REQUIRE_ACCOUNT_VERIFICATION",
true
),
PublicUrl = PublicUrl =
_configuration.GetValue<string?>("PUBLIC_URL") ?? "http://localhost:8901", _configuration.GetValue<string?>("PUBLIC_URL") ?? "http://localhost:8901",
ApiKeys = _configuration.GetValue("KYOO_APIKEYS", string.Empty)!.Split(','), ApiKeys = _configuration.GetValue("KYOO_APIKEYS", string.Empty)!.Split(','),
@ -154,10 +151,7 @@ namespace Kyoo.Authentication
{ {
string prefix = "Bearer "; string prefix = "Bearer ";
if ( if (
ctx.Request.Headers.TryGetValue( ctx.Request.Headers.TryGetValue("Authorization", out StringValues val)
"Authorization",
out StringValues val
)
&& val.ToString() is string auth && val.ToString() is string auth
&& auth.StartsWith(prefix) && auth.StartsWith(prefix)
) )
@ -186,4 +180,3 @@ namespace Kyoo.Authentication
SA.New<IApplicationBuilder>(app => app.UseAuthentication(), SA.Authentication), SA.New<IApplicationBuilder>(app => app.UseAuthentication(), SA.Authentication),
}; };
} }
}

View File

@ -21,8 +21,8 @@ using System.Threading.Tasks;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
namespace Kyoo.Authentication namespace Kyoo.Authentication;
{
/// <summary> /// <summary>
/// The service that controls jwt creation and validation. /// The service that controls jwt creation and validation.
/// </summary> /// </summary>
@ -51,4 +51,3 @@ namespace Kyoo.Authentication
/// <returns>The id of the token's user.</returns> /// <returns>The id of the token's user.</returns>
Guid GetRefreshTokenUserID(string refreshToken); Guid GetRefreshTokenUserID(string refreshToken);
} }
}

View File

@ -32,8 +32,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
namespace Kyoo.Authentication namespace Kyoo.Authentication;
{
/// <summary> /// <summary>
/// A permission validator to validate permission with user Permission array /// A permission validator to validate permission with user Permission array
/// or the default array from the configurations if the user is not logged. /// or the default array from the configurations if the user is not logged.
@ -126,11 +126,7 @@ namespace Kyoo.Authentication
/// <param name="partialInfo">The partial permission to validate.</param> /// <param name="partialInfo">The partial permission to validate.</param>
/// <param name="group">The group of the permission.</param> /// <param name="group">The group of the permission.</param>
/// <param name="options">The option containing default values.</param> /// <param name="options">The option containing default values.</param>
public PermissionValidatorFilter( public PermissionValidatorFilter(object partialInfo, Group? group, PermissionOption options)
object partialInfo,
Group? group,
PermissionOption options
)
{ {
switch (partialInfo) switch (partialInfo)
{ {
@ -159,11 +155,7 @@ namespace Kyoo.Authentication
if (permission == null || kind == null) if (permission == null || kind == null)
{ {
if ( if (context.HttpContext.Items["PermissionGroup"] is Group group and not Group.None)
context.HttpContext.Items["PermissionGroup"]
is Group group
and not Group.None
)
_group = group; _group = group;
else if (_group == Group.None) else if (_group == Group.None)
_group = Group.Overall; _group = Group.Overall;
@ -226,10 +218,7 @@ namespace Kyoo.Authentication
} }
} }
else if (res.Failure != null) else if (res.Failure != null)
context.Result = _ErrorResult( context.Result = _ErrorResult(res.Failure.Message, StatusCodes.Status403Forbidden);
res.Failure.Message,
StatusCodes.Status403Forbidden
);
else else
context.Result = _ErrorResult( context.Result = _ErrorResult(
"Authentication panic", "Authentication panic",
@ -277,9 +266,7 @@ namespace Kyoo.Authentication
); );
// Change the failure message to make the API nice to use. // Change the failure message to make the API nice to use.
if (ret.Failure != null) if (ret.Failure != null)
return AuthenticateResult.Fail( return AuthenticateResult.Fail("Invalid JWT token. The token may have expired.");
"Invalid JWT token. The token may have expired."
);
return ret; return ret;
} }
} }
@ -295,4 +282,3 @@ namespace Kyoo.Authentication
return new ObjectResult(new RequestError(error)) { StatusCode = code }; return new ObjectResult(new RequestError(error)) { StatusCode = code };
} }
} }
}

View File

@ -27,8 +27,8 @@ using Kyoo.Abstractions.Models;
using Kyoo.Authentication.Models; using Kyoo.Authentication.Models;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
namespace Kyoo.Authentication namespace Kyoo.Authentication;
{
/// <summary> /// <summary>
/// The service that controls jwt creation and validation. /// The service that controls jwt creation and validation.
/// </summary> /// </summary>
@ -132,4 +132,3 @@ namespace Kyoo.Authentication
throw new SecurityTokenException("Token not associated to any user."); throw new SecurityTokenException("Token not associated to any user.");
} }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Authentication.Models.DTO namespace Kyoo.Authentication.Models.DTO;
{
/// <summary> /// <summary>
/// A model only used on login requests. /// A model only used on login requests.
/// </summary> /// </summary>
@ -44,4 +44,3 @@ namespace Kyoo.Authentication.Models.DTO
Password = password; Password = password;
} }
} }
}

View File

@ -21,8 +21,8 @@ using Kyoo.Abstractions.Models;
using Kyoo.Utils; using Kyoo.Utils;
using BCryptNet = BCrypt.Net.BCrypt; using BCryptNet = BCrypt.Net.BCrypt;
namespace Kyoo.Authentication.Models.DTO namespace Kyoo.Authentication.Models.DTO;
{
/// <summary> /// <summary>
/// A model only used on register requests. /// A model only used on register requests.
/// </summary> /// </summary>
@ -74,4 +74,3 @@ namespace Kyoo.Authentication.Models.DTO
}; };
} }
} }
}

View File

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Authentication.Models namespace Kyoo.Authentication.Models;
{
/// <summary> /// <summary>
/// The main authentication options. /// The main authentication options.
/// </summary> /// </summary>
@ -43,4 +43,3 @@ namespace Kyoo.Authentication.Models
/// </summary> /// </summary>
public PermissionOption Permissions { get; set; } = new(); public PermissionOption Permissions { get; set; } = new();
} }
}

View File

@ -35,8 +35,8 @@ using Microsoft.IdentityModel.Tokens;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
using BCryptNet = BCrypt.Net.BCrypt; using BCryptNet = BCrypt.Net.BCrypt;
namespace Kyoo.Authentication.Views namespace Kyoo.Authentication.Views;
{
/// <summary> /// <summary>
/// Sign in, Sign up or refresh tokens. /// Sign in, Sign up or refresh tokens.
/// </summary> /// </summary>
@ -127,12 +127,7 @@ namespace Kyoo.Authentication.Views
/// <response code="403">The provider gave an error.</response> /// <response code="403">The provider gave an error.</response>
[HttpGet("logged/{provider}")] [HttpGet("logged/{provider}")]
[ProducesResponseType(StatusCodes.Status302Found)] [ProducesResponseType(StatusCodes.Status302Found)]
public ActionResult OauthCodeRedirect( public ActionResult OauthCodeRedirect(string provider, string code, string state, string? error)
string provider,
string code,
string state,
string? error
)
{ {
return Redirect( return Redirect(
_BuildUrl( _BuildUrl(
@ -495,4 +490,3 @@ namespace Kyoo.Authentication.Views
return NoContent(); return NoContent();
} }
} }
}

View File

@ -20,8 +20,8 @@ using Kyoo.Abstractions.Models.Utils;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// The route constraint that goes with the <see cref="Identifier"/>. /// The route constraint that goes with the <see cref="Identifier"/>.
/// </summary> /// </summary>
@ -39,4 +39,3 @@ namespace Kyoo.Core.Controllers
return values.ContainsKey(routeKey); return values.ContainsKey(routeKey);
} }
} }
}

View File

@ -20,8 +20,8 @@ using System.Linq;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// An class to interact with the database. Every repository is mapped through here. /// An class to interact with the database. Every repository is mapped through here.
/// </summary> /// </summary>
@ -103,4 +103,3 @@ namespace Kyoo.Core.Controllers
return (IRepository<T>)_repositories.First(x => x.RepositoryType == typeof(T)); return (IRepository<T>)_repositories.First(x => x.RepositoryType == typeof(T));
} }
} }
}

View File

@ -26,8 +26,8 @@ using Kyoo.Abstractions.Models.Utils;
using Kyoo.Postgresql; using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle collections /// A local repository to handle collections
/// </summary> /// </summary>
@ -100,4 +100,3 @@ namespace Kyoo.Core.Controllers
await base.Delete(obj); await base.Delete(obj);
} }
} }
}

View File

@ -27,8 +27,8 @@ using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle episodes. /// A local repository to handle episodes.
/// </summary> /// </summary>
@ -47,8 +47,7 @@ namespace Kyoo.Core.Controllers
IRepository<Show>.OnEdited += async (show) => IRepository<Show>.OnEdited += async (show) =>
{ {
await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope(); await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope();
DatabaseContext database = DatabaseContext database = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
scope.ServiceProvider.GetRequiredService<DatabaseContext>();
List<Episode> episodes = await database List<Episode> episodes = await database
.Episodes.AsTracking() .Episodes.AsTracking()
.Where(x => x.ShowId == show.Id) .Where(x => x.ShowId == show.Id)
@ -153,4 +152,3 @@ namespace Kyoo.Core.Controllers
await _shows.Delete(obj.ShowId); await _shows.Delete(obj.ShowId);
} }
} }
}

View File

@ -25,8 +25,8 @@ using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Utils; using Kyoo.Abstractions.Models.Utils;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle library items. /// A local repository to handle library items.
/// </summary> /// </summary>
@ -124,4 +124,3 @@ namespace Kyoo.Core.Controllers
); );
} }
} }
}

View File

@ -32,8 +32,8 @@ using Kyoo.Postgresql;
using Kyoo.Utils; using Kyoo.Utils;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A base class to create repositories using Entity Framework. /// A base class to create repositories using Entity Framework.
/// </summary> /// </summary>
@ -170,9 +170,7 @@ namespace Kyoo.Core.Controllers
{ {
T? ret = await GetOrDefault(filter, include, sortBy, reverse, afterId); T? ret = await GetOrDefault(filter, include, sortBy, reverse, afterId);
if (ret == null) if (ret == null)
throw new ItemNotFoundException( throw new ItemNotFoundException($"No {typeof(T).Name} found with the given predicate.");
$"No {typeof(T).Name} found with the given predicate."
);
return ret; return ret;
} }
@ -244,13 +242,7 @@ namespace Kyoo.Core.Controllers
Pagination? limit = default Pagination? limit = default
) )
{ {
IQueryable<T> query = await ApplyFilters( IQueryable<T> query = await ApplyFilters(Database.Set<T>(), filter, sort, limit, include);
Database.Set<T>(),
filter,
sort,
limit,
include
);
return await query.ToListAsync(); return await query.ToListAsync();
} }
@ -435,9 +427,8 @@ namespace Kyoo.Core.Controllers
protected virtual Task Validate(T resource) protected virtual Task Validate(T resource)
{ {
if ( if (
typeof(T) typeof(T).GetProperty(nameof(resource.Slug))!.GetCustomAttribute<ComputedAttribute>()
.GetProperty(nameof(resource.Slug))! != null
.GetCustomAttribute<ComputedAttribute>() != null
) )
return Task.CompletedTask; return Task.CompletedTask;
if (string.IsNullOrEmpty(resource.Slug)) if (string.IsNullOrEmpty(resource.Slug))
@ -446,9 +437,7 @@ namespace Kyoo.Core.Controllers
{ {
try try
{ {
MethodInfo? setter = typeof(T) MethodInfo? setter = typeof(T).GetProperty(nameof(resource.Slug))!.GetSetMethod();
.GetProperty(nameof(resource.Slug))!
.GetSetMethod();
if (setter != null) if (setter != null)
setter.Invoke(resource, new object[] { resource.Slug + '!' }); setter.Invoke(resource, new object[] { resource.Slug + '!' });
else else
@ -496,4 +485,3 @@ namespace Kyoo.Core.Controllers
await Delete(resource); await Delete(resource);
} }
} }
}

View File

@ -25,8 +25,8 @@ using Kyoo.Abstractions.Models.Utils;
using Kyoo.Postgresql; using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle shows /// A local repository to handle shows
/// </summary> /// </summary>
@ -106,4 +106,3 @@ namespace Kyoo.Core.Controllers
await base.Delete(obj); await base.Delete(obj);
} }
} }
}

View File

@ -22,8 +22,8 @@ using System.Data.Common;
using System.IO; using System.IO;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle shows /// A local repository to handle shows
/// </summary> /// </summary>
@ -61,4 +61,3 @@ namespace Kyoo.Core.Controllers
public NewsRepository(DbConnection database, SqlVariableContext context) public NewsRepository(DbConnection database, SqlVariableContext context)
: base(database, context) { } : base(database, context) { }
} }
}

View File

@ -29,8 +29,8 @@ using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle seasons. /// A local repository to handle seasons.
/// </summary> /// </summary>
@ -47,8 +47,7 @@ namespace Kyoo.Core.Controllers
IRepository<Show>.OnEdited += async (show) => IRepository<Show>.OnEdited += async (show) =>
{ {
await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope(); await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope();
DatabaseContext database = DatabaseContext database = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
scope.ServiceProvider.GetRequiredService<DatabaseContext>();
List<Season> seasons = await database List<Season> seasons = await database
.Seasons.AsTracking() .Seasons.AsTracking()
.Where(x => x.ShowId == show.Id) .Where(x => x.ShowId == show.Id)
@ -130,4 +129,3 @@ namespace Kyoo.Core.Controllers
await base.Delete(obj); await base.Delete(obj);
} }
} }
}

View File

@ -26,8 +26,8 @@ using Kyoo.Postgresql;
using Kyoo.Utils; using Kyoo.Utils;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle shows /// A local repository to handle shows
/// </summary> /// </summary>
@ -107,4 +107,3 @@ namespace Kyoo.Core.Controllers
await base.Delete(obj); await base.Delete(obj);
} }
} }
}

View File

@ -26,8 +26,8 @@ using Kyoo.Postgresql;
using Kyoo.Utils; using Kyoo.Utils;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// A local repository to handle studios /// A local repository to handle studios
/// </summary> /// </summary>
@ -79,4 +79,3 @@ namespace Kyoo.Core.Controllers
await base.Delete(obj); await base.Delete(obj);
} }
} }
}

View File

@ -31,8 +31,8 @@ using Kyoo.Abstractions.Models.Exceptions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SkiaSharp; using SkiaSharp;
namespace Kyoo.Core.Controllers namespace Kyoo.Core.Controllers;
{
/// <summary> /// <summary>
/// Download images and retrieve the path of those images for a resource. /// Download images and retrieve the path of those images for a resource.
/// </summary> /// </summary>
@ -42,8 +42,7 @@ namespace Kyoo.Core.Controllers
Lazy<IRepository<User>> users Lazy<IRepository<User>> users
) : IThumbnailsManager ) : IThumbnailsManager
{ {
private static readonly Dictionary<string, TaskCompletionSource<object>> _downloading = private static readonly Dictionary<string, TaskCompletionSource<object>> _downloading = new();
new();
private static async Task _WriteTo(SKBitmap bitmap, string path, int quality) private static async Task _WriteTo(SKBitmap bitmap, string path, int quality)
{ {
@ -265,4 +264,3 @@ namespace Kyoo.Core.Controllers
await _WriteTo(ret, $"/metadata/user/{userId}.webp", 75); await _WriteTo(ret, $"/metadata/user/{userId}.webp", 75);
} }
} }
}

View File

@ -33,8 +33,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Core namespace Kyoo.Core;
{
/// <summary> /// <summary>
/// The core module containing default implementations /// The core module containing default implementations
/// </summary> /// </summary>
@ -145,4 +145,3 @@ namespace Kyoo.Core
) )
}; };
} }
}

View File

@ -25,8 +25,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Kyoo.Core namespace Kyoo.Core;
{
/// <summary> /// <summary>
/// A middleware to handle errors globally. /// A middleware to handle errors globally.
/// </summary> /// </summary>
@ -80,4 +80,3 @@ namespace Kyoo.Core
} }
} }
} }
}

View File

@ -22,8 +22,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// An API endpoint to check the health. /// An API endpoint to check the health.
/// </summary> /// </summary>
@ -72,4 +72,3 @@ namespace Kyoo.Core.Api
/// </summary> /// </summary>
public record HealthResult(string Status); public record HealthResult(string Status);
} }
}

View File

@ -25,8 +25,8 @@ using Kyoo.Abstractions.Models;
using Kyoo.Utils; using Kyoo.Utils;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// A common API containing custom methods to help inheritors. /// A common API containing custom methods to help inheritors.
/// </summary> /// </summary>
@ -97,4 +97,3 @@ namespace Kyoo.Core.Api
return new SearchPage<TResult>(result, self, previous, next, first); return new SearchPage<TResult>(result, self, previous, next, first);
} }
} }
}

View File

@ -27,8 +27,8 @@ using Kyoo.Models;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// A base class to handle CRUD operations on a specific resource type <typeparamref name="T"/>. /// A base class to handle CRUD operations on a specific resource type <typeparamref name="T"/>.
/// </summary> /// </summary>
@ -67,10 +67,7 @@ namespace Kyoo.Core.Api
[PartialPermission(Kind.Read)] [PartialPermission(Kind.Read)]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<T>> Get( public async Task<ActionResult<T>> Get(Identifier identifier, [FromQuery] Include<T>? fields)
Identifier identifier,
[FromQuery] Include<T>? fields
)
{ {
T? ret = await identifier.Match( T? ret = await identifier.Match(
id => Repository.GetOrDefault(id, fields), id => Repository.GetOrDefault(id, fields),
@ -273,4 +270,3 @@ namespace Kyoo.Core.Api
return NoContent(); return NoContent();
} }
} }
}

View File

@ -26,8 +26,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// A base class to handle CRUD operations and services thumbnails for /// A base class to handle CRUD operations and services thumbnails for
/// a specific resource type <typeparamref name="T"/>. /// a specific resource type <typeparamref name="T"/>.
@ -97,10 +97,7 @@ namespace Kyoo.Core.Api
[PartialPermission(Kind.Read)] [PartialPermission(Kind.Read)]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public Task<IActionResult> GetPoster( public Task<IActionResult> GetPoster(Identifier identifier, [FromQuery] ImageQuality? quality)
Identifier identifier,
[FromQuery] ImageQuality? quality
)
{ {
return _GetImage(identifier, "poster", quality); return _GetImage(identifier, "poster", quality);
} }
@ -140,12 +137,8 @@ namespace Kyoo.Core.Api
/// </response> /// </response>
[HttpGet("{identifier:id}/thumbnail")] [HttpGet("{identifier:id}/thumbnail")]
[HttpGet("{identifier:id}/backdrop", Order = AlternativeRoute)] [HttpGet("{identifier:id}/backdrop", Order = AlternativeRoute)]
public Task<IActionResult> GetBackdrop( public Task<IActionResult> GetBackdrop(Identifier identifier, [FromQuery] ImageQuality? quality)
Identifier identifier,
[FromQuery] ImageQuality? quality
)
{ {
return _GetImage(identifier, "thumbnail", quality); return _GetImage(identifier, "thumbnail", quality);
} }
} }
}

View File

@ -28,8 +28,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Studio"/>. /// Information about one or multiple <see cref="Studio"/>.
/// </summary> /// </summary>
@ -100,4 +100,3 @@ namespace Kyoo.Core.Api
return Page(resources, pagination.Limit); return Page(resources, pagination.Limit);
} }
} }
}

View File

@ -30,8 +30,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Collection"/>. /// Information about one or multiple <see cref="Collection"/>.
/// </summary> /// </summary>
@ -260,4 +260,3 @@ namespace Kyoo.Core.Api
return Page(resources, pagination.Limit); return Page(resources, pagination.Limit);
} }
} }
}

View File

@ -28,8 +28,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Episode"/>. /// Information about one or multiple <see cref="Episode"/>.
/// </summary> /// </summary>
@ -196,4 +196,3 @@ namespace Kyoo.Core.Api
return (path, $"/episodes/{identifier}"); return (path, $"/episodes/{identifier}");
} }
} }
}

View File

@ -23,8 +23,8 @@ using Kyoo.Abstractions.Models.Permissions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Endpoint for items that are not part of a specific library. /// Endpoint for items that are not part of a specific library.
/// An item can ether represent a collection or a show. /// An item can ether represent a collection or a show.
@ -54,4 +54,3 @@ namespace Kyoo.Core.Api
_libraryItems = libraryItems; _libraryItems = libraryItems;
} }
} }
}

View File

@ -30,8 +30,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Movie"/>. /// Information about one or multiple <see cref="Movie"/>.
/// </summary> /// </summary>
@ -208,4 +208,3 @@ namespace Kyoo.Core.Api
return (path, $"/movies/{identifier}"); return (path, $"/movies/{identifier}");
} }
} }
}

View File

@ -23,8 +23,8 @@ using Kyoo.Abstractions.Models.Permissions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// List new items added to kyoo. /// List new items added to kyoo.
/// </summary> /// </summary>
@ -38,4 +38,3 @@ namespace Kyoo.Core.Api
public NewsApi(IRepository<INews> news, IThumbnailsManager thumbs) public NewsApi(IRepository<INews> news, IThumbnailsManager thumbs)
: base(news, thumbs) { } : base(news, thumbs) { }
} }
}

View File

@ -26,8 +26,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// An endpoint to search for every resources of kyoo. Searching for only a specific type of resource /// An endpoint to search for every resources of kyoo. Searching for only a specific type of resource
/// is available on the said endpoint. /// is available on the said endpoint.
@ -69,9 +69,7 @@ namespace Kyoo.Core.Api
[FromQuery] Include<Collection> fields [FromQuery] Include<Collection> fields
) )
{ {
return SearchPage( return SearchPage(await _searchManager.SearchCollections(q, sortBy, pagination, fields));
await _searchManager.SearchCollections(q, sortBy, pagination, fields)
);
} }
/// <summary> /// <summary>
@ -204,4 +202,3 @@ namespace Kyoo.Core.Api
return SearchPage(await _searchManager.SearchStudios(q, sortBy, pagination, fields)); return SearchPage(await _searchManager.SearchStudios(q, sortBy, pagination, fields));
} }
} }
}

View File

@ -28,8 +28,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Season"/>. /// Information about one or multiple <see cref="Season"/>.
/// </summary> /// </summary>
@ -87,10 +87,7 @@ namespace Kyoo.Core.Api
) )
{ {
ICollection<Episode> resources = await _libraryManager.Episodes.GetAll( ICollection<Episode> resources = await _libraryManager.Episodes.GetAll(
Filter.And( Filter.And(filter, identifier.Matcher<Episode>(x => x.SeasonId, x => x.Season!.Slug)),
filter,
identifier.Matcher<Episode>(x => x.SeasonId, x => x.Season!.Slug)
),
sortBy, sortBy,
fields, fields,
pagination pagination
@ -132,4 +129,3 @@ namespace Kyoo.Core.Api
return ret; return ret;
} }
} }
}

View File

@ -30,8 +30,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Information about one or multiple <see cref="Show"/>. /// Information about one or multiple <see cref="Show"/>.
/// </summary> /// </summary>
@ -256,10 +256,7 @@ namespace Kyoo.Core.Api
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ShowWatchStatus?> SetWatchStatus( public async Task<ShowWatchStatus?> SetWatchStatus(Identifier identifier, WatchStatus status)
Identifier identifier,
WatchStatus status
)
{ {
Guid id = await identifier.Match( Guid id = await identifier.Match(
id => Task.FromResult(id), id => Task.FromResult(id),
@ -291,4 +288,3 @@ namespace Kyoo.Core.Api
await _libraryManager.WatchStatus.DeleteShowStatus(id, User.GetIdOrThrow()); await _libraryManager.WatchStatus.DeleteShowStatus(id, User.GetIdOrThrow());
} }
} }
}

View File

@ -29,8 +29,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// List new items added to kyoo. /// List new items added to kyoo.
/// </summary> /// </summary>
@ -69,4 +69,3 @@ namespace Kyoo.Core.Api
return Page(resources, pagination.Limit); return Page(resources, pagination.Limit);
} }
} }
}

View File

@ -28,8 +28,8 @@ using Kyoo.Utils;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Core.Api namespace Kyoo.Core.Api;
{
/// <summary> /// <summary>
/// Proxy to other services /// Proxy to other services
/// </summary> /// </summary>
@ -93,4 +93,3 @@ namespace Kyoo.Core.Api
await _Proxy(rest + query.ToQueryString(), (path, $"{type}/{id}")); await _Proxy(rest + query.ToQueryString(), (path, $"{type}/{id}"));
} }
} }
}

View File

@ -37,8 +37,8 @@ using Serilog.Templates;
using Serilog.Templates.Themes; using Serilog.Templates.Themes;
using ILogger = Serilog.ILogger; using ILogger = Serilog.ILogger;
namespace Kyoo.Host namespace Kyoo.Host;
{
/// <summary> /// <summary>
/// Hosts of kyoo (main functions) generally only create a new <see cref="Application"/> /// Hosts of kyoo (main functions) generally only create a new <see cref="Application"/>
/// and return <see cref="Start(string[])"/>. /// and return <see cref="Start(string[])"/>.
@ -124,10 +124,7 @@ namespace Kyoo.Host
"Version: {Version}", "Version: {Version}",
Assembly.GetExecutingAssembly().GetName().Version.ToString(3) Assembly.GetExecutingAssembly().GetName().Version.ToString(3)
); );
_logger.Information( _logger.Information("Data directory: {DataDirectory}", Environment.CurrentDirectory);
"Data directory: {DataDirectory}",
Environment.CurrentDirectory
);
await host.RunAsync(cancellationToken); await host.RunAsync(cancellationToken);
} }
catch (Exception ex) catch (Exception ex)
@ -157,9 +154,7 @@ namespace Kyoo.Host
}) })
.UseIIS() .UseIIS()
.UseIISIntegration() .UseIISIntegration()
.UseUrls( .UseUrls(Environment.GetEnvironmentVariable("KYOO_BIND_URL") ?? "http://*:5000")
Environment.GetEnvironmentVariable("KYOO_BIND_URL") ?? "http://*:5000"
)
.UseStartup(host => .UseStartup(host =>
PluginsStartup.FromWebHost(host, new LoggerFactory().AddSerilog()) PluginsStartup.FromWebHost(host, new LoggerFactory().AddSerilog())
) )
@ -199,4 +194,3 @@ namespace Kyoo.Host
.Enrich.FromLogContext(); .Enrich.FromLogContext();
} }
} }
}

View File

@ -23,8 +23,8 @@ using Kyoo.Abstractions.Controllers;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Kyoo.Host.Controllers namespace Kyoo.Host.Controllers;
{
/// <summary> /// <summary>
/// An implementation of <see cref="IPluginManager"/>. /// An implementation of <see cref="IPluginManager"/>.
/// This is used to load plugins and retrieve information from them. /// This is used to load plugins and retrieve information from them.
@ -86,10 +86,7 @@ namespace Kyoo.Host.Controllers
public void LoadPlugins(params Type[] plugins) public void LoadPlugins(params Type[] plugins)
{ {
LoadPlugins( LoadPlugins(
plugins plugins.Select(x => (IPlugin)ActivatorUtilities.CreateInstance(_provider, x)).ToArray()
.Select(x => (IPlugin)ActivatorUtilities.CreateInstance(_provider, x))
.ToArray()
); );
} }
} }
}

View File

@ -23,8 +23,8 @@ using Kyoo.Abstractions.Controllers;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Serilog; using Serilog;
namespace Kyoo.Host namespace Kyoo.Host;
{
/// <summary> /// <summary>
/// A module that registers host controllers and other needed things. /// A module that registers host controllers and other needed things.
/// </summary> /// </summary>
@ -58,4 +58,3 @@ namespace Kyoo.Host
public IEnumerable<IStartupAction> ConfigureSteps => public IEnumerable<IStartupAction> ConfigureSteps =>
new[] { SA.New<IApplicationBuilder>(app => app.UseSerilogRequestLogging(), SA.Before) }; new[] { SA.New<IApplicationBuilder>(app => app.UseSerilogRequestLogging(), SA.Before) };
} }
}

View File

@ -36,8 +36,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Kyoo.Host namespace Kyoo.Host;
{
/// <summary> /// <summary>
/// The Startup class is used to configure the AspNet's webhost. /// The Startup class is used to configure the AspNet's webhost.
/// </summary> /// </summary>
@ -81,8 +81,7 @@ namespace Kyoo.Host
/// <returns>A new <see cref="PluginsStartup"/>.</returns> /// <returns>A new <see cref="PluginsStartup"/>.</returns>
public static PluginsStartup FromWebHost(WebHostBuilderContext host, ILoggerFactory logger) public static PluginsStartup FromWebHost(WebHostBuilderContext host, ILoggerFactory logger)
{ {
HostServiceProvider hostProvider = HostServiceProvider hostProvider = new(host.HostingEnvironment, host.Configuration, logger);
new(host.HostingEnvironment, host.Configuration, logger);
PluginManager plugins = new(hostProvider, logger.CreateLogger<PluginManager>()); PluginManager plugins = new(hostProvider, logger.CreateLogger<PluginManager>());
return new PluginsStartup(plugins); return new PluginsStartup(plugins);
} }
@ -93,9 +92,7 @@ namespace Kyoo.Host
/// <param name="services">The service collection to fill.</param> /// <param name="services">The service collection to fill.</param>
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
foreach ( foreach (Assembly assembly in _plugins.GetAllPlugins().Select(x => x.GetType().Assembly))
Assembly assembly in _plugins.GetAllPlugins().Select(x => x.GetType().Assembly)
)
services.AddMvcCore().AddApplicationPart(assembly); services.AddMvcCore().AddApplicationPart(assembly);
_hostModule.Configure(services); _hostModule.Configure(services);
@ -199,4 +196,3 @@ namespace Kyoo.Host
} }
} }
} }
}

View File

@ -19,8 +19,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
namespace Kyoo.Host namespace Kyoo.Host;
{
/// <summary> /// <summary>
/// Program entrypoint. /// Program entrypoint.
/// </summary> /// </summary>
@ -46,4 +46,3 @@ namespace Kyoo.Host
return application.Start(args); return application.Start(args);
} }
} }
}

View File

@ -24,8 +24,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using static System.Text.Json.JsonNamingPolicy; using static System.Text.Json.JsonNamingPolicy;
namespace Kyoo.Meiliseach namespace Kyoo.Meiliseach;
{
public class MeilisearchModule : IPlugin public class MeilisearchModule : IPlugin
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -64,11 +64,7 @@ namespace Kyoo.Meiliseach
CamelCase.ConvertName(nameof(Movie.Rating)), CamelCase.ConvertName(nameof(Movie.Rating)),
CamelCase.ConvertName(nameof(Movie.Runtime)), CamelCase.ConvertName(nameof(Movie.Runtime)),
}, },
DisplayedAttributes = new[] DisplayedAttributes = new[] { CamelCase.ConvertName(nameof(Movie.Id)), "kind" },
{
CamelCase.ConvertName(nameof(Movie.Id)),
"kind"
},
RankingRules = new[] RankingRules = new[]
{ {
"words", "words",
@ -191,4 +187,3 @@ namespace Kyoo.Meiliseach
builder.RegisterType<SearchManager>().As<ISearchManager>().InstancePerLifetimeScope(); builder.RegisterType<SearchManager>().As<ISearchManager>().InstancePerLifetimeScope();
} }
} }
}

View File

@ -31,8 +31,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace Kyoo.Postgresql namespace Kyoo.Postgresql;
{
/// <summary> /// <summary>
/// The database handle used for all local repositories. /// The database handle used for all local repositories.
/// This is an abstract class. It is meant to be implemented by plugins. This allow the core to be database agnostic. /// This is an abstract class. It is meant to be implemented by plugins. This allow the core to be database agnostic.
@ -260,10 +260,7 @@ namespace Kyoo.Postgresql
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Show>().Ignore(x => x.FirstEpisode).Ignore(x => x.AirDate); modelBuilder.Entity<Show>().Ignore(x => x.FirstEpisode).Ignore(x => x.AirDate);
modelBuilder modelBuilder.Entity<Episode>().Ignore(x => x.PreviousEpisode).Ignore(x => x.NextEpisode);
.Entity<Episode>()
.Ignore(x => x.PreviousEpisode)
.Ignore(x => x.NextEpisode);
modelBuilder modelBuilder
.Entity<Show>() .Entity<Show>()
@ -353,9 +350,7 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<MovieWatchStatus>().HasQueryFilter(x => x.UserId == CurrentUserId); modelBuilder.Entity<MovieWatchStatus>().HasQueryFilter(x => x.UserId == CurrentUserId);
modelBuilder.Entity<ShowWatchStatus>().HasQueryFilter(x => x.UserId == CurrentUserId); modelBuilder.Entity<ShowWatchStatus>().HasQueryFilter(x => x.UserId == CurrentUserId);
modelBuilder modelBuilder.Entity<EpisodeWatchStatus>().HasQueryFilter(x => x.UserId == CurrentUserId);
.Entity<EpisodeWatchStatus>()
.HasQueryFilter(x => x.UserId == CurrentUserId);
modelBuilder.Entity<ShowWatchStatus>().Navigation(x => x.NextEpisode).AutoInclude(); modelBuilder.Entity<ShowWatchStatus>().Navigation(x => x.NextEpisode).AutoInclude();
@ -543,9 +538,7 @@ namespace Kyoo.Postgresql
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete</param>
/// <exception cref="DuplicatedItemException">A duplicated item has been found.</exception> /// <exception cref="DuplicatedItemException">A duplicated item has been found.</exception>
/// <returns>The number of state entries written to the database.</returns> /// <returns>The number of state entries written to the database.</returns>
public override async Task<int> SaveChangesAsync( public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default
)
{ {
try try
{ {
@ -635,13 +628,10 @@ namespace Kyoo.Postgresql
public void DiscardChanges() public void DiscardChanges()
{ {
foreach ( foreach (
EntityEntry entry in ChangeTracker EntityEntry entry in ChangeTracker.Entries().Where(x => x.State != EntityState.Detached)
.Entries()
.Where(x => x.State != EntityState.Detached)
) )
{ {
entry.State = EntityState.Detached; entry.State = EntityState.Detached;
} }
} }
} }
}

View File

@ -25,8 +25,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Npgsql; using Npgsql;
namespace Kyoo.Postgresql namespace Kyoo.Postgresql;
{
/// <summary> /// <summary>
/// A postgresql implementation of <see cref="DatabaseContext"/>. /// A postgresql implementation of <see cref="DatabaseContext"/>.
/// </summary> /// </summary>
@ -135,4 +135,3 @@ namespace Kyoo.Postgresql
}; };
} }
} }
}

View File

@ -33,8 +33,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Npgsql; using Npgsql;
namespace Kyoo.Postgresql namespace Kyoo.Postgresql;
{
/// <summary> /// <summary>
/// A module to add postgresql capacity to the app. /// A module to add postgresql capacity to the app.
/// </summary> /// </summary>
@ -137,11 +137,8 @@ namespace Kyoo.Postgresql
}, },
ServiceLifetime.Transient ServiceLifetime.Transient
); );
services.AddTransient<DbConnection>( services.AddTransient<DbConnection>((_) => new NpgsqlConnection(builder.ConnectionString));
(_) => new NpgsqlConnection(builder.ConnectionString)
);
services.AddHealthChecks().AddDbContextCheck<DatabaseContext>(); services.AddHealthChecks().AddDbContextCheck<DatabaseContext>();
} }
} }
}

View File

@ -22,8 +22,8 @@ using Kyoo.Swagger.Models;
using NSwag; using NSwag;
using NSwag.Generation.AspNetCore; using NSwag.Generation.AspNetCore;
namespace Kyoo.Swagger namespace Kyoo.Swagger;
{
/// <summary> /// <summary>
/// A class to sort apis. /// A class to sort apis.
/// </summary> /// </summary>
@ -63,4 +63,3 @@ namespace Kyoo.Swagger
}; };
} }
} }
}

View File

@ -26,8 +26,8 @@ using NSwag;
using NSwag.Generation.AspNetCore; using NSwag.Generation.AspNetCore;
using NSwag.Generation.Processors.Contexts; using NSwag.Generation.Processors.Contexts;
namespace Kyoo.Swagger namespace Kyoo.Swagger;
{
/// <summary> /// <summary>
/// A class to handle Api Groups (OpenApi tags and x-tagGroups). /// A class to handle Api Groups (OpenApi tags and x-tagGroups).
/// Tags should be specified via <see cref="ApiDefinitionAttribute"/> and this filter will map this to the /// Tags should be specified via <see cref="ApiDefinitionAttribute"/> and this filter will map this to the
@ -121,4 +121,3 @@ namespace Kyoo.Swagger
options.PostProcess += x => x.AddLeftoversToOthersGroup(); options.PostProcess += x => x.AddLeftoversToOthersGroup();
} }
} }
}

View File

@ -24,8 +24,8 @@ using Kyoo.Utils;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace Kyoo.Swagger namespace Kyoo.Swagger;
{
/// <summary> /// <summary>
/// A filter that change <see cref="ProducesResponseTypeAttribute"/>'s /// A filter that change <see cref="ProducesResponseTypeAttribute"/>'s
/// <see cref="ProducesResponseTypeAttribute.Type"/> that where set to <see cref="ActionResult{T}"/> to the /// <see cref="ProducesResponseTypeAttribute.Type"/> that where set to <see cref="ActionResult{T}"/> to the
@ -66,4 +66,3 @@ namespace Kyoo.Swagger
} }
} }
} }
}

View File

@ -20,8 +20,8 @@ using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using NSwag; using NSwag;
namespace Kyoo.Swagger.Models namespace Kyoo.Swagger.Models;
{
/// <summary> /// <summary>
/// A class representing a group of tags in the <see cref="OpenApiDocument"/> /// A class representing a group of tags in the <see cref="OpenApiDocument"/>
/// </summary> /// </summary>
@ -39,4 +39,3 @@ namespace Kyoo.Swagger.Models
[JsonProperty(PropertyName = "tags")] [JsonProperty(PropertyName = "tags")]
public List<string> Tags { get; set; } public List<string> Tags { get; set; }
} }
}

View File

@ -25,8 +25,8 @@ using NSwag;
using NSwag.Generation.Processors; using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts; using NSwag.Generation.Processors.Contexts;
namespace Kyoo.Swagger namespace Kyoo.Swagger;
{
/// <summary> /// <summary>
/// An operation processor that adds permissions information from the <see cref="PermissionAttribute"/> and the /// An operation processor that adds permissions information from the <see cref="PermissionAttribute"/> and the
/// <see cref="PartialPermissionAttribute"/>. /// <see cref="PartialPermissionAttribute"/>.
@ -36,8 +36,7 @@ namespace Kyoo.Swagger
/// <inheritdoc /> /// <inheritdoc />
public bool Process(OperationProcessorContext context) public bool Process(OperationProcessorContext context)
{ {
context.OperationDescription.Operation.Security ??= context.OperationDescription.Operation.Security ??= new List<OpenApiSecurityRequirement>();
new List<OpenApiSecurityRequirement>();
OpenApiSecurityRequirement perms = context OpenApiSecurityRequirement perms = context
.MethodInfo.GetCustomAttributes<UserOnlyAttribute>() .MethodInfo.GetCustomAttributes<UserOnlyAttribute>()
.Aggregate( .Aggregate(
@ -101,4 +100,3 @@ namespace Kyoo.Swagger
: new List<string>(); : new List<string>();
} }
} }
}

View File

@ -29,8 +29,8 @@ using NSwag;
using NSwag.Generation.AspNetCore; using NSwag.Generation.AspNetCore;
using static Kyoo.Abstractions.Models.Utils.Constants; using static Kyoo.Abstractions.Models.Utils.Constants;
namespace Kyoo.Swagger namespace Kyoo.Swagger;
{
/// <summary> /// <summary>
/// A module to enable a swagger interface and an OpenAPI endpoint to document Kyoo. /// A module to enable a swagger interface and an OpenAPI endpoint to document Kyoo.
/// </summary> /// </summary>
@ -128,4 +128,3 @@ namespace Kyoo.Swagger
) )
}; };
} }
}