plugin: ship JFVR as a real Jellyfin plugin (self-hosted catalog)
Replaces the deploy.py approach (which sed-patched index.html inside the
container, and was therefore lost on every jellyfin/jellyfin upgrade) with a
proper plugin installable from a Jellyfin plugin repository.
The web bundle is unchanged: the same src/*.js -> dist/jfvr.js is now embedded
in Jellyfin.Plugin.JFVR.dll and served from /JFVR/jfvr.js with a content-hash
cache key. index.html is rewritten at request time by an IStartupFilter
middleware, so nothing on disk is touched.
Verified before this commit:
- dotnet build: 0 warnings, 0 errors (net10.0, Jellyfin.Controller 12.1.0)
- the DLL embeds dist/jfvr.js byte for byte
- 19/19 checks on the rewrite logic (injection, idempotency, legacy-tag
takeover, no </body> safety, other scripts preserved, URL override)
- manifest.json passes Jellyfin's PackageInfo/VersionInfo expectations
- the packaged zip's MD5 matches the checksum the manifest advertises
Details that were checked against the Jellyfin source rather than assumed:
- a catalog version survives when targetAbi <= serverVersion, so a single
targetAbi 12.0.0.0 package covers all of 12.x (server is 12.1.0)
- Jellyfin writes meta.json itself at install time, so the zip needs only
the DLL
- Jellyfin verifies the MD5 at install time
Also adds pack.py (build -> package -> manifest -> Gitea release) and documents
the plugin route in README/HANDOFF, keeping deploy.py as a fallback.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.JFVR.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Jellyfin.Plugin.JFVR.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Serves the JFVR web bundle and a small status endpoint.
|
||||
///
|
||||
/// The bundle is anonymous on purpose: the injected tag lives in
|
||||
/// <c>index.html</c>, which the browser fetches before the user has
|
||||
/// authenticated, and the payload is the same JavaScript that is already public
|
||||
/// in the project repository.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("JFVR")]
|
||||
public class JfvrController : ControllerBase
|
||||
{
|
||||
private readonly BundleProvider _bundle;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JfvrController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="bundle">Embedded web bundle.</param>
|
||||
public JfvrController(BundleProvider bundle)
|
||||
{
|
||||
_bundle = bundle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the JFVR web bundle.
|
||||
/// </summary>
|
||||
/// <returns>The bundle as JavaScript.</returns>
|
||||
[HttpGet("jfvr.js")]
|
||||
[AllowAnonymous]
|
||||
[Produces("application/javascript")]
|
||||
public ActionResult GetBundle()
|
||||
{
|
||||
var etag = "\"" + _bundle.Hash + "\"";
|
||||
|
||||
// The URL is versioned with ?v=<hash>, so the body for a given URL never
|
||||
// changes: it is safe to cache forever, and an update always produces a
|
||||
// new URL.
|
||||
Response.Headers[HeaderNames.CacheControl] = "public, max-age=31536000, immutable";
|
||||
Response.Headers[HeaderNames.ETag] = etag;
|
||||
|
||||
if (Request.Headers[HeaderNames.IfNoneMatch].ToString().Contains(_bundle.Hash, StringComparison.Ordinal))
|
||||
{
|
||||
return StatusCode(304);
|
||||
}
|
||||
|
||||
return File(_bundle.Bytes, "application/javascript; charset=utf-8");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports which bundle the server is serving and whether injection is on.
|
||||
/// Handy for verifying a deployment without opening DevTools on the Quest.
|
||||
/// </summary>
|
||||
/// <returns>A small JSON status object.</returns>
|
||||
[HttpGet("status")]
|
||||
[AllowAnonymous]
|
||||
public ActionResult<object> GetStatus()
|
||||
{
|
||||
var config = Plugin.Instance?.Configuration;
|
||||
|
||||
return new
|
||||
{
|
||||
plugin = "Jellyfin.Plugin.JFVR",
|
||||
version = typeof(Plugin).Assembly.GetName().Version?.ToString() ?? "unknown",
|
||||
bundleHash = _bundle.Hash,
|
||||
bundleBytes = _bundle.Bytes.Length,
|
||||
enabled = config?.Enabled ?? false,
|
||||
scriptUrlOverride = config?.ScriptUrlOverride ?? string.Empty,
|
||||
injectedTag = string.IsNullOrWhiteSpace(config?.ScriptUrlOverride)
|
||||
? "../JFVR/jfvr.js?v=" + _bundle.Hash
|
||||
: config!.ScriptUrlOverride.Trim()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user