mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 03:11:10 +00:00
Removes unused file system API endpoints
This commit is contained in:
1 parent
8c579cd4bd
commit
532322eab2
35 files changed
-3111
No files matched your search
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetDirectoryTreeRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetDirectoryTreeRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetDirectoryTreeQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetDirectoryTreeQuery ToQuery(this GetDirectoryTreeRequest request)
|
||||
{
|
||||
return new GetDirectoryTreeQuery(request.Path, request.IncludeFiles, request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetTreeDirectoriesRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetTreeDirectoriesRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetTreeDirectoriesQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetTreeDirectoriesQuery ToQuery(this GetTreeDirectoriesRequest request)
|
||||
{
|
||||
return new GetTreeDirectoriesQuery(request.Path, request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
#endregion
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the tree of directories of a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the tree of directories.</param>
|
||||
/// <param name="IncludeFiles">Whether to include files in the directory tree or not.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetDirectoryTreeQuery(
|
||||
string? Path,
|
||||
bool IncludeFiles,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get a directory tree.
|
||||
/// </summary>
|
||||
public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IPathService _pathService;
|
||||
private readonly IDriveService _driveService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="driveService">Injected service for handling file system drives.</param>
|
||||
/// <param name="directoryService">Injected service for handling directories.</param>
|
||||
/// <param name="fileService">Injected service for handling files.</param>
|
||||
/// <param name="pathService">Injected service for handling file system paths.</param>
|
||||
public GetDirectoryTreeQueryHandler(IDriveService driveService, IDirectoryService directoryService, IFileService fileService, IPathService pathService)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_fileService = fileService;
|
||||
_pathService = pathService;
|
||||
_driveService = driveService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tree of expanded directories leading up to the requested path, with the additional list of drives, and children of the last child directory.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDirectoryTreeQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
List<FileSystemTreeNodeResponse> result = [];
|
||||
// retrieve the list of drives
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> getDrivesResult = GetDrives();
|
||||
if (getDrivesResult.IsError)
|
||||
return getDrivesResult.Errors;
|
||||
result.AddRange(getDrivesResult.Value);
|
||||
|
||||
ErrorOr<IEnumerable<PathSegment>> pathPartsResults = _pathService.ParsePath(request.Path!);
|
||||
if (pathPartsResults.IsError)
|
||||
return pathPartsResults.Errors;
|
||||
|
||||
List<PathSegment> pathParts = pathPartsResults.Value.ToList();
|
||||
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse? currentNode, request.IncludeHiddenElements);
|
||||
if (buildDirectoryTreeResult.IsError)
|
||||
return buildDirectoryTreeResult.Errors;
|
||||
|
||||
// add subdirectories of the last directory node
|
||||
ErrorOr<Success> loadChildrenResult = LoadChildren(currentNode, request.IncludeFiles, request.IncludeHiddenElements);
|
||||
if (loadChildrenResult.IsError)
|
||||
return loadChildrenResult.Errors;
|
||||
return await ValueTask.FromResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root drives (on Windows), or an empty list on Unix-based systems.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing a list of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> GetDrives()
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemItem>> getDrivesResult = _driveService.GetDrives();
|
||||
if (getDrivesResult.IsError)
|
||||
return getDrivesResult.Errors;
|
||||
return ErrorOrFactory.From(getDrivesResult.Value.ToTreeNodeResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the tree of directories based on the parsed path parts.
|
||||
/// </summary>
|
||||
/// <param name="drives">The list of available drives.</param>
|
||||
/// <param name="pathParts">The list of parsed path segments (directories).</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing a list of <see cref="FileSystemTreeNodeResponse"/> representing the directory tree, or an error message.
|
||||
/// </returns>
|
||||
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> BuildDirectoryTree(List<FileSystemTreeNodeResponse> drives, List<PathSegment> pathParts, out FileSystemTreeNodeResponse currentNode, bool includeHiddenElements = true)
|
||||
{
|
||||
// find the root drive that matches the first part of the path
|
||||
FileSystemTreeNodeResponse drive = drives.First(drive => drive.Name.Contains(pathParts[0].Name));
|
||||
drive.IsExpanded = true;
|
||||
currentNode = drive;
|
||||
string currentPath = pathParts[0].Name;
|
||||
|
||||
// traverse the remaining path parts to build the tree structure
|
||||
for (int i = 1; i < pathParts.Count; i++)
|
||||
{
|
||||
ErrorOr<string> combinedPathResult = _pathService.CombinePath(currentPath, pathParts[i].Name);
|
||||
if (combinedPathResult.IsError)
|
||||
return combinedPathResult.Errors;
|
||||
if (_pathService.Exists(combinedPathResult.Value, includeHiddenElements))
|
||||
{
|
||||
|
||||
currentPath = combinedPathResult.Value;
|
||||
// create a new node for the directory and add it as a child of the current node
|
||||
FileSystemTreeNodeResponse newNode = new()
|
||||
{
|
||||
Path = currentPath,
|
||||
Name = pathParts[i].Name,
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true
|
||||
};
|
||||
currentNode.Children.Add(newNode);
|
||||
currentNode = newNode; // move to the new node
|
||||
}
|
||||
}
|
||||
return new List<FileSystemTreeNodeResponse> { drive };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the child directories and files of the specified directory node.
|
||||
/// </summary>
|
||||
/// <param name="node">The directory node to load children for.</param>
|
||||
/// <param name="includeFiles">Whether to include files in the directories or not.</param>
|
||||
/// <returns>A result indicating a successful operation, or an error message.</returns>
|
||||
private ErrorOr<Success> LoadChildren(FileSystemTreeNodeResponse node, bool includeFiles, bool includeHiddenElements)
|
||||
{
|
||||
// get subdirectories under the current node's path
|
||||
ErrorOr<IEnumerable<Directory>> getSubDirectoriesResult = _directoryService.GetSubdirectories(node.Path, includeHiddenElements);
|
||||
if (getSubDirectoriesResult.IsError)
|
||||
return getSubDirectoriesResult.Errors;
|
||||
// add each subdirectory as a child node of the current directory
|
||||
foreach (Directory subDirectory in getSubDirectoriesResult.Value ?? [])
|
||||
{
|
||||
FileSystemTreeNodeResponse subDirNode = new()
|
||||
{
|
||||
Name = subDirectory.Name,
|
||||
Path = subDirectory.Id.Path,
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = false
|
||||
};
|
||||
node.Children.Add(subDirNode);
|
||||
}
|
||||
if (includeFiles)
|
||||
{
|
||||
// get files under the current node's path
|
||||
ErrorOr<IEnumerable<File>> getFilesResult = _fileService.GetFiles(node.Path, includeHiddenElements);
|
||||
if (getFilesResult.IsError)
|
||||
return getFilesResult.Errors;
|
||||
// add each file as a child node of the current directory
|
||||
foreach (File file in getFilesResult.Value)
|
||||
{
|
||||
FileSystemTreeNodeResponse fileNode = new()
|
||||
{
|
||||
Name = file.Name,
|
||||
Path = file.Id.Path,
|
||||
ItemType = FileSystemItemType.File,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = true
|
||||
};
|
||||
node.Children.Add(fileNode);
|
||||
}
|
||||
}
|
||||
node.ChildrenLoaded = true;
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDirectoryTreeQuery"/>.
|
||||
/// </summary>
|
||||
public class GetDirectoryTreeQueryValidator : AbstractValidator<GetDirectoryTreeQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoryTreeQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of directories at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of directories.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetTreeDirectoriesQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all directories.
|
||||
/// </summary>
|
||||
public class GetTreeDirectoriesQueryHandler : IRequestHandler<GetTreeDirectoriesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="directoryService">Injected service for handling directories.</param>
|
||||
public GetTreeDirectoriesQueryHandler(IDirectoryService directoryService)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of directories at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="request">The query containing the requested path.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeDirectoriesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<Directory>> getSubdirectoriesResult = _directoryService.GetSubdirectories(request.Path!, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(getSubdirectoriesResult.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetTreeDirectoriesQuery"/>.
|
||||
/// </summary>
|
||||
public class GetTreeDirectoriesQueryValidator : AbstractValidator<GetTreeDirectoriesQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get the tree of directories that make up a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file system path for which to get the directory tree. Required.</param>
|
||||
/// <param name="IncludeFiles">Whether to include files along the directories or not. Optional.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden file system elements or not. Optional.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetDirectoryTreeRequest(
|
||||
string? Path,
|
||||
bool IncludeFiles,
|
||||
bool IncludeHiddenElements
|
||||
);
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get the directories of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file system path for which to get the directory tree. Required.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden file system elements or not. Optional.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetTreeDirectoriesRequest(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
);
|
||||
-2
@@ -10,8 +10,6 @@ public static partial class ApiRoutes
|
||||
/// </summary>
|
||||
public static class Directories
|
||||
{
|
||||
public const string GET_DIRECTORY_TREE = "/directories/get-directory-tree";
|
||||
public const string GET_TREE_DIRECTORIES = "/directories/get-tree-directories";
|
||||
public const string GET_DIRECTORIES = "/directories/get-directories";
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Common.Routes.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/directories/get-directory-tree</c> route.
|
||||
/// </summary>
|
||||
public class GetDirectoryTreeEndpoint : BaseEndpoint<GetDirectoryTreeRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetDirectoryTreeEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Directories.GET_DIRECTORY_TREE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tree of expanded directories leading up to the path stored in <paramref name="request"/>, with the additional list of drives, and children of the last child directory.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the file system path for for which to get the directory tree.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetDirectoryTreeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetDirectoryTreeEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoryTreeEndpointSummary : Summary<GetDirectoryTreeEndpoint, GetDirectoryTreeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoryTreeEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the directory tree structure for a specified file system path.";
|
||||
Description = "Returns a hierarchical view of the directory tree, with options to include files and hidden elements.";
|
||||
|
||||
ExampleRequest = new GetDirectoryTreeRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeFiles: true,
|
||||
IncludeHiddenElements: true
|
||||
);
|
||||
RequestExamples.Add(new RequestExample(new GetDirectoryTreeRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeFiles: false,
|
||||
IncludeHiddenElements: false
|
||||
)));
|
||||
RequestExamples.Add(new RequestExample(new GetDirectoryTreeRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeFiles: true,
|
||||
IncludeHiddenElements: false
|
||||
)));
|
||||
RequestExamples.Add(new RequestExample(new GetDirectoryTreeRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeFiles: false,
|
||||
IncludeHiddenElements: true
|
||||
)));
|
||||
|
||||
RequestParam(r => r.Path, "The file system path for which to get the directory tree. Required.");
|
||||
RequestParam(r => r.IncludeFiles, "Whether to include files along the directories or not. Optional.");
|
||||
RequestParam(r => r.IncludeHiddenElements, "Whether to include hidden file system elements or not. Optional.");
|
||||
|
||||
Response(200, "The directory tree structure for the specified path.",
|
||||
example: new FileSystemTreeNodeResponse[] {
|
||||
new()
|
||||
{
|
||||
Path = "/",
|
||||
Name = "The Lord of the Rings - The Fellowship of the Ring (2001)",
|
||||
ItemType = FileSystemItemType.Root,
|
||||
IsExpanded = true,
|
||||
ChildrenLoaded = true,
|
||||
Children =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Path = "/media/",
|
||||
Name = "media",
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true,
|
||||
ChildrenLoaded = true,
|
||||
Children =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Path = "/media/movies/",
|
||||
Name = "movies",
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true,
|
||||
ChildrenLoaded = true,
|
||||
Children =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Path = "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/",
|
||||
Name = "The Lord of the Rings - The Fellowship of the Ring (2001)",
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true,
|
||||
ChildrenLoaded = true,
|
||||
Children =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Path = "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/Extras/",
|
||||
Name = "Extras",
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = false,
|
||||
Children = []
|
||||
},
|
||||
new()
|
||||
{
|
||||
Path = "/media/movies/The Matrix (1999)/The Matrix.mkv",
|
||||
Name = "The Matrix.mkv",
|
||||
ItemType = FileSystemItemType.File,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = false,
|
||||
Children = []
|
||||
},
|
||||
new()
|
||||
{
|
||||
Path = "/media/movies/The Matrix (1999)/The Matrix.en.srt",
|
||||
Name = "The Matrix.en.srt",
|
||||
ItemType = FileSystemItemType.File,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = false,
|
||||
Children = []
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
});
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/directories/get-directory-tree"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/directories/get-directory-tree"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/directories/get-directory-tree"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the provided path does not exist, or the current user doesn't have permission to access it.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "UnauthorizedAccess",
|
||||
instance = "/api/v1/directories/get-directory-tree",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/directories/get-directory-tree",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PathCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-839f81e411d7eb91ed5aa91e56b00bbb-7c8bd5dfabdaf2dc-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Common.Routes.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/directories/get-tree-directories</c> route.
|
||||
/// </summary>
|
||||
public class GetTreeDirectoriesEndpoint : BaseEndpoint<GetTreeDirectoriesRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetTreeDirectoriesEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Directories.GET_TREE_DIRECTORIES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directories of the path stored in <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the file system path for which to get the directories.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetTreeDirectoriesRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetTreeDirectoriesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesEndpointSummary : Summary<GetTreeDirectoriesEndpoint, GetTreeDirectoriesRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the directory tree structure for the specified file system path.";
|
||||
Description = "Returns the directory tree structure, with an option to include hidden file system elements.";
|
||||
|
||||
ExampleRequest = new GetTreeDirectoriesRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeHiddenElements: true
|
||||
);
|
||||
RequestExamples.Add(new RequestExample(new GetTreeDirectoriesRequest(
|
||||
Path: "/media/movies/",
|
||||
IncludeHiddenElements: false
|
||||
)));
|
||||
|
||||
RequestParam(r => r.Path, "The file system path for which to get the directory tree. Required.");
|
||||
RequestParam(r => r.IncludeHiddenElements, "Whether to include hidden file system elements or not. Optional.");
|
||||
|
||||
Response(200, "The directory tree structure is returned.",
|
||||
example: new FileSystemTreeNodeResponse[] {
|
||||
new() { Path = "/media/movies/The Matrix (1999)/", Name = "The Matrix (1999)", ItemType = FileSystemItemType.Directory, IsExpanded = false, ChildrenLoaded = false, Children = [] },
|
||||
new() { Path = "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/", Name = "The Lord of the Rings - The Fellowship of the Ring (2001)", ItemType = FileSystemItemType.Directory, IsExpanded = false, ChildrenLoaded = false, Children = [] },
|
||||
});
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/directories/get-tree-directories"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/directories/get-tree-directories"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/directories/get-tree-directories"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the provided path does not exist, or the current user doesn't have permission to access it.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "UnauthorizedAccess",
|
||||
instance = "/api/v1/directories/get-tree-directories",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/directories/get-tree-directories",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PathCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-839f81e411d7eb91ed5aa91e56b00bbb-7c8bd5dfabdaf2dc-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -42,34 +42,4 @@ public class DirectoriesController : Controller
|
||||
$"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <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("api-get-tree-directories")]
|
||||
public async Task<IActionResult> GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: check if it's really used
|
||||
IEnumerable<FileSystemTreeNodeModel> response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
|
||||
$"directories/get-tree-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <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("api-get-directory-tree")]
|
||||
public async Task<IActionResult> GetDirectoryTree([FromQuery] string path, [FromQuery] bool includeFiles, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: check if it's really used
|
||||
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
|
||||
$"directories/get-directory-tree?path={Uri.EscapeDataString(path)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}", cancellationToken).ConfigureAwait(false);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
}
|
||||
@@ -126,8 +126,6 @@ EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "directories", "directories", "{FBD8915E-DFE2-4C16-8B47-64383AB0719D}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\docs\technical\requests\file-system-management\directories\GetDirectories.http = ..\docs\technical\requests\file-system-management\directories\GetDirectories.http
|
||||
..\docs\technical\requests\file-system-management\directories\GetDirectoryTree.http = ..\docs\technical\requests\file-system-management\directories\GetDirectoryTree.http
|
||||
..\docs\technical\requests\file-system-management\directories\GetTreeDirectories.http = ..\docs\technical\requests\file-system-management\directories\GetTreeDirectories.http
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "drives", "drives", "{DB498346-5F46-49FC-B2E9-8239C56791FF}"
|
||||
|
||||
Reference in new issue
Block a user