Routes the file browser thumbnail requests through the authenticated Web proxy

This commit is contained in:
BinaryAlley committed 2026-08-29 16:35:12 +03:00
1 parent a32f80337b
commit f694882b46
15 files changed
+299 -35

No files matched your search

@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
using Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Thumbnails;
using Lumina.Presentation.Web.Common.Routes;
using Lumina.Presentation.Web.Core.Endpoints.Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Core.Endpoints.FileSystemManagement.Thumbnails.GetThumbnail;
/// <summary>
/// API endpoint for the <c>/thumbnails/api-get-thumbnail</c> route.
/// </summary>
public class GetThumbnailEndpoint : BaseEndpoint<GetThumbnailRequest, IResult>
{
private readonly IApiHttpClient _apiHttpClient;
/// <summary>
/// Initializes a new instance of the <see cref="GetThumbnailEndpoint"/> class.
/// </summary>
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
public GetThumbnailEndpoint(IApiHttpClient apiHttpClient)
{
_apiHttpClient = apiHttpClient;
}
/// <summary>
/// Configures the endpoint.
/// </summary>
public override void Configure()
{
base.Configure();
Verbs(Http.GET);
Routes(WebRoutes.Thumbnails.GET_THUMBNAIL);
DontAutoTag();
Options(options => options.WithTags("Thumbnails"));
}
/// <summary>
/// Retrieves the thumbnail of the file located at the path identified by the request.
/// </summary>
/// <param name="request">The request containing the file system path of the file for which to get the thumbnail.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetThumbnailRequest request, CancellationToken cancellationToken)
{
// the thumbnail is proxied through the Web application, so that the request carries the authentication of the current user
BlobDataDto blob = await _apiHttpClient.GetBlobAsync($"{ApiRoutes.Thumbnails.GET_THUMBNAIL}?path={Uri.EscapeDataString(request.Path!)}&quality={request.Quality}", cancellationToken).ConfigureAwait(false);
return Results.File(blob.Data, blob.ContentType);
}
}
@@ -119,11 +119,10 @@ public class ThemeFileSystemBrowserRenderer
{
string initConfigJson = JsonSerializer.Serialize(new
{
configuration.ServerBasePath,
configuration.ClientBasePath,
configuration.Path,
configuration.ViewMode,
configuration.IconSize,
ClientBasePath = configuration.ClientBasePath,
Path = configuration.Path,
ViewMode = configuration.ViewMode,
IconSize = configuration.IconSize,
IconBaseUrl = $"{assetBase}/images/icons",
FileIconsUrl = $"{assetBase}/file-icons.json"
}, s_camelCaseJsonOptions);
@@ -1,11 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.DTO.Configuration;
using Lumina.Presentation.Web.Common.DTO.Themes;
using Lumina.Presentation.Web.Common.Enums.FileSystem;
using Lumina.Presentation.Web.Common.Primitives;
using Lumina.Presentation.Web.Core.Themes;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -19,17 +17,14 @@ namespace Lumina.Presentation.Web.Core.ViewComponents;
/// </summary>
public class FileSystemBrowserViewComponent : ViewComponent
{
private readonly ServerConfigurationDto _serverConfiguration;
private readonly ThemeFileSystemBrowserRenderer _renderer;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemBrowserViewComponent"/> class.
/// </summary>
/// <param name="serverConfigurationOptions">Injected service for retrieving <see cref="ServerConfigurationDto"/>.</param>
/// <param name="renderer">Injected renderer of the themed file system browser component.</param>
public FileSystemBrowserViewComponent(IOptions<ServerConfigurationDto> serverConfigurationOptions, ThemeFileSystemBrowserRenderer renderer)
public FileSystemBrowserViewComponent(ThemeFileSystemBrowserRenderer renderer)
{
_serverConfiguration = serverConfigurationOptions.Value;
_renderer = renderer;
}
@@ -40,7 +35,6 @@ public class FileSystemBrowserViewComponent : ViewComponent
public async Task<IViewComponentResult> InvokeAsync()
{
ThemeFileSystemBrowserConfigurationDto configuration = new(
ServerBasePath: $"{_serverConfiguration.BaseAddress}:{_serverConfiguration.Port}/api/v{_serverConfiguration.ApiVersion}/",
ClientBasePath: "http://localhost:5012/", // TODO: take from appsettings or environment
Path: RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? @"/" : @"C:\Users\",
ViewMode: FileSystemViewMode.List.ToString().ToLower(),
@@ -53,7 +47,6 @@ public class FileSystemBrowserViewComponent : ViewComponent
return View(new
{
Path = configuration.Path,
ServerBasePath = configuration.ServerBasePath,
ClientBasePath = configuration.ClientBasePath,
ViewMode = configuration.ViewMode,
IconSize = configuration.IconSize
@@ -97,7 +97,6 @@
return;
}
await initFileSystemBrowser({
serverBasePath: '@Model.ServerBasePath',
clientBasePath: '@Model.ClientBasePath',
path: '@Model.Path.Replace(@"\", @"\\")',
viewMode: '@Model.ViewMode',