Files
ersatztv/ErsatzTV/Pages/EmbyLibrariesEditor.razor
T
Jason DoveandGitHub 1c07df5bc3 use cancellation tokens in many places (#2350)
* use cancellation tokens everywhere

* more cancellation tokens
2025-08-27 03:20:35 +00:00

47 lines
2.1 KiB
Plaintext

@page "/media/sources/emby/{Id:int}/libraries"
@using ErsatzTV.Application.Emby
@using ErsatzTV.Application.MediaSources
@inject IMediator Mediator
@inject ChannelWriter<IScannerBackgroundServiceRequest> ScannerWorkerChannel
<RemoteMediaSourceLibrariesEditor
Id="@Id"
Name="Emby"
GetUpdateLibraryRequest="GetUpdateLibraryRequest"
GetLibrariesBySourceId="GetLibrariesBySourceId"
GetMediaSourceById="GetMediaSourceById"
SynchronizeLibraryByIdIfNeeded="SynchronizeLibraryByIdIfNeeded"/>
@code {
[Parameter]
public int Id { get; set; }
private IRequest<Either<BaseError, Unit>> GetUpdateLibraryRequest(List<RemoteMediaSourceLibraryEditViewModel> libraries) =>
new UpdateEmbyLibraryPreferences(
libraries.Map(l => new EmbyLibraryPreference(l.Id, l.ShouldSyncItems)).ToList());
private Task<List<RemoteMediaSourceLibraryEditViewModel>> GetLibrariesBySourceId(int mediaSourceId, CancellationToken cancellationToken) =>
Mediator.Send(new GetEmbyLibrariesBySourceId(Id), cancellationToken)
.Map(list => list.Map(ProjectToEditViewModel).OrderBy(x => x.MediaKind).ThenBy(x => x.Name).ToList());
private Task<Option<RemoteMediaSourceViewModel>> GetMediaSourceById(int mediaSourceId, CancellationToken cancellationToken) =>
Mediator.Send(new GetEmbyMediaSourceById(Id), cancellationToken)
.MapT(vm => new RemoteMediaSourceViewModel(vm.Id, vm.Name, vm.Address));
private RemoteMediaSourceLibraryEditViewModel ProjectToEditViewModel(EmbyLibraryViewModel library) => new()
{
Id = library.Id,
Name = library.Name,
MediaKind = library.MediaKind,
ShouldSyncItems = library.ShouldSyncItems
};
private async Task<Unit> SynchronizeLibraryByIdIfNeeded(RemoteMediaSourceLibrariesEditor.SynchronizeParameters parameters, CancellationToken cancellationToken)
{
await ScannerWorkerChannel.WriteAsync(new SynchronizeEmbyLibraries(parameters.MediaSourceId), cancellationToken);
await ScannerWorkerChannel.WriteAsync(new SynchronizeEmbyLibraryByIdIfNeeded(parameters.LibraryId), cancellationToken);
return Unit.Default;
}
}