#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;
///
/// Controller for managing file system directories.
///
[Route("[controller]")]
public class DirectoriesController : Controller
{
private readonly IApiHttpClient _apiHttpClient;
///
/// Initializes a new instance of the class.
///
/// Injected service for interactions with the API.
public DirectoriesController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
///
/// Gets the directories of .
///
/// The path for which to get the directories.
/// Whether to include hidden file system elements or not.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-directories")]
public async Task GetDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
IEnumerable response = await _apiHttpClient.GetAsync(
$"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = response });
}
///
/// Gets the directories of .
///
/// The path for which to get the directories.
/// Whether to include hidden file system elements or not.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-tree-directories")]
public async Task GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
IEnumerable response = await _apiHttpClient.GetAsync(
$"directories/get-tree-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = response });
}
///
/// Gets the tree of expanded directories leading up to , with the additional list of drives, and children of the last child directory.
///
/// The path for which to get the directory tree.
/// Whether to include hidden file system elements or not.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-directory-tree")]
public async Task GetDirectoryTree([FromQuery] string path, [FromQuery] bool includeFiles, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync($"directories/get-directory-tree?path={Uri.EscapeDataString(path)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = response });
}
}