diff --git a/Directory.Build.props b/Directory.Build.props
index b05672f..d9ed512 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,7 @@
- 1.0.0.1
- 1.0.0.1
- 1.0.0.1
+ 1.0.0.2
+ 1.0.0.2
+ 1.0.0.2
diff --git a/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs b/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs
new file mode 100644
index 0000000..9edc777
--- /dev/null
+++ b/Jellyfin.Plugin.Request/Hosting/IndexHtmlPatchPayload.cs
@@ -0,0 +1,12 @@
+namespace Jellyfin.Plugin.Request.Hosting;
+
+///
+/// Payload shape expected by the File Transformation callback.
+///
+public sealed class IndexHtmlPatchPayload
+{
+ ///
+ /// Gets or sets the current file 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 fe8501a..f62d8d8 100644
--- a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs
+++ b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs
@@ -1,24 +1,31 @@
using System;
using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
+using Newtonsoft.Json.Linq;
namespace Jellyfin.Plugin.Request.Hosting;
///
-/// Ensures jellyfin-web index.html loads the Request nav loader script.
+/// Injects the Request nav loader into jellyfin-web.
+/// Prefers File Transformation (safe on Docker/Unraid); falls back to patching index.html on disk.
///
public sealed class WebNavInjector : IHostedService
{
private const string LoaderSrc = "/Requests/Assets/nav-loader.js";
private const string MarkerStart = "";
private const string MarkerEnd = "";
+ private static readonly Guid TransformationId = Guid.Parse("11c08950-c4bb-484d-89ff-205b3724416b");
private readonly IServerApplicationPaths _applicationPaths;
private readonly ILogger _logger;
+ private CancellationTokenSource? _retryCts;
///
/// Initializes a new instance of the class.
@@ -34,27 +41,127 @@ public sealed class WebNavInjector : IHostedService
///
public Task StartAsync(CancellationToken cancellationToken)
{
+ if (TryRegisterFileTransformation())
+ {
+ _logger.LogInformation("Request nav loader registered with File Transformation for index.html.");
+ 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.");
+
try
{
- TryInject();
+ TryPatchIndexHtml();
}
catch (Exception ex)
{
- _logger.LogWarning(
- ex,
- "Could not inject Request nav loader into jellyfin-web. Use scripts/install-web-loader.ps1 or .sh after ensuring index.html is writable.");
+ _logger.LogWarning(ex, "Could not patch jellyfin-web index.html on disk.");
}
+ _retryCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
+ _ = RetryRegisterAsync(_retryCts.Token);
return Task.CompletedTask;
}
///
public Task StopAsync(CancellationToken cancellationToken)
{
+ _retryCts?.Cancel();
+ _retryCts?.Dispose();
return Task.CompletedTask;
}
- private void TryInject()
+ ///
+ /// File Transformation callback: injects the nav-loader script tag into index.html contents.
+ ///
+ /// Current file contents.
+ /// Transformed HTML.
+ public static string InjectNavLoader(IndexHtmlPatchPayload payload)
+ {
+ var html = payload?.Contents ?? string.Empty;
+ if (html.Contains(LoaderSrc, StringComparison.Ordinal)
+ || html.Contains(MarkerStart, StringComparison.Ordinal))
+ {
+ return html;
+ }
+
+ var block = $"{MarkerStart}\n\n{MarkerEnd}\n";
+ var bodyIndex = html.LastIndexOf("