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

@@ -1,12 +1,17 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.Request.Hosting;
/// <summary>
/// Payload shape expected by the File Transformation callback.
/// Payload shape expected by the File Transformation callback/endpoint.
/// </summary>
public sealed class IndexHtmlPatchPayload
{
/// <summary>
/// Gets or sets the current file contents.
/// </summary>
[JsonProperty("contents")]
[JsonPropertyName("contents")]
public string Contents { get; set; } = string.Empty;
}
@@ -18,9 +18,14 @@ namespace Jellyfin.Plugin.Request.Hosting;
/// </summary>
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 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 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
}
/// <summary>
/// File Transformation callback: injects the nav-loader script tag into index.html contents.
/// File Transformation reflection callback.
/// </summary>
/// <param name="payload">Current file contents.</param>
/// <param name="payload">Current file contents wrapper.</param>
/// <returns>Transformed HTML.</returns>
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);
}
/// <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))
{
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);
}