using System.Threading.Channels; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Repositories; namespace ErsatzTV.Application.Jellyfin; public class SynchronizeJellyfinMediaSourcesHandler : IRequestHandler>> { private readonly ChannelWriter _scannerWorkerChannel; private readonly IMediaSourceRepository _mediaSourceRepository; public SynchronizeJellyfinMediaSourcesHandler( IMediaSourceRepository mediaSourceRepository, ChannelWriter scannerWorkerChannel) { _mediaSourceRepository = mediaSourceRepository; _scannerWorkerChannel = scannerWorkerChannel; } public async Task>> Handle( SynchronizeJellyfinMediaSources request, CancellationToken cancellationToken) { List mediaSources = await _mediaSourceRepository.GetAllJellyfin(); foreach (JellyfinMediaSource mediaSource in mediaSources) { await _scannerWorkerChannel.WriteAsync(new SynchronizeJellyfinAdminUserId(mediaSource.Id), cancellationToken); await _scannerWorkerChannel.WriteAsync(new SynchronizeJellyfinLibraries(mediaSource.Id), cancellationToken); } return mediaSources; } }