From 4890504fb9643750ce26d6639d0c908aa0e853fc Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Sun, 28 Jul 2024 01:17:30 +0200 Subject: [PATCH] fix: append base path to image urls - Append the base path to image urls served by the plugin, instead of overwriting the existing base path set on the base url. --- Shokofin/API/Models/Image.cs | 2 +- Shokofin/Web/ImageHostUrl.cs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Shokofin/API/Models/Image.cs b/Shokofin/API/Models/Image.cs index 5a9f9e2c..6bc33cbe 100644 --- a/Shokofin/API/Models/Image.cs +++ b/Shokofin/API/Models/Image.cs @@ -69,7 +69,7 @@ public virtual bool IsAvailable /// /// The image URL public string ToURLString() - => new Uri(new Uri(Web.ImageHostUrl.Value), $"/Plugin/Shokofin/Host/Image/{Source}/{Type}/{ID}").ToString(); + => new Uri(new Uri(Web.ImageHostUrl.BaseUrl), $"{Web.ImageHostUrl.BasePath}/Plugin/Shokofin/Host/Image/{Source}/{Type}/{ID}").ToString(); } /// diff --git a/Shokofin/Web/ImageHostUrl.cs b/Shokofin/Web/ImageHostUrl.cs index edd93d7e..71bb453c 100644 --- a/Shokofin/Web/ImageHostUrl.cs +++ b/Shokofin/Web/ImageHostUrl.cs @@ -12,9 +12,14 @@ namespace Shokofin.Web; public class ImageHostUrl : IAsyncActionFilter { /// - /// The current image host url base to use. + /// The current image host base url to use. /// - public static string Value { get; private set; } = "http://localhost:8096/"; + public static string BaseUrl { get; private set; } = "http://localhost:8096/"; + + /// + /// The current image host base path to use. + /// + public static string BasePath { get; private set; } = "/"; private readonly object LockObj = new(); @@ -26,12 +31,16 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE var uriBuilder = new UriBuilder(request.Scheme, request.Host.Host, request.Host.Port ?? (request.Scheme == "https" ? 443 : 80), $"{request.PathBase}{request.Path}", request.QueryString.HasValue ? request.QueryString.Value : null); var result = RemoteImagesRegex.Match(uriBuilder.Path); if (result.Success) { - uriBuilder.Path = result.Length == uriBuilder.Path.Length ? "/" : uriBuilder.Path[..^result.Length] + "/"; + var path = result.Length == uriBuilder.Path.Length ? "" : uriBuilder.Path[..^result.Length]; + uriBuilder.Path = ""; uriBuilder.Query = ""; var uri = uriBuilder.ToString(); - lock (LockObj) - if (!string.Equals(uri, Value)) - Value = uri; + lock (LockObj) { + if (!string.Equals(uri, BaseUrl)) + BaseUrl = uri; + if (!string.Equals(path, BasePath)) + BasePath = path; + } } await next(); }