mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 13:01:10 +00:00
Routes the file browser thumbnail requests through the authenticated Web proxy
This commit is contained in:
1 parent
a32f80337b
commit
f694882b46
15 files changed
+299
-35
No files matched your search
-2
@@ -7,14 +7,12 @@ namespace Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
/// <summary>
|
||||
/// Data transfer object for the runtime configuration of the file system browser component.
|
||||
/// </summary>
|
||||
/// <param name="ServerBasePath">The base URL of the remote API used for thumbnail retrieval.</param>
|
||||
/// <param name="ClientBasePath">The base URL of the Web application used for file system API calls.</param>
|
||||
/// <param name="Path">The initial path displayed by the file system browser.</param>
|
||||
/// <param name="ViewMode">The initial view mode of the file system browser.</param>
|
||||
/// <param name="IconSize">The initial icon size of the file system browser.</param>
|
||||
[DebuggerDisplay("Path: {Path}, ViewMode: {ViewMode}")]
|
||||
public sealed record ThemeFileSystemBrowserConfigurationDto(
|
||||
string ServerBasePath,
|
||||
string ClientBasePath,
|
||||
string Path,
|
||||
string ViewMode,
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for retrieving the thumbnail of a file system file.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path of the file for which the thumbnail is retrieved.</param>
|
||||
/// <param name="Quality">The quality to use for the thumbnail.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetThumbnailRequest(
|
||||
string? Path,
|
||||
int Quality
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Lumina.Presentation.Web.Common.Routes;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of remote API routes called by this Web application.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the thumbnail endpoints of the remote API.
|
||||
/// </summary>
|
||||
public static class Thumbnails
|
||||
{
|
||||
public const string GET_THUMBNAIL = "thumbnails/get-thumbnail";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Lumina.Presentation.Web.Common.Routes;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of routes defined in the Web application.
|
||||
/// </summary>
|
||||
public static partial class WebRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the thumbnail endpoints.
|
||||
/// </summary>
|
||||
public static class Thumbnails
|
||||
{
|
||||
public const string GET_THUMBNAIL = "thumbnails/api-get-thumbnail";
|
||||
}
|
||||
}
|
||||
+56
@@ -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
|
||||
|
||||
-1
@@ -97,7 +97,6 @@
|
||||
return;
|
||||
}
|
||||
await initFileSystemBrowser({
|
||||
serverBasePath: '@Model.ServerBasePath',
|
||||
clientBasePath: '@Model.ClientBasePath',
|
||||
path: '@Model.Path.Replace(@"\", @"\\")',
|
||||
viewMode: '@Model.ViewMode',
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
let explorerItemTemplate = null;
|
||||
let pathSegmentTemplate = null;
|
||||
|
||||
let serverBasePath;
|
||||
let clientBasePath;
|
||||
let _path;
|
||||
let pathSeparator = '/';
|
||||
@@ -113,7 +112,6 @@
|
||||
* @param {any} config The configuration of the file system browser, with the server and client base paths, the initial path, the initial view mode and icon size, and the optional theme asset URLs.
|
||||
*/
|
||||
async function initFileSystemBrowser(config) {
|
||||
serverBasePath = config.serverBasePath;
|
||||
clientBasePath = config.clientBasePath;
|
||||
iconBaseUrl = config.iconBaseUrl || '';
|
||||
fileIconsUrl = config.fileIconsUrl || '';
|
||||
@@ -1468,8 +1466,8 @@
|
||||
* @throws {Error} - Throws an error if the API call fails.
|
||||
*/
|
||||
async function getThumbnailApiCall(path, quality) {
|
||||
// fetch the thumbnail for the given item from the server
|
||||
const response = await fetch(`${serverBasePath}thumbnails/get-thumbnail?path=` + encodeURIComponent(path) + '&quality=' + quality, {
|
||||
// fetch the thumbnail for the given item from the server, through the Web application, which proxies the request with the authentication of the current user
|
||||
const response = await fetch(`${clientBasePath}thumbnails/api-get-thumbnail?path=` + encodeURIComponent(path) + '&quality=' + quality, {
|
||||
signal: abortController.signal // use the abort signal
|
||||
});
|
||||
if (!response.ok)
|
||||
|
||||
Reference in new issue
Block a user