Skip to content

Commit

Permalink
Migrate to dotnet8 (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya authored Mar 23, 2024
2 parents 5fedce7 + ee0f703 commit 6143125
Show file tree
Hide file tree
Showing 28 changed files with 981 additions and 1,039 deletions.
2 changes: 1 addition & 1 deletion back/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 as builder
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 as builder
ARG TARGETARCH
WORKDIR /kyoo

Expand Down
2 changes: 1 addition & 1 deletion back/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0
FROM mcr.microsoft.com/dotnet/sdk:8.0
RUN apt-get update && apt-get install -y curl
WORKDIR /app

Expand Down
4 changes: 2 additions & 2 deletions back/src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>preview</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
<Company>Kyoo</Company>
<Authors>Kyoo</Authors>
<Copyright>Copyright (c) Kyoo</Copyright>
Expand Down
10 changes: 5 additions & 5 deletions back/src/Kyoo.Abstractions/Kyoo.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Autofac" Version="8.0.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="EntityFrameworkCore.Projectables" Version="4.1.4-prebeta" />
<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="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Sprache" Version="2.3.1" />
<PackageReference Include="System.ComponentModel.Composition" Version="7.0.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,18 @@
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Runtime.Serialization;

namespace Kyoo.Abstractions.Models.Exceptions;

/// <summary>
/// An exception raised when an item already exists in the database.
/// </summary>
[Serializable]
public class DuplicatedItemException : Exception
public class DuplicatedItemException(object? existing = null)
: Exception("Already exists in the database.")
{
/// <summary>
/// The existing object.
/// </summary>
public object? Existing { get; }

/// <summary>
/// Create a new <see cref="DuplicatedItemException"/> with the default message.
/// </summary>
/// <param name="existing">The existing object.</param>
public DuplicatedItemException(object? existing = null)
: base("Already exists in the database.")
{
Existing = existing;
}

/// <summary>
/// The serialization constructor.
/// </summary>
/// <param name="info">Serialization infos</param>
/// <param name="context">The serialization context</param>
protected DuplicatedItemException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
public object? Existing { get; } = existing;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Runtime.Serialization;

namespace Kyoo.Abstractions.Models.Exceptions;

Expand All @@ -39,12 +38,4 @@ public ItemNotFoundException()
/// <param name="message">The message of the exception</param>
public ItemNotFoundException(string message)
: base(message) { }

/// <summary>
/// The serialization constructor
/// </summary>
/// <param name="info">Serialization infos</param>
/// <param name="context">The serialization context</param>
protected ItemNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Runtime.Serialization;

namespace Kyoo.Abstractions.Models.Exceptions;

Expand All @@ -29,7 +28,4 @@ public UnauthorizedException()

public UnauthorizedException(string message)
: base(message) { }

protected UnauthorizedException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
2 changes: 1 addition & 1 deletion back/src/Kyoo.Authentication/Kyoo.Authentication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />

<ProjectReference Include="../Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion back/src/Kyoo.Authentication/Views/AuthApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public async Task<ActionResult> GetProfilePicture()
{
Stream img = await thumbs.GetUserImage(User.GetIdOrThrow());
// Allow clients to cache the image for 6 month.
Response.Headers.Add("Cache-Control", $"public, max-age={60 * 60 * 24 * 31 * 6}");
Response.Headers.CacheControl = $"public, max-age={60 * 60 * 24 * 31 * 6}";
return File(img, "image/webp", true);
}

Expand Down
14 changes: 7 additions & 7 deletions back/src/Kyoo.Core/Kyoo.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.Proxy" Version="4.4.0" />
<PackageReference Include="AspNetCore.Proxy" Version="4.5.0" />
<PackageReference Include="Blurhash.SkiaSharp" Version="2.0.0" />
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="InterpolatedSql.Dapper" Version="2.1.0" />
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="InterpolatedSql.Dapper" Version="2.3.0" />
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ private async Task<IActionResult> _GetImage(
if (!identifier.Match(id => false, slug => slug == "random"))
{
// Allow clients to cache the image for 6 month.
Response.Headers.Add("Cache-Control", $"public, max-age={60 * 60 * 24 * 31 * 6}");
Response.Headers.CacheControl = $"public, max-age={60 * 60 * 24 * 31 * 6}";
}
else
Response.Headers.Add("Cache-Control", $"public, no-store");
Response.Headers.CacheControl = $"public, no-store";
return PhysicalFile(Path.GetFullPath(path), "image/webp", true);
}

Expand Down
4 changes: 2 additions & 2 deletions back/src/Kyoo.Core/Views/Resources/UserApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public async Task<ActionResult> GetProfilePicture(Identifier identifier)
);
Stream img = await thumbs.GetUserImage(gid);
if (identifier.Is("random"))
Response.Headers.Add("Cache-Control", $"public, no-store");
Response.Headers.CacheControl = $"public, no-store";
else
{
// Allow clients to cache the image for 6 month.
Response.Headers.Add("Cache-Control", $"public, max-age={60 * 60 * 24 * 31 * 6}");
Response.Headers.CacheControl = $"public, max-age={60 * 60 * 24 * 31 * 6}";
}
return File(img, "image/webp", true);
}
Expand Down
12 changes: 6 additions & 6 deletions back/src/Kyoo.Host/Kyoo.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.SyslogMessages" Version="3.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="Autofac" Version="8.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Autofac.Extras.AttributeMetadata" Version="6.0.0" />
</ItemGroup>

