From b4ce6bbb4218978db7e1fc514e81aa1315bb4250 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 18 Mar 2025 14:29:09 -0400 Subject: [PATCH] add caching support for ImageUrl --- Oqtane.Server/Controllers/FileController.cs | 5 +++++ Oqtane.Shared/Shared/Utilities.cs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 4bdb8a90..7ead95d7 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -23,6 +23,7 @@ using System.IO.Compression; using Oqtane.Services; using Microsoft.Extensions.Primitives; using Microsoft.AspNetCore.Http.HttpResults; +using Microsoft.Net.Http.Headers; // ReSharper disable StringIndexOfIsCultureSpecific.1 @@ -735,6 +736,10 @@ namespace Oqtane.Controllers } if (!string.IsNullOrEmpty(imagepath)) { + if (!string.IsNullOrEmpty(file.Folder.CacheControl)) + { + HttpContext.Response.Headers.Append(HeaderNames.CacheControl, value: file.Folder.CacheControl); + } return PhysicalFile(imagepath, file.GetMimeType()); } else diff --git a/Oqtane.Shared/Shared/Utilities.cs b/Oqtane.Shared/Shared/Utilities.cs index 826fac70..1a1fb8c3 100644 --- a/Oqtane.Shared/Shared/Utilities.cs +++ b/Oqtane.Shared/Shared/Utilities.cs @@ -121,6 +121,17 @@ namespace Oqtane.Shared return $"{alias?.BaseUrl}{url}{Constants.ImageUrl}{fileId}/{width}/{height}/{mode}/{position}/{background}/{rotate}/{recreate}"; } + public static string ImageUrl(Alias alias, string folderpath, string filename, int width, int height, string mode, string position, string background, int rotate, string format, bool recreate) + { + var aliasUrl = (alias != null && !string.IsNullOrEmpty(alias.Path)) ? "/" + alias.Path : ""; + mode = string.IsNullOrEmpty(mode) ? "crop" : mode; + position = string.IsNullOrEmpty(position) ? "center" : position; + background = string.IsNullOrEmpty(background) ? "transparent" : background; + format = string.IsNullOrEmpty(format) ? "png" : format; + var querystring = $"?width={width}&height={height}&mode={mode}&position={position}&background={background}&rotate={rotate}&format={format}&recreate={recreate}"; + return $"{alias?.BaseUrl}{aliasUrl}{Constants.FileUrl}{folderpath.Replace("\\", "/")}{filename}{querystring}"; + } + public static string TenantUrl(Alias alias, string url) { url = (!url.StartsWith("/")) ? "/" + url : url;