using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Jellyfin.Plugin.Floatplane.Channel; using MediaBrowser.Model.Tasks; using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.Floatplane.Tasks; /// /// Scheduled task: refresh creators/channels and warm the newest posts, then bump the /// channel cache key so Jellyfin re-lists on the next browse. Found by type scanning. /// public class FloatplaneSyncTask : IScheduledTask, IConfigurableScheduledTask { private readonly CatalogService _catalog; private readonly ILogger _logger; public FloatplaneSyncTask(CatalogService catalog, ILogger logger) { _catalog = catalog; _logger = logger; } /// public string Name => "Refresh Floatplane catalogue"; /// public string Key => "FloatplaneSync"; /// public string Description => "Reloads subscribed creators, their channels and the newest videos from Floatplane."; /// public string Category => "Floatplane"; /// public bool IsHidden => false; /// public bool IsEnabled => true; /// public bool IsLogged => true; /// public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) { _logger.LogInformation("Floatplane sync started"); await _catalog.RefreshAsync(progress, cancellationToken).ConfigureAwait(false); _logger.LogInformation("Floatplane sync finished: {Creators} creators, generation {Gen}", _catalog.Creators.Count, _catalog.Generation); } /// public IEnumerable GetDefaultTriggers() { var hours = Math.Clamp(Plugin.Instance?.Configuration.SyncIntervalHours ?? 6, 1, 168); return [ new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerStartup }, new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(hours).Ticks } ]; } }