Expand Down
75 changes: 35 additions & 40 deletions back/src/Kyoo.Host/PluginsStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,63 +136,58 @@ public void Configure(IApplicationBuilder app, ILifetimeScope container)
/// A simple host service provider used to activate plugins instance.
/// The same services as a generic host are available and an <see cref="ILoggerFactory"/> has been added.
/// </summary>
private class HostServiceProvider : IServiceProvider
private class HostServiceProvider(
IWebHostEnvironment hostEnvironment,
IConfiguration configuration,
ILoggerFactory loggerFactory
) : IServiceProvider
{
/// <summary>
/// The host environment that could be used by plugins to configure themself.
/// </summary>
private readonly IWebHostEnvironment _hostEnvironment;

/// <summary>
/// The configuration context.
/// </summary>
private readonly IConfiguration _configuration;

/// <summary>
/// A logger factory used to create a logger for the plugin manager.
/// </summary>
private readonly ILoggerFactory _loggerFactory;

/// <summary>
/// Create a new <see cref="HostServiceProvider"/> that will return given services when asked.
/// </summary>
/// <param name="hostEnvironment">
/// The host environment that could be used by plugins to configure themself.
/// </param>
/// <param name="configuration">The configuration context</param>
/// <param name="loggerFactory">A logger factory used to create a logger for the plugin manager.</param>
public HostServiceProvider(
IWebHostEnvironment hostEnvironment,
IConfiguration configuration,
ILoggerFactory loggerFactory
)
{
_hostEnvironment = hostEnvironment;
_configuration = configuration;
_loggerFactory = loggerFactory;
}

/// <inheritdoc />
public object GetService(Type serviceType)
{
if (
serviceType == typeof(IWebHostEnvironment)
|| serviceType == typeof(IHostEnvironment)
)
return _hostEnvironment;
return hostEnvironment;
if (serviceType == typeof(IConfiguration))
return _configuration;
if (serviceType.GetGenericTypeDefinition() == typeof(ILogger<>))
return configuration;
if (serviceType == typeof(IServiceProviderIsService))
return new ProviderIsService();
if (
serviceType.IsGenericType
&& serviceType.GetGenericTypeDefinition() == typeof(ILogger<>)
)
{
return Utility.RunGenericMethod<object>(
typeof(LoggerFactoryExtensions),
nameof(LoggerFactoryExtensions.CreateLogger),
serviceType.GetGenericArguments().First(),
_loggerFactory
loggerFactory
);
}

return null;
throw new ArgumentException(
$"{serviceType.Name} is not available in configuration stpe"
);
}

public class ProviderIsService : IServiceProviderIsService
{
public bool IsService(Type serviceType)
{
Type[] supported =
[
typeof(IWebHostEnvironment),
typeof(IHostEnvironment),
typeof(IConfiguration),
typeof(IServiceProviderIsService),
];
if (supported.Contains(serviceType))
return true;
return serviceType.IsGenericType
&& serviceType.GetGenericTypeDefinition() == typeof(ILogger<>);
}
}
}
}
2 changes: 1 addition & 1 deletion back/src/Kyoo.Meilisearch/Kyoo.Meilisearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MeiliSearch" Version="0.14.6" />
<PackageReference Include="MeiliSearch" Version="0.15.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions back/src/Kyoo.Postgresql/Kyoo.Postgresql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="EFCore.NamingConventions" Version="8.0.3" />
<PackageReference Include="EntityFrameworkCore.Projectables" Version="4.1.4-prebeta" />
<PackageReference Include="InterpolatedSql.Dapper" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PackageReference Include="InterpolatedSql.Dapper" Version="2.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 6143125

Please sign in to comment.