#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Models.FileManagement;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Controllers.FileManagement;
///
/// Controller for managing file system paths.
///
[Route("[controller]")]
public class PathController : Controller
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IApiHttpClient _apiHttpClient;
#endregion
#region ====================================================================== CTOR =====================================================================================
///
/// Initializes a new instance of the class.
///
/// Injected service for interactions with the API.
public PathController(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
///
/// Gets the root of .
///
/// The path for which to get the root.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-root")]
public async Task GetPathRoot([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel response = await _apiHttpClient.GetAsync($"path/get-path-root?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { root = response } });
}
///
/// Gets the path separator character of the file system.
///
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-separator")]
public async Task GetPathSeparator(CancellationToken cancellationToken)
{
PathSeparatorModel response = await _apiHttpClient.GetAsync($"path/get-path-separator", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSeparator = response.Separator } });
}
///
/// Gets the path separator character of the file system.
///
/// The path for which to get the parent path.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-parent")]
public async Task GetPathParent([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync($"path/get-path-parent?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSegments = response } });
}
///
/// Gets the path components of .
///
/// The path for which to get the path segments.
/// Cancellation token that can be used to stop the execution.
[HttpGet("split")]
public async Task SplitPath([FromQuery] string path, CancellationToken cancellationToken)
{
PathSegmentModel[] response = await _apiHttpClient.GetAsync($"path/split?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { pathSegments = response } });
}
///
/// Validates the validity of .
///
/// The path to be validated.
/// Cancellation token that can be used to stop the execution.
[HttpGet("validate")]
public async Task ValidatePath([FromQuery] string path, CancellationToken cancellationToken)
{
PathValidModel response = await _apiHttpClient.GetAsync($"path/validate?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { isValid = response.IsValid } });
}
///
/// Checks whether exists or not.
///
/// The path to be checked.
/// Whether to include hidden file system elements or not.
/// Cancellation token that can be used to stop the execution.
[HttpGet("check-path-exists")]
public async Task CheckPathExists([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
{
PathExistsModel response = await _apiHttpClient.GetAsync($"path/check-path-exists?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
return Json(new { success = true, data = new { exists = response.Exists } });
}
#endregion
}