diff --git a/Directory.Build.props b/Directory.Build.props index b02f91e..1cc7d55 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.0.0.5 - 1.0.0.5 - 1.0.0.5 + 1.0.0.6 + 1.0.0.6 + 1.0.0.6 diff --git a/Jellyfin.Plugin.Request/Api/RequestController.cs b/Jellyfin.Plugin.Request/Api/RequestController.cs index bedd4a4..cbeaafd 100644 --- a/Jellyfin.Plugin.Request/Api/RequestController.cs +++ b/Jellyfin.Plugin.Request/Api/RequestController.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Jellyfin.Data; using Jellyfin.Database.Implementations.Enums; using Jellyfin.Plugin.Request.Configuration; +using Jellyfin.Plugin.Request.Hosting; using Jellyfin.Plugin.Request.Storage; using Jellyfin.Plugin.Request.Tmdb; using MediaBrowser.Controller.Library; @@ -79,6 +80,20 @@ public sealed class RequestController : ControllerBase return EmbeddedFile("Web.requestPage.html", "text/html; charset=utf-8"); } + /// + /// File Transformation endpoint: injects nav-loader.js into jellyfin-web index.html. + /// Must stay anonymous because File Transformation calls it without auth. + /// + /// Current file contents. + /// Transformed HTML body. + [HttpPost("TransformIndexHtml")] + [AllowAnonymous] + public ContentResult TransformIndexHtml([FromBody] IndexHtmlPatchPayload payload) + { + var html = WebNavInjector.InjectHtml(payload?.Contents ?? string.Empty); + return Content(html, "text/html; charset=utf-8"); + } + /// /// Serves plugin web assets. /// diff --git a/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs b/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs index 9edc777..38502c2 100644 --- a/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs +++ b/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs @@ -1,12 +1,17 @@ +using System.Text.Json.Serialization; +using Newtonsoft.Json; + namespace Jellyfin.Plugin.Request.Hosting; /// -/// Payload shape expected by the File Transformation callback. +/// Payload shape expected by the File Transformation callback/endpoint. /// public sealed class IndexHtmlPatchPayload { /// /// Gets or sets the current file contents. /// + [JsonProperty("contents")] + [JsonPropertyName("contents")] public string Contents { get; set; } = string.Empty; } diff --git a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs index f62d8d8..2810562 100644 --- a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs +++ b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs @@ -18,9 +18,14 @@ namespace Jellyfin.Plugin.Request.Hosting; /// public sealed class WebNavInjector : IHostedService { - private const string LoaderSrc = "/Requests/Assets/nav-loader.js"; + /// + /// Script URL injected into jellyfin-web index.html. + /// + public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.6"; + private const string MarkerStart = ""; private const string MarkerEnd = ""; + private const string TransformationEndpoint = "/Requests/TransformIndexHtml"; private static readonly Guid TransformationId = Guid.Parse("11c08950-c4bb-484d-89ff-205b3724416b"); private readonly IServerApplicationPaths _applicationPaths; @@ -43,12 +48,14 @@ public sealed class WebNavInjector : IHostedService { if (TryRegisterFileTransformation()) { - _logger.LogInformation("Request nav loader registered with File Transformation for index.html."); + _logger.LogInformation( + "Request nav loader registered with File Transformation (callback + {Endpoint}).", + TransformationEndpoint); return Task.CompletedTask; } _logger.LogWarning( - "File Transformation plugin was not found. Install it from https://www.iamparadox.dev/jellyfin/plugins/manifest.json for reliable Request tab injection. Falling back to disk patch."); + "File Transformation plugin was not found yet. Install/enable it from https://www.iamparadox.dev/jellyfin/plugins/manifest.json. Falling back to disk patch and retrying registration."); try { @@ -73,14 +80,25 @@ public sealed class WebNavInjector : IHostedService } /// - /// File Transformation callback: injects the nav-loader script tag into index.html contents. + /// File Transformation reflection callback. /// - /// Current file contents. + /// Current file contents wrapper. /// Transformed HTML. - public static string InjectNavLoader(IndexHtmlPatchPayload payload) + public static string InjectNavLoader(JObject payload) { - var html = payload?.Contents ?? string.Empty; - if (html.Contains(LoaderSrc, StringComparison.Ordinal) + var html = payload?["contents"]?.ToString() ?? string.Empty; + return InjectHtml(html); + } + + /// + /// Injects the nav-loader script tag into index.html contents. + /// + /// Current HTML. + /// Transformed HTML. + public static string InjectHtml(string html) + { + html ??= string.Empty; + if (html.Contains("/Requests/Assets/nav-loader.js", StringComparison.Ordinal) || html.Contains(MarkerStart, StringComparison.Ordinal)) { return html; @@ -95,11 +113,12 @@ public sealed class WebNavInjector : IHostedService private async Task RetryRegisterAsync(CancellationToken cancellationToken) { - for (var attempt = 1; attempt <= 10; attempt++) + for (var attempt = 1; attempt <= 12; attempt++) { try { - await Task.Delay(TimeSpan.FromSeconds(3 * attempt), cancellationToken).ConfigureAwait(false); + await Task.Delay(TimeSpan.FromSeconds(Math.Min(3 * attempt, 20)), cancellationToken) + .ConfigureAwait(false); } catch (OperationCanceledException) { @@ -116,7 +135,7 @@ public sealed class WebNavInjector : IHostedService } _logger.LogWarning( - "File Transformation still unavailable after retries. Use scripts/install-web-loader.sh|.ps1 if the Request tab is missing."); + "File Transformation still unavailable after retries. Request tab will not appear until File Transformation is installed and Jellyfin is restarted."); } private bool TryRegisterFileTransformation() @@ -125,27 +144,33 @@ public sealed class WebNavInjector : IHostedService { Assembly? fileTransformationAssembly = AssemblyLoadContext.All .SelectMany(context => context.Assemblies) - .FirstOrDefault(assembly => assembly.FullName?.Contains(".FileTransformation", StringComparison.OrdinalIgnoreCase) == true); + .FirstOrDefault(assembly => + assembly.FullName?.Contains(".FileTransformation", StringComparison.OrdinalIgnoreCase) == true); if (fileTransformationAssembly is null) { return false; } - Type? pluginInterfaceType = fileTransformationAssembly.GetType("Jellyfin.Plugin.FileTransformation.PluginInterface"); + Type? pluginInterfaceType = fileTransformationAssembly.GetType( + "Jellyfin.Plugin.FileTransformation.PluginInterface"); MethodInfo? registerMethod = pluginInterfaceType?.GetMethod( "RegisterTransformation", BindingFlags.Public | BindingFlags.Static); if (registerMethod is null) { + _logger.LogWarning("File Transformation PluginInterface.RegisterTransformation was not found."); return false; } + // Prefer HTTP endpoint: plugin ALC reflection callbacks often fail to resolve. + // Keep callback fields as a secondary path when the host can invoke them. JObject payload = new() { ["id"] = TransformationId, ["fileNamePattern"] = @"index\.html", + ["transformationEndpoint"] = TransformationEndpoint, ["callbackAssembly"] = typeof(WebNavInjector).Assembly.FullName, ["callbackClass"] = typeof(WebNavInjector).FullName, ["callbackMethod"] = nameof(InjectNavLoader) @@ -156,7 +181,7 @@ public sealed class WebNavInjector : IHostedService } catch (Exception ex) { - _logger.LogDebug(ex, "File Transformation registration failed."); + _logger.LogWarning(ex, "File Transformation registration failed."); return false; } } @@ -171,14 +196,13 @@ public sealed class WebNavInjector : IHostedService } var html = File.ReadAllText(indexPath); - if (html.Contains(LoaderSrc, StringComparison.Ordinal)) + if (html.Contains("/Requests/Assets/nav-loader.js", StringComparison.Ordinal)) { _logger.LogInformation("Request nav loader already present in {Path}", indexPath); return; } - var updated = InjectNavLoader(new IndexHtmlPatchPayload { Contents = html }); - File.WriteAllText(indexPath, updated); + File.WriteAllText(indexPath, InjectHtml(html)); _logger.LogInformation("Injected Request nav loader into {Path}", indexPath); } diff --git a/Jellyfin.Plugin.Request/Web/nav-loader.js b/Jellyfin.Plugin.Request/Web/nav-loader.js index 039e268..a2c1e3d 100644 --- a/Jellyfin.Plugin.Request/Web/nav-loader.js +++ b/Jellyfin.Plugin.Request/Web/nav-loader.js @@ -29,12 +29,15 @@ } function isHomeTabContext() { - const hash = window.location.hash || ""; + const hash = (window.location.hash || "").toLowerCase(); const onHomeHash = hash === "" + || hash === "#" || hash === "#/home" || hash === "#/home.html" + || hash === "#home" || hash.indexOf("#/home?") === 0 - || hash.indexOf("#/home.html?") === 0; + || hash.indexOf("#/home.html?") === 0 + || hash.indexOf("#home?") === 0; if (!onHomeHash) { return false; } @@ -393,6 +396,7 @@ } function boot() { + console.info("[Jellyfin.Plugin.Request] nav-loader active"); ensureRequestTab(); document.addEventListener("viewshow", (event) => { if (event.target && event.target.id === "indexPage") { diff --git a/build.yaml b/build.yaml index 19ed880..86f3ac2 100644 --- a/build.yaml +++ b/build.yaml @@ -1,7 +1,7 @@ --- name: "Request" guid: "11c08950-c4bb-484d-89ff-205b3724416b" -version: "1.0.0.5" +version: "1.0.0.6" targetAbi: "10.11.11.0" framework: "net9.0" overview: "Request movies and TV shows from a local admin review queue" diff --git a/manifest.json b/manifest.json index 10669f7..2912b84 100644 --- a/manifest.json +++ b/manifest.json @@ -9,12 +9,12 @@ "repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies", "versions": [ { - "version": "1.0.0.5", - "changelog": "TMDB search: support API key or Read Access Token, clearer results and errors", + "version": "1.0.0.6", + "changelog": "Fix Request tab injection via File Transformation HTTP endpoint fallback", "targetAbi": "10.11.11.0", - "sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.5.zip", - "checksum": "0CDC1AF943448041BED74990E53174A8", - "timestamp": "2026-08-02T21:05:32.0804687Z", + "sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.6.zip", + "checksum": "F8F96C31230088255BA06409A5343897", + "timestamp": "2026-08-02T21:25:31.5610895Z", "dependencies": [] } ] diff --git a/release/Jellyfin.Plugin.Request_1.0.0.6.zip b/release/Jellyfin.Plugin.Request_1.0.0.6.zip new file mode 100644 index 0000000..573dc76 Binary files /dev/null and b/release/Jellyfin.Plugin.Request_1.0.0.6.zip differ diff --git a/scripts/package-release.ps1 b/scripts/package-release.ps1 index 132a5d8..de28298 100644 --- a/scripts/package-release.ps1 +++ b/scripts/package-release.ps1 @@ -1,5 +1,5 @@ param( - [string]$Version = "1.0.0.5", + [string]$Version = "1.0.0.6", [string]$TargetAbi = "10.11.11.0", [string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main" ) @@ -17,7 +17,7 @@ $dllPath = Join-Path $root "Jellyfin.Plugin.Request\bin\Release\net9.0\Jellyfin. $zipPath = Join-Path $releaseDir $zipFileName $manifestPath = Join-Path $root "manifest.json" $timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -$changelog = "TMDB search: support API key or Read Access Token, clearer results and errors" +$changelog = "Fix Request tab injection via File Transformation HTTP endpoint fallback" Write-Host "Building plugin..." dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release