delete guest devices on teardown (#18)

Jellyfin does not cascade a user delete to the Device rows redemption
creates, and DeviceManager throws for the whole listing when one device's
user is missing, so a single leftover guest 404s the dashboard devices page.

Deletes the guest's devices before the user, and sweeps devices this plugin
created whose user is already gone at startup for links torn down by older
builds.
Cette révision appartient à :
Francois CB
2026-07-27 20:56:04 +02:00
révisé par GitHub
Parent d1ee74677b
révision 911ab41b0c
5 fichiers modifiés avec 112 ajouts et 6 suppressions
+22
Voir le fichier
@@ -13,14 +13,17 @@ namespace Jellyfin.Plugin.ShareLinks.Lifecycle;
public sealed class StartupCleanupHostedService : BackgroundService
{
private readonly IShareLinkCleanupService _cleanupService;
private readonly JellyfinGuestUserService _guestUserService;
private readonly ILogger<StartupCleanupHostedService> _logger;
/// <summary>Initializes a new instance of the <see cref="StartupCleanupHostedService"/> class.</summary>
public StartupCleanupHostedService(
IShareLinkCleanupService cleanupService,
JellyfinGuestUserService guestUserService,
ILogger<StartupCleanupHostedService> logger)
{
_cleanupService = cleanupService;
_guestUserService = guestUserService;
_logger = logger;
}
@@ -38,5 +41,24 @@ public sealed class StartupCleanupHostedService : BackgroundService
{
_logger.LogWarning(ex, "ShareLinks: startup cleanup failed.");
}
// Separate try: a device row stranded by an older build breaks the admin
// devices page until it goes, so this should still run when the record
// cleanup above fails for its own reasons.
try
{
var removed = await _guestUserService.PurgeOrphanedGuestDevicesAsync(stoppingToken).ConfigureAwait(false);
if (removed > 0)
{
_logger.LogInformation("ShareLinks: removed {Count} orphaned guest device(s) at startup.", removed);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
}
catch (Exception ex)
{
_logger.LogWarning(ex, "ShareLinks: orphaned guest device sweep failed.");
}
}
}