Format code

This commit is contained in:
Zoe Roux 2024-04-21 21:27:58 +02:00
parent 9e38c3f333
commit 996209d205
No known key found for this signature in database
7 changed files with 34 additions and 26 deletions

View File

@ -104,10 +104,7 @@ public class Image
string? src = document.RootElement.GetProperty("Source").GetString(); string? src = document.RootElement.GetProperty("Source").GetString();
string? blurhash = document.RootElement.GetProperty("Blurhash").GetString(); string? blurhash = document.RootElement.GetProperty("Blurhash").GetString();
Guid? id = document.RootElement.GetProperty("Id").GetGuid(); Guid? id = document.RootElement.GetProperty("Id").GetGuid();
return new Image(src ?? string.Empty, blurhash) return new Image(src ?? string.Empty, blurhash) { Id = id ?? Guid.Empty };
{
Id = id ?? Guid.Empty
};
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -33,8 +33,11 @@ namespace Kyoo.Core.Controllers;
/// <summary> /// <summary>
/// A local repository to handle episodes. /// A local repository to handle episodes.
/// </summary> /// </summary>
public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows, IThumbnailsManager thumbnails) public class EpisodeRepository(
: GenericRepository<Episode>(database) DatabaseContext database,
IRepository<Show> shows,
IThumbnailsManager thumbnails
) : GenericRepository<Episode>(database)
{ {
static EpisodeRepository() static EpisodeRepository()
{ {
@ -86,9 +89,12 @@ public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows
resource.Season = null; resource.Season = null;
if (resource.SeasonId == null && resource.SeasonNumber != null) if (resource.SeasonId == null && resource.SeasonNumber != null)
{ {
resource.SeasonId = await Database.Seasons.Where(x => resource.SeasonId = await Database
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber .Seasons.Where(x =>
).Select(x => x.Id).FirstOrDefaultAsync(); x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
)
.Select(x => x.Id)
.FirstOrDefaultAsync();
} }
await thumbnails.DownloadImages(resource); await thumbnails.DownloadImages(resource);
} }

View File

@ -96,6 +96,7 @@ await using (AsyncServiceScope scope = app.Services.CreateAsyncScope())
{ {
await MeilisearchModule.Initialize(scope.ServiceProvider); await MeilisearchModule.Initialize(scope.ServiceProvider);
} }
// The methods takes care of creating a scope and will download images on the background. // The methods takes care of creating a scope and will download images on the background.
_ = MiscRepository.DownloadMissingImages(app.Services); _ = MiscRepository.DownloadMissingImages(app.Services);

View File

@ -65,4 +65,3 @@ public class ThumbnailsApi(IThumbnailsManager thumbs) : BaseApi
return PhysicalFile(Path.GetFullPath(path), "image/webp", true); return PhysicalFile(Path.GetFullPath(path), "image/webp", true);
} }
} }

View File

@ -40,8 +40,7 @@ namespace Kyoo.Core.Api;
[ApiController] [ApiController]
[PartialPermission(nameof(Show))] [PartialPermission(nameof(Show))]
[ApiDefinition("Shows", Group = ResourcesGroup)] [ApiDefinition("Shows", Group = ResourcesGroup)]
public class MovieApi(ILibraryManager libraryManager) public class MovieApi(ILibraryManager libraryManager) : TranscoderApi<Movie>(libraryManager.Movies)
: TranscoderApi<Movie>(libraryManager.Movies)
{ {
/// <summary> /// <summary>
/// Get studio that made the show /// Get studio that made the show

View File

@ -9,23 +9,27 @@ namespace Kyoo.Postgresql.Migrations
{ {
private void MigrateImage(MigrationBuilder migrationBuilder, string table, string type) private void MigrateImage(MigrationBuilder migrationBuilder, string table, string type)
{ {
migrationBuilder.Sql($""" migrationBuilder.Sql(
update {table} as r set {type} = json_build_object( $"""
'Id', gen_random_uuid(), update {table} as r set {type} = json_build_object(
'Source', r.{type}_source, 'Id', gen_random_uuid(),
'Blurhash', r.{type}_blurhash 'Source', r.{type}_source,
) 'Blurhash', r.{type}_blurhash
where r.{type}_source is not null )
"""); where r.{type}_source is not null
"""
);
} }
private void UnMigrateImage(MigrationBuilder migrationBuilder, string table, string type) private void UnMigrateImage(MigrationBuilder migrationBuilder, string table, string type)
{ {
migrationBuilder.Sql($""" migrationBuilder.Sql(
update {table} as r $"""
set {type}_source = r.{type}->>'Source', update {table} as r
{type}_blurhash = r.{type}->>'Blurhash' set {type}_source = r.{type}->>'Source',
"""); {type}_blurhash = r.{type}->>'Blurhash'
"""
);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -187,7 +187,9 @@ class Matcher:
} }
current = await self._client.get(kind, kyoo_id) current = await self._client.get(kind, kyoo_id)
if self._provider.name not in current["externalId"]: if self._provider.name not in current["externalId"]:
logger.error(f"Could not refresh metadata of {kind}/{kyoo_id}. Missisg provider id.") logger.error(
f"Could not refresh metadata of {kind}/{kyoo_id}. Missisg provider id."
)
return False return False
provider_id = current["externalId"][self._provider.name] provider_id = current["externalId"][self._provider.name]
new_value = await identify_table[kind](current, provider_id) new_value = await identify_table[kind](current, provider_id)