Replaces MVC with FastEndpoints in Lumina.Presentation.Api

This commit is contained in:
BinaryAlley committed 2024-10-23 21:34:10 +03:00
1 parent b1a20716df
commit c7b8bc2f1c
519 files changed
+15329 -8539

No files matched your search

@@ -0,0 +1,81 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
/// <summary>
/// Controller for managing file system directories.
/// </summary>
[Route("[controller]")]
public class DirectoriesController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="DirectoriesController"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public DirectoriesController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Gets the directories of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the directories.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-directories")]
public async IAsyncEnumerable<DirectoryModel?> GetDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
{
IAsyncEnumerable<DirectoryModel?> response = _apiHttpClient.GetAsyncEnumerable<DirectoryModel>(
$"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
await foreach (DirectoryModel? directory in response)
{
if (cancellationToken.IsCancellationRequested)
yield break;
yield return directory;
}
}
/// <summary>
/// Gets the directories of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the directories.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-tree-directories")]
public async IAsyncEnumerable<FileSystemTreeNodeModel?> GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
{
IAsyncEnumerable<FileSystemTreeNodeModel?> response = _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>(
$"directories/get-tree-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
await foreach (FileSystemTreeNodeModel? directory in response)
{
if (cancellationToken.IsCancellationRequested)
yield break;
yield return directory;
}
}
/// <summary>
/// Gets the tree of expanded directories leading up to <paramref name="path"/>, with the additional list of drives, and children of the last child directory.
/// </summary>
/// <param name="path">The path for which to get the directory tree.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-directory-tree")]
public async Task<IActionResult> GetDirectoryTree([FromQuery] string path, [FromQuery] bool includeFiles, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>($"directories/get-directory-tree?path={Uri.EscapeDataString(path)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { tree = response } });
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
using Microsoft.AspNetCore.Mvc;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
/// <summary>
/// Controller for managing file system drives.
/// </summary>
[Route("[controller]")]
public class DrivesController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="DrivesController"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public DrivesController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Controller action for getting the list of all file system drives.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-drives")]
public async Task<IActionResult> GetDrives(CancellationToken cancellationToken)
{
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>($"drives/get-drives", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { drives = response } });
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
using Microsoft.AspNetCore.Mvc;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
/// <summary>
/// Controller for managing file systems.
/// </summary>
[Route("/file-system")]
public class FileSystemController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemController"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public FileSystemController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Gets the type of the file system.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-type")]
public async Task<IActionResult> GetType(CancellationToken cancellationToken)
{
FileSystemTypeModel response = await _apiHttpClient.GetAsync<FileSystemTypeModel>($"file-system/get-type", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { platformType = response.PlatformType.ToString() } });
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
/// <summary>
/// Controller for managing file system files.
/// </summary>
[Route("[controller]")]
public class FilesController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="FilesController"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public FilesController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Gets the files of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the files.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-tree-files")]
public async IAsyncEnumerable<FileSystemTreeNodeModel?> GetTreeFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
{
IAsyncEnumerable<FileSystemTreeNodeModel?> response = _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>(
$"files/get-tree-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
await foreach (FileSystemTreeNodeModel? file in response)
{
if (cancellationToken.IsCancellationRequested)
yield break;
yield return file;
}
}
/// <summary>
/// Gets the files of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the files.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-files")]
public async IAsyncEnumerable<FileModel?> GetFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
{
IAsyncEnumerable<FileModel?> response = _apiHttpClient.GetAsyncEnumerable<FileModel>(
$"files/get-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
await foreach (FileModel? file in response)
{
if (cancellationToken.IsCancellationRequested)
yield break;
yield return file;
}
}
}
@@ -0,0 +1,100 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
/// <summary>
/// Controller for managing file system paths.
/// </summary>
[Route("[controller]")]
public class PathController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="PathController"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public PathController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Gets the root of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the root.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-root")]
public async Task<IActionResult> GetPathRoot([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel response = await _apiHttpClient.GetAsync<PathSegmentModel>($"path/get-path-root?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { root = response } });
}
/// <summary>
/// Gets the path separator character of the file system.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-separator")]
public async Task<IActionResult> GetPathSeparator(CancellationToken cancellationToken)
{
PathSeparatorModel response = await _apiHttpClient.GetAsync<PathSeparatorModel>($"path/get-path-separator", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSeparator = response.Separator } });
}
/// <summary>
/// Gets the path separator character of the file system.
/// </summary>
/// <param name="path">The path for which to get the parent path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-path-parent")]
public async Task<IActionResult> GetPathParent([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync<PathSegmentModel[]>($"path/get-path-parent?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSegments = response } });
}
/// <summary>
/// Gets the path components of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path for which to get the path segments.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("split")]
public async Task<IActionResult> SplitPath([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync<PathSegmentModel[]>($"path/split?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSegments = response } });
}
/// <summary>
/// Validates the validity of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path to be validated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("validate")]
public async Task<IActionResult> ValidatePath([FromQuery] string path, CancellationToken cancellationToken)
{
PathValidModel response = await _apiHttpClient.GetAsync<PathValidModel>($"path/validate?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { isValid = response.IsValid } });
}
/// <summary>
/// Checks whether <paramref name="path"/> exists or not.
/// </summary>
/// <param name="path">The path to be checked.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("check-path-exists")]
public async Task<IActionResult> CheckPathExists([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
PathExistsModel response = await _apiHttpClient.GetAsync<PathExistsModel>($"path/check-path-exists?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { exists = response.Exists } });
}
}