Migrate to dotnet8 (#350)

This commit is contained in:
Zoe Roux 2024-03-23 01:15:57 +01:00 committed by GitHub
commit 6143125f7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 952 additions and 1010 deletions

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -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;
@ -25,28 +24,11 @@ namespace Kyoo.Abstractions.Models.Exceptions;
/// 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;
}

View File

@ -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;
@ -39,12 +38,4 @@ public class ItemNotFoundException : Exception
/// <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) { }
}

View File

@ -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;
@ -29,7 +28,4 @@ public class UnauthorizedException : Exception
public UnauthorizedException(string message)
: base(message) { }
protected UnauthorizedException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

View File

@ -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" />

View File

@ -446,7 +446,7 @@ public class AuthApi(
{
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);
}

View File

@ -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>

View File

@ -74,10 +74,10 @@ public class CrudThumbsApi<T> : CrudApi<T>
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);
}

View File

@ -59,11 +59,11 @@ public class UserApi(ILibraryManager libraryManager, IThumbnailsManager thumbs)
);
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);
}

View File

@ -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>

View File

@ -136,42 +136,12 @@ public class PluginsStartup
/// 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
{
/// <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(
private class HostServiceProvider(
IWebHostEnvironment hostEnvironment,
IConfiguration configuration,
ILoggerFactory loggerFactory
)
) : IServiceProvider
{
_hostEnvironment = hostEnvironment;
_configuration = configuration;
_loggerFactory = loggerFactory;
}
/// <inheritdoc />
public object GetService(Type serviceType)
{
@ -179,20 +149,45 @@ public class PluginsStartup
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<>);
}
}
}
}

View File

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MeiliSearch" Version="0.14.6" />
<PackageReference Include="MeiliSearch" Version="0.15.0" />
</ItemGroup>
<ItemGroup>

View File

@ -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>

View File

@ -23,8 +23,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class Initial : Migration
{
@ -153,10 +153,7 @@ namespace Kyoo.Postgresql.Migrations
status = table.Column<Status>(type: "status", nullable: false),
rating = table.Column<int>(type: "integer", nullable: false),
runtime = table.Column<int>(type: "integer", nullable: false),
air_date = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: true
),
air_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
added_date = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: false,
@ -219,10 +216,7 @@ namespace Kyoo.Postgresql.Migrations
type: "timestamp with time zone",
nullable: true
),
end_air = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: true
),
end_air = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
added_date = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: false,
@ -346,10 +340,7 @@ namespace Kyoo.Postgresql.Migrations
nullable: false,
defaultValueSql: "now() at time zone 'utc'"
),
end_date = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: true
),
end_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
poster_source = table.Column<string>(type: "text", nullable: true),
poster_blurhash = table.Column<string>(
type: "character varying(32)",
@ -567,4 +558,3 @@ namespace Kyoo.Postgresql.Migrations
migrationBuilder.DropTable(name: "studios");
}
}
}

View File

@ -22,8 +22,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class Watchlist : Migration
{
@ -65,10 +65,7 @@ namespace Kyoo.Postgresql.Migrations
},
constraints: table =>
{
table.PrimaryKey(
"pk_episode_watch_status",
x => new { x.user_id, x.episode_id }
);
table.PrimaryKey("pk_episode_watch_status", x => new { x.user_id, x.episode_id });
table.ForeignKey(
name: "fk_episode_watch_status_episodes_episode_id",
column: x => x.episode_id,
@ -221,4 +218,3 @@ namespace Kyoo.Postgresql.Migrations
.OldAnnotation("Npgsql:Enum:watch_status", "completed,watching,droped,planned");
}
}
}

View File

@ -2,8 +2,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class Settings : Migration
{
@ -25,4 +25,3 @@ namespace Kyoo.Postgresql.Migrations
migrationBuilder.DropColumn(name: "settings", table: "users");
}
}
}

View File

@ -1,9 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class RuntimeNullable : Migration
{
@ -55,4 +55,3 @@ namespace Kyoo.Postgresql.Migrations
);
}
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class RemoveUserLogo : Migration
{
@ -32,4 +32,3 @@ namespace Kyoo.Postgresql.Migrations
);
}
}
}

View File

@ -3,8 +3,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class AddIssues : Migration
{
@ -65,4 +65,3 @@ namespace Kyoo.Postgresql.Migrations
);
}
}
}

View File

@ -2,8 +2,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class AddPlayPermission : Migration
{
@ -19,4 +19,3 @@ namespace Kyoo.Postgresql.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) { }
}
}

View File

@ -2,8 +2,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class AddUserExternalId : Migration
{
@ -25,4 +25,3 @@ namespace Kyoo.Postgresql.Migrations
migrationBuilder.DropColumn(name: "external_id", table: "users");
}
}
}

View File

@ -2,8 +2,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
namespace Kyoo.Postgresql.Migrations;
/// <inheritdoc />
public partial class MakePasswordOptional : Migration
{
@ -35,4 +35,3 @@ namespace Kyoo.Postgresql.Migrations
);
}
}
}

View File

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NSwag.AspNetCore" Version="13.20.0" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.3" />
<ProjectReference Include="../Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@ -51,7 +51,6 @@ public class SwaggerModule : IPlugin
document.Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3);
document.DocumentName = "v1";
document.UseControllerSummaryAsTagDescription = true;
document.GenerateExamples = true;
document.PostProcess = options =>
{
options.Info.Contact = new OpenApiContact
@ -82,7 +81,7 @@ public class SwaggerModule : IPlugin
!= AlternativeRoute;
return true;
});
document.SchemaGenerator.Settings.TypeMappers.Add(
document.SchemaSettings.TypeMappers.Add(
new PrimitiveTypeMapper(
typeof(Identifier),
x =>

View File

@ -8,8 +8,8 @@
]);
dotnet = with pkgs.dotnetCorePackages;
combinePackages [
sdk_7_0
aspnetcore_7_0
sdk_8_0
aspnetcore_8_0
aspnetcore_6_0
];
in