mirror of https://github.com/ErsatzTV/ErsatzTV.git
11 changed files with 146 additions and 51 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
namespace ErsatzTV.Core.Health.Checks; |
||||
|
||||
public interface IUnavailableHealthCheck : IHealthCheck |
||||
{ |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Extensions; |
||||
using ErsatzTV.Core.Health; |
||||
using ErsatzTV.Core.Health.Checks; |
||||
using ErsatzTV.Core.Interfaces.Emby; |
||||
using ErsatzTV.Core.Interfaces.Jellyfin; |
||||
using ErsatzTV.Core.Interfaces.Plex; |
||||
using ErsatzTV.Infrastructure.Data; |
||||
using Microsoft.EntityFrameworkCore; |
||||
|
||||
namespace ErsatzTV.Infrastructure.Health.Checks; |
||||
|
||||
public class UnavailableHealthCheck : BaseHealthCheck, IUnavailableHealthCheck |
||||
{ |
||||
private readonly IDbContextFactory<TvContext> _dbContextFactory; |
||||
private readonly IEmbyPathReplacementService _embyPathReplacementService; |
||||
private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService; |
||||
private readonly IPlexPathReplacementService _plexPathReplacementService; |
||||
|
||||
public UnavailableHealthCheck( |
||||
IDbContextFactory<TvContext> dbContextFactory, |
||||
IPlexPathReplacementService plexPathReplacementService, |
||||
IJellyfinPathReplacementService jellyfinPathReplacementService, |
||||
IEmbyPathReplacementService embyPathReplacementService) |
||||
{ |
||||
_dbContextFactory = dbContextFactory; |
||||
_plexPathReplacementService = plexPathReplacementService; |
||||
_jellyfinPathReplacementService = jellyfinPathReplacementService; |
||||
_embyPathReplacementService = embyPathReplacementService; |
||||
} |
||||
|
||||
protected override string Title => "Unavailable"; |
||||
|
||||
public async Task<HealthCheckResult> Check(CancellationToken cancellationToken) |
||||
{ |
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); |
||||
|
||||
IQueryable<MediaItem> mediaItems = dbContext.MediaItems |
||||
.Filter(mi => mi.State == MediaItemState.Unavailable) |
||||
.Include(mi => (mi as Episode).MediaVersions) |
||||
.ThenInclude(mv => mv.MediaFiles) |
||||
.Include(mi => (mi as Movie).MediaVersions) |
||||
.ThenInclude(mv => mv.MediaFiles) |
||||
.Include(mi => (mi as MusicVideo).MediaVersions) |
||||
.ThenInclude(mv => mv.MediaFiles) |
||||
.Include(mi => (mi as OtherVideo).MediaVersions) |
||||
.ThenInclude(mv => mv.MediaFiles) |
||||
.Include(mi => (mi as Song).MediaVersions) |
||||
.ThenInclude(mv => mv.MediaFiles); |
||||
|
||||
List<MediaItem> five = await mediaItems |
||||
.OrderBy(mi => mi.Id) |
||||
.Take(5) |
||||
.ToListAsync(cancellationToken); |
||||
|
||||
if (five.Any()) |
||||
{ |
||||
var paths = new List<string>(); |
||||
|
||||
foreach (MediaItem mediaItem in five) |
||||
{ |
||||
string path = await mediaItem.GetLocalPath( |
||||
_plexPathReplacementService, |
||||
_jellyfinPathReplacementService, |
||||
_embyPathReplacementService, |
||||
false); |
||||
|
||||
paths.Add(path); |
||||
} |
||||
|
||||
var files = string.Join(", ", paths); |
||||
|
||||
int count = await mediaItems.CountAsync(cancellationToken); |
||||
|
||||
return WarningResult( |
||||
$"There are {count} files that are unavailable because ErsatzTV cannot find them on disk, including the following: {files}", |
||||
"/search?query=state%3aUnavailable"); |
||||
} |
||||
|
||||
return OkResult(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue