using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.ShareLinks.Services;
using MediaBrowser.Model.Tasks;
namespace Jellyfin.Plugin.ShareLinks.Tasks;
///
/// Scheduled task that expires share links past their ExpiresAtUtc and tears down
/// the associated guest users and tags.
///
public sealed class CleanupShareLinksScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly IShareLinkCleanupService _cleanupService;
/// Initializes a new instance of the class.
public CleanupShareLinksScheduledTask(IShareLinkCleanupService cleanupService)
{
_cleanupService = cleanupService;
}
///
public string Name => "Clean up ShareLinks";
///
public string Key => "ShareLinksCleanup";
///
public string Description => "Expires share links past their expiry time and removes their guest users and tags.";
///
public string Category => "ShareLinks";
///
public bool IsHidden => false;
///
public bool IsEnabled => true;
///
public bool IsLogged => true;
///
public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken)
{
_ = progress;
await _cleanupService.CleanupAsync(cancellationToken).ConfigureAwait(false);
}
///
public IEnumerable GetDefaultTriggers()
{
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfoType.IntervalTrigger,
IntervalTicks = TimeSpan.FromMinutes(30).Ticks,
};
}
}