@page "/ffmpeg/{Id:int}" @page "/ffmpeg/add" @using ErsatzTV.Application.Resolutions @using ErsatzTV.Application.Resolutions.Queries @using ErsatzTV.Application.FFmpegProfiles @using ErsatzTV.Application.FFmpegProfiles.Commands @using ErsatzTV.Application.FFmpegProfiles.Queries @using ErsatzTV.Core.FFmpeg @using Microsoft.AspNetCore.Components @using Microsoft.Extensions.Caching.Memory @inject NavigationManager _navigationManager @inject ILogger _logger @inject ISnackbar _snackbar @inject IMediator _mediator @inject IMemoryCache _memoryCache @(IsEdit ? "Edit FFmpeg Profile" : "Add FFmpeg Profile") General @foreach (ResolutionViewModel resolution in _resolutions) { @resolution.Name } Video @foreach (HardwareAccelerationKind hwAccel in Enum.GetValues()) { @hwAccel } @foreach (VaapiDriver driver in Enum.GetValues()) { @driver } @foreach (string device in _vaapiDevices) { @device } Audio @(IsEdit ? "Save Changes" : "Add Profile") @code { [Parameter] public int Id { get; set; } private FFmpegProfileEditViewModel _model = new(); private EditContext _editContext; private ValidationMessageStore _messageStore; private List _resolutions; private List _vaapiDevices; protected override async Task OnParametersSetAsync() { _resolutions = await _mediator.Send(new GetAllResolutions()); if (IsEdit) { Option profile = await _mediator.Send(new GetFFmpegProfileById(Id)); profile.Match( ffmpegProfileViewModel => _model = new FFmpegProfileEditViewModel(ffmpegProfileViewModel), () => _navigationManager.NavigateTo("404")); } else { _model = new FFmpegProfileEditViewModel(await _mediator.Send(new NewFFmpegProfile())); } _editContext = new EditContext(_model); _messageStore = new ValidationMessageStore(_editContext); if (!_memoryCache.TryGetValue("ffmpeg.render_devices", out List vaapiDevices)) { vaapiDevices = new List { "/dev/dri/renderD128" }; } _vaapiDevices = vaapiDevices.OrderBy(s => s).ToList(); } private bool IsEdit => Id != 0; private async Task HandleSubmitAsync() { _messageStore.Clear(); if (_editContext.Validate()) { Seq errorMessage = IsEdit ? (await _mediator.Send(_model.ToUpdate())).LeftToSeq() : (await _mediator.Send(_model.ToCreate())).LeftToSeq(); errorMessage.HeadOrNone().Match( error => { _snackbar.Add("Unexpected error saving ffmpeg profile"); _logger.LogError("Unexpected error saving ffmpeg profile: {Error}", error.Value); }, () => _navigationManager.NavigateTo("/ffmpeg")); } } }