Video-Converter-In-Blazor/BlazorApp1/Components/Pages/Home.razor
2025-01-31 11:16:42 +01:00

84 lines
2.0 KiB
Plaintext

@page "/"
@rendermode InteractiveServer
@using BlazorApp1.Handler.Interfaces
@using BlazorApp1.Helpers
@using BlazorApp1.Models
@using Microsoft.AspNetCore.Authorization
@inject IFileHandler FileHandler
@inject IVideoHandler VideoHandler
@attribute [Authorize]
<PageTitle>Auth</PageTitle>
<h1>You are authenticated</h1>
<AuthorizeView>
Hello @context.User.Identity?.Name!
</AuthorizeView>
<br/>
<label>1 Gb max allowed</label>
<EditForm Model="@File" OnSubmit="Upload">
<InputFile OnChange="OnFileSelected"></InputFile>
<InputSelect @bind-Value="Codec">
@foreach (FFOptionsCodecs codec in Enum.GetValues<FFOptionsCodecs>())
{
<option value="@codec">@codec</option>
}
</InputSelect>
<InputSelect @bind-Value="Filters">
@foreach (FFOptionsFilters filter in Enum.GetValues<FFOptionsFilters>())
{
<option value="@filter">@filter</option>
}
</InputSelect>
<button type="submit">Upload</button>
</EditForm>
<a href="/Videos/Final/@NewFilePath">Download new video</a>
@code
{
[SupplyParameterFromForm(FormName = "UploadFile")]
private FileInput? File { get; set; } = new();
private IBrowserFile? _browserFile;
private FFOptionsCodecs Codec { get; set; }
private FFOptionsFilters Filters { get; set; }
private string NewFilePath { get; set; } = "";
private void OnFileSelected(InputFileChangeEventArgs e)
{
_browserFile = e.File;
}
private async Task Upload()
{
if (_browserFile is null)
{
return;
}
await FileHandler.SaveFile(_browserFile);
string filePath = FileHandler.GetFileReference(_browserFile.Name);
VideoHandler.ConvertVideo(filePath, Codec, Filters, out string newFilePath);
await FileHandler.DeleteTempFile(filePath);
NewFilePath = newFilePath.GetFileNameFromPath();
}
public class FileInput
{
public IFormFile FileForm { get; set; }
}
}