fix(nav): inject request tab via FT HTTP endpoint

File Transformation reflection callbacks often fail across plugin load contexts; register an anonymous TransformIndexHtml endpoint as the reliable injection path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael SloanandCursor committed 2026-08-02 17:25:31 -04:00
1 parent e260677dab
commit bfa8115fd0
9 files changed
+79 -31

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Version>1.0.0.5</Version> <Version>1.0.0.6</Version>
<AssemblyVersion>1.0.0.5</AssemblyVersion> <AssemblyVersion>1.0.0.6</AssemblyVersion>
<FileVersion>1.0.0.5</FileVersion> <FileVersion>1.0.0.6</FileVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Jellyfin.Data; using Jellyfin.Data;
using Jellyfin.Database.Implementations.Enums; using Jellyfin.Database.Implementations.Enums;
using Jellyfin.Plugin.Request.Configuration; using Jellyfin.Plugin.Request.Configuration;
using Jellyfin.Plugin.Request.Hosting;
using Jellyfin.Plugin.Request.Storage; using Jellyfin.Plugin.Request.Storage;
using Jellyfin.Plugin.Request.Tmdb; using Jellyfin.Plugin.Request.Tmdb;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@@ -79,6 +80,20 @@ public sealed class RequestController : ControllerBase
return EmbeddedFile("Web.requestPage.html", "text/html; charset=utf-8"); return EmbeddedFile("Web.requestPage.html", "text/html; charset=utf-8");
} }
/// <summary>
/// File Transformation endpoint: injects nav-loader.js into jellyfin-web index.html.
/// Must stay anonymous because File Transformation calls it without auth.
/// </summary>
/// <param name="payload">Current file contents.</param>
/// <returns>Transformed HTML body.</returns>
[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");
}
/// <summary> /// <summary>
/// Serves plugin web assets. /// Serves plugin web assets.
/// </summary> /// </summary>
@@ -1,12 +1,17 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.Request.Hosting; namespace Jellyfin.Plugin.Request.Hosting;
/// <summary> /// <summary>
/// Payload shape expected by the File Transformation callback. /// Payload shape expected by the File Transformation callback/endpoint.
/// </summary> /// </summary>
public sealed class IndexHtmlPatchPayload public sealed class IndexHtmlPatchPayload
{ {
/// <summary> /// <summary>
/// Gets or sets the current file contents. /// Gets or sets the current file contents.
/// </summary> /// </summary>
[JsonProperty("contents")]
[JsonPropertyName("contents")]
public string Contents { get; set; } = string.Empty; public string Contents { get; set; } = string.Empty;
} }
@@ -18,9 +18,14 @@ namespace Jellyfin.Plugin.Request.Hosting;
/// </summary> /// </summary>
public sealed class WebNavInjector : IHostedService public sealed class WebNavInjector : IHostedService
{ {
private const string LoaderSrc = "/Requests/Assets/nav-loader.js"; /// <summary>
/// Script URL injected into jellyfin-web index.html.
/// </summary>
public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.6";
private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->"; private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->";
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->"; private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
private const string TransformationEndpoint = "/Requests/TransformIndexHtml";
private static readonly Guid TransformationId = Guid.Parse("11c08950-c4bb-484d-89ff-205b3724416b"); private static readonly Guid TransformationId = Guid.Parse("11c08950-c4bb-484d-89ff-205b3724416b");
private readonly IServerApplicationPaths _applicationPaths; private readonly IServerApplicationPaths _applicationPaths;
@@ -43,12 +48,14 @@ public sealed class WebNavInjector : IHostedService
{ {
if (TryRegisterFileTransformation()) 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; return Task.CompletedTask;
} }
_logger.LogWarning( _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 try
{ {
@@ -73,14 +80,25 @@ public sealed class WebNavInjector : IHostedService
} }
/// <summary> /// <summary>
/// File Transformation callback: injects the nav-loader script tag into index.html contents. /// File Transformation reflection callback.
/// </summary> /// </summary>
/// <param name="payload">Current file contents.</param> /// <param name="payload">Current file contents wrapper.</param>
/// <returns>Transformed HTML.</returns> /// <returns>Transformed HTML.</returns>
public static string InjectNavLoader(IndexHtmlPatchPayload payload) public static string InjectNavLoader(JObject payload)
{ {
var html = payload?.Contents ?? string.Empty; var html = payload?["contents"]?.ToString() ?? string.Empty;
if (html.Contains(LoaderSrc, StringComparison.Ordinal) return InjectHtml(html);
}
/// <summary>
/// Injects the nav-loader script tag into index.html contents.
/// </summary>
/// <param name="html">Current HTML.</param>
/// <returns>Transformed HTML.</returns>
public static string InjectHtml(string html)
{
html ??= string.Empty;
if (html.Contains("/Requests/Assets/nav-loader.js", StringComparison.Ordinal)
|| html.Contains(MarkerStart, StringComparison.Ordinal)) || html.Contains(MarkerStart, StringComparison.Ordinal))
{ {
return html; return html;
@@ -95,11 +113,12 @@ public sealed class WebNavInjector : IHostedService
private async Task RetryRegisterAsync(CancellationToken cancellationToken) private async Task RetryRegisterAsync(CancellationToken cancellationToken)
{ {
for (var attempt = 1; attempt <= 10; attempt++) for (var attempt = 1; attempt <= 12; attempt++)
{ {
try 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) catch (OperationCanceledException)
{ {
@@ -116,7 +135,7 @@ public sealed class WebNavInjector : IHostedService
} }
_logger.LogWarning( _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() private bool TryRegisterFileTransformation()
@@ -125,27 +144,33 @@ public sealed class WebNavInjector : IHostedService
{ {
Assembly? fileTransformationAssembly = AssemblyLoadContext.All Assembly? fileTransformationAssembly = AssemblyLoadContext.All
.SelectMany(context => context.Assemblies) .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) if (fileTransformationAssembly is null)
{ {
return false; return false;
} }
Type? pluginInterfaceType = fileTransformationAssembly.GetType("Jellyfin.Plugin.FileTransformation.PluginInterface"); Type? pluginInterfaceType = fileTransformationAssembly.GetType(
"Jellyfin.Plugin.FileTransformation.PluginInterface");
MethodInfo? registerMethod = pluginInterfaceType?.GetMethod( MethodInfo? registerMethod = pluginInterfaceType?.GetMethod(
"RegisterTransformation", "RegisterTransformation",
BindingFlags.Public | BindingFlags.Static); BindingFlags.Public | BindingFlags.Static);
if (registerMethod is null) if (registerMethod is null)
{ {
_logger.LogWarning("File Transformation PluginInterface.RegisterTransformation was not found.");
return false; 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() JObject payload = new()
{ {
["id"] = TransformationId, ["id"] = TransformationId,
["fileNamePattern"] = @"index\.html", ["fileNamePattern"] = @"index\.html",
["transformationEndpoint"] = TransformationEndpoint,
["callbackAssembly"] = typeof(WebNavInjector).Assembly.FullName, ["callbackAssembly"] = typeof(WebNavInjector).Assembly.FullName,
["callbackClass"] = typeof(WebNavInjector).FullName, ["callbackClass"] = typeof(WebNavInjector).FullName,
["callbackMethod"] = nameof(InjectNavLoader) ["callbackMethod"] = nameof(InjectNavLoader)
@@ -156,7 +181,7 @@ public sealed class WebNavInjector : IHostedService
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogDebug(ex, "File Transformation registration failed."); _logger.LogWarning(ex, "File Transformation registration failed.");
return false; return false;
} }
} }
@@ -171,14 +196,13 @@ public sealed class WebNavInjector : IHostedService
} }
var html = File.ReadAllText(indexPath); 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); _logger.LogInformation("Request nav loader already present in {Path}", indexPath);
return; return;
} }
var updated = InjectNavLoader(new IndexHtmlPatchPayload { Contents = html }); File.WriteAllText(indexPath, InjectHtml(html));
File.WriteAllText(indexPath, updated);
_logger.LogInformation("Injected Request nav loader into {Path}", indexPath); _logger.LogInformation("Injected Request nav loader into {Path}", indexPath);
} }
+6 -2
View File
@@ -29,12 +29,15 @@
} }
function isHomeTabContext() { function isHomeTabContext() {
const hash = window.location.hash || ""; const hash = (window.location.hash || "").toLowerCase();
const onHomeHash = hash === "" const onHomeHash = hash === ""
|| hash === "#"
|| hash === "#/home" || hash === "#/home"
|| hash === "#/home.html" || hash === "#/home.html"
|| hash === "#home"
|| hash.indexOf("#/home?") === 0 || hash.indexOf("#/home?") === 0
|| hash.indexOf("#/home.html?") === 0; || hash.indexOf("#/home.html?") === 0
|| hash.indexOf("#home?") === 0;
if (!onHomeHash) { if (!onHomeHash) {
return false; return false;
} }
@@ -393,6 +396,7 @@
} }
function boot() { function boot() {
console.info("[Jellyfin.Plugin.Request] nav-loader active");
ensureRequestTab(); ensureRequestTab();
document.addEventListener("viewshow", (event) => { document.addEventListener("viewshow", (event) => {
if (event.target && event.target.id === "indexPage") { if (event.target && event.target.id === "indexPage") {
+1 -1
View File
@@ -1,7 +1,7 @@
--- ---
name: "Request" name: "Request"
guid: "11c08950-c4bb-484d-89ff-205b3724416b" guid: "11c08950-c4bb-484d-89ff-205b3724416b"
version: "1.0.0.5" version: "1.0.0.6"
targetAbi: "10.11.11.0" targetAbi: "10.11.11.0"
framework: "net9.0" framework: "net9.0"
overview: "Request movies and TV shows from a local admin review queue" overview: "Request movies and TV shows from a local admin review queue"
+5 -5
View File
@@ -9,12 +9,12 @@
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies", "repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
"versions": [ "versions": [
{ {
"version": "1.0.0.5", "version": "1.0.0.6",
"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",
"targetAbi": "10.11.11.0", "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", "sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.6.zip",
"checksum": "0CDC1AF943448041BED74990E53174A8", "checksum": "F8F96C31230088255BA06409A5343897",
"timestamp": "2026-08-02T21:05:32.0804687Z", "timestamp": "2026-08-02T21:25:31.5610895Z",
"dependencies": [] "dependencies": []
} }
] ]
Binary file not shown.
+2 -2
View File
@@ -1,5 +1,5 @@
param( param(
[string]$Version = "1.0.0.5", [string]$Version = "1.0.0.6",
[string]$TargetAbi = "10.11.11.0", [string]$TargetAbi = "10.11.11.0",
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main" [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 $zipPath = Join-Path $releaseDir $zipFileName
$manifestPath = Join-Path $root "manifest.json" $manifestPath = Join-Path $root "manifest.json"
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") $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..." Write-Host "Building plugin..."
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